Skip to main content

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

  1. Add weni-eda to your Django project:
    Add weni.eda.django.eda_app to your INSTALLED_APPS in settings.py:

    # settings.py
    INSTALLED_APPS = [
        # ... other installed apps
        'weni.eda.django.eda_app',
    ]
    
  2. 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_PORT 5672 The 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.

    The following variables are used only when connecting over SSL with weni.eda.django.AMQConnectionParamsFactory (port 5671):

    Variable Name Examples Description
    AMQ_BROKER_HOST "localhost" The hostname or IP address of the SSL message broker server.
    AMQ_VIRTUAL_HOST "/" The virtual host to use when connecting to the SSL broker.
    AMQ_BROKER_USER "guest" The username for authenticating with the SSL message broker.
    AMQ_BROKER_PASSWORD "guest" The password for authenticating with the SSL message broker.
  3. 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 the consume method 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 to dict
    • self.ack() Confirms to RabbitMQ that the message can be removed from the queue, which prevents it from being reprocessed.
  4. Registering your event handlers:
    the EDA_CONSUMERS_HANDLE variable 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-queue queue will be dispatched to the ExampleConsumer consumer and will fall into its consume method.

  5. Starting to consume the queues
    To start consuming messages from the queue, you need to run the edaconsume command 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.

    By default the consumer connects to the standard broker (no SSL). To connect over SSL on port 5671, pass the --params-class flag with the dotted path to the desired ParamsFactory:

    python manage.py edaconsume   # default broker (no SSL)
    python manage.py edaconsume --params-class "weni.eda.django.AMQConnectionParamsFactory"   # SSL 5671
    

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

weni_eda-0.2.0a3.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

weni_eda-0.2.0a3-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

File details

Details for the file weni_eda-0.2.0a3.tar.gz.

File metadata

  • Download URL: weni_eda-0.2.0a3.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.14.0 Darwin/25.3.0

File hashes

Hashes for weni_eda-0.2.0a3.tar.gz
Algorithm Hash digest
SHA256 2985184d2ade6a08d430a36009491a836475fe1aa1b3563d4b5593e08e7b5a27
MD5 162f8269a46944d6cb40a002cb30b2ed
BLAKE2b-256 94d1183f4dc3521b417e55c32419d13a1f81dedbe6da23edc8e783cd47e51191

See more details on using hashes here.

File details

Details for the file weni_eda-0.2.0a3-py3-none-any.whl.

File metadata

  • Download URL: weni_eda-0.2.0a3-py3-none-any.whl
  • Upload date:
  • Size: 12.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.14.0 Darwin/25.3.0

File hashes

Hashes for weni_eda-0.2.0a3-py3-none-any.whl
Algorithm Hash digest
SHA256 aec4952cb2c06a22bcb61bf122f20c77f00717fce33a9850a7d7ccbc35fe8370
MD5 45c2be1e56902810221713b60a511038
BLAKE2b-256 e6257b8afdaef170cba2791910057baaf9867b7e633db98cd839004f5b97d7f5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page