Skip to main content

A lightweight event bus implementation using Redis

Project description

Eve Bus

A lightweight, reliable event bus implementation using Redis as the message broker. This library provides a simple interface for publishing and subscribing to events in distributed systems.

Features

  • Publish and subscribe to events using Redis
  • Thread-safe implementation
  • Support for multiple event handlers per event
  • Automatic retry mechanism for failed event handlers
  • Clean shutdown and resource management
  • Easy integration with dependency injection frameworks

Installation

pip install eve-bus

Usage

Basic Setup

from eve.adapters.events import RedisEventBus, subscribe, publish
from eve.domain.events import Event
from redis import Redis

# Create a Redis client
redis_client = Redis(host='localhost', port=6379, db=0)

# Create an event bus instance
event_bus = RedisEventBus(redis_client)

# Define an event class
class UserCreated(Event):
    user_id: str
    username: str

# Subscribe to an event
@subscribe('UserCreated')
def handle_user_created(event_data):
    print(f"User created: {event_data['username']}")

# Publish an event
user_created_event = UserCreated(user_id='123', username='john_doe')
publish(user_created_event)

# When done, shutdown the event bus
event_bus.shutdown()

Using with Dependency Injection

from dependency_injector import containers, providers
from eve.adapters.events import RedisEventBus
from redis import Redis

class Container(containers.DeclarativeContainer):
    # Redis client provider
    redis_client = providers.Singleton(
        Redis,
        host='localhost',
        port=6379,
        db=0
    )

    # Event bus provider
    event_bus = providers.Singleton(RedisEventBus, redis_client=redis_client)

# Create a container instance
container = Container()

# Get the event bus instance
event_bus = container.event_bus()

Configuration

You can configure the event bus by setting the following environment variables:

  • EVENT_CHANNEL: Prefix for Redis channels (default: 'event')

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

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

eve_bus-0.1.0.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

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

eve_bus-0.1.0-py3-none-any.whl (3.7 kB view details)

Uploaded Python 3

File details

Details for the file eve_bus-0.1.0.tar.gz.

File metadata

  • Download URL: eve_bus-0.1.0.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.6

File hashes

Hashes for eve_bus-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a92925ba31a557094e9310f5eae91c01514a57f92ceec0dbf6ef587045508798
MD5 19ad54447124cf2153db9cf77cee6010
BLAKE2b-256 04952e46ed5bfc5cbdca38c7cc6dbe34995bffa00e5456a4999f2dbf65ed6aca

See more details on using hashes here.

File details

Details for the file eve_bus-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: eve_bus-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.6

File hashes

Hashes for eve_bus-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cc4db0a821213961a9d9d558638ef74a3d0d8183e22f8cb00a08b2be8643a2d9
MD5 db8a4eeb0ef40f88bdb13c18144f6ee1
BLAKE2b-256 ed062dda795e38ea5dc00e76ea75c1fe4df6066175e7e669db55307406a684f8

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