No project description provided
Project description
Weni EDA
weni-eda is a Python library designed to simplify the use of Event-Driven Architecture (EDA). It provides an interface that seamlessly integrates with the Django framework and RabbitMQ messaging service. The design is scalable and intended to support various integrations in the future.
Features
- Easy integration with Django.
- Support for RabbitMQ.
- Simplified event handling and message dispatching.
- Scalable design to accommodate future integrations with other frameworks and messaging services.
Installation
To install the library, use pip:
pip install weni-eda
Configuration
Django Integration
-
Add weni-eda to your Django project:
Addweni.eda.django.eda_appto yourINSTALLED_APPSinsettings.py:# settings.py INSTALLED_APPS = [ # ... other installed apps 'weni.eda.django.eda_app', ]
-
Environment Variables for weni-eda Configuration
The following environment variables are used to configure the weni-eda library. Here is a detailed explanation of each variable:
Variable Name Examples Description EDA_CONSUMERS_HANDLE"example.event_driven.handle.handle_consumers"Specifies the handler module for consumer events. EDA_BROKER_HOST"localhost"The hostname or IP address of the message broker server. EDA_VIRTUAL_HOST"/"The virtual host to use when connecting to the broker. EDA_BROKER_PORT5672The port number on which the message broker is listening. EDA_BROKER_USER"guest"The username for authenticating with the message broker. EDA_BROKER_PASSWORD"guest"The password for authenticating with the message broker. -
Creating your event consumers
We provide an abstract class that facilitates the consumption of messages. To use it, you need to inherit it and declare theconsumemethod as follows:from weni.eda.django.consumers import EDAConsumer class ExampleConsumer(EDAConsumer): def consume(self, message: Message): body = JSONParser.parse(message.body) self.ack()
JSONParser.parse(message.body)Converts the message arriving from RabbitMQ in JSON format todictself.ack()Confirms to RabbitMQ that the message can be removed from the queue, which prevents it from being reprocessed.
-
Registering your event handlers:
theEDA_CONSUMERS_HANDLEvariable indicates the function that will be called when the consumer starts. this function will be responsible for mapping the messages to their respective consumers. The function must be declared as follows:import amqp from .example_consumer import ExampleConsumer def handle_consumers(channel: amqp.Channel): channel.basic_consume("example-queue", callback=ExampleConsumer().handle)
This indicates that any message arriving at the
example-queuequeue will be dispatched to theExampleConsumerconsumer and will fall into itsconsumemethod. -
Starting to consume the queues
To start consuming messages from the queue, you need to run theedaconsumecommand as follows:python manage.py edaconsume
From then on, all messages that arrive in the queues where your application is written will be dispatched to their respective consumers.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file weni_eda-0.1.1.tar.gz.
File metadata
- Download URL: weni_eda-0.1.1.tar.gz
- Upload date:
- Size: 11.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.10.12 Linux/6.5.0-44-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f95934fcf27f3dd2aaadb96e16826a73fb5d0ef0e7cca24a4b0ccce026449f82
|
|
| MD5 |
359b0e114e8d4934b0e5b633dae1b17d
|
|
| BLAKE2b-256 |
701dfd24b0cc7401a7235f8175200dfe3aef58166858b729bdf58a6bea87d0e5
|
File details
Details for the file weni_eda-0.1.1-py3-none-any.whl.
File metadata
- Download URL: weni_eda-0.1.1-py3-none-any.whl
- Upload date:
- Size: 10.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.10.12 Linux/6.5.0-44-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
24953f43b01976cd90345931c1552307d27d1f709ebd1792fa840126c7699cb8
|
|
| MD5 |
7724776664e139110aac9d6f337d006f
|
|
| BLAKE2b-256 |
0362c05d4df33794c7da6e47bfa2456bc05941310f9e953d13df3d9e65270664
|