Skip to content

hvuhsg/event-bus

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

event-bus

Run Tests
EventBus implementation in python

Examples

sync

from multi_event_bus import EventBus

eb = EventBus(redis_host="127.0.0.1", redis_port=6379)

eb.dispatch("event-name", payload={"num": 1})

eb.subscribe_to("event-name", consumer_id="consumer-1", offset=0)

event, topic = eb.get(consumer_id="consumer-1")  # Blocking

print(event.payload)  # -> {"num": 1}

async

from multi_event_bus import AsyncEventBus

eb = AsyncEventBus(redis_host="127.0.0.1", redis_port=6379)

eb.dispatch("event-name", payload={"num": 1})

eb.subscribe_to("event-name", consumer_id="consumer-2", offset=0)

event, topic = await eb.get(consumer_id="consumer-2")

print(event.payload)  # -> {"num": 1}

register event schema

from multi_event_bus import EventBus

eb = EventBus(redis_host="127.0.0.1", redis_port=6379)

# Enforce json schema of event
json_schema = {
    "type": "object",
    "properties": {"num": {"type": "string"}}
}
eb.register_event_schema("event-name", schema=json_schema)

eb.dispatch("event-name", payload={"num": "7854"})

eb.subscribe_to("event-name", consumer_id="consumer-3", offset=0)

event, topic = eb.get(consumer_id="consumer-3")  # Blocking

print(event.payload)  # -> {"num": "7854"}

Development

scripts

poetry run run_pytest
poetry run run_flake8
poetry run run_mypy
poetry run run_black

run tests

poetry run test

run all (test and black)

poetry run all

About

EventBus implementation in python

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages