Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hvuhsg/event-bus
EventBus implementation in python
https://github.com/hvuhsg/event-bus
Last synced: 7 days ago
JSON representation
EventBus implementation in python
- Host: GitHub
- URL: https://github.com/hvuhsg/event-bus
- Owner: hvuhsg
- Created: 2022-04-01T14:23:34.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-04-19T17:58:00.000Z (over 2 years ago)
- Last Synced: 2024-09-21T21:44:19.628Z (about 2 months ago)
- Language: Python
- Size: 85.9 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# event-bus
[![Run Tests](https://github.com/hvuhsg/event-bus/actions/workflows/test.yml/badge.svg)](https://github.com/hvuhsg/event-bus/actions/workflows/test.yml)
EventBus implementation in python### Examples
#### sync```python
from multi_event_bus import EventBuseb = 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```python
from multi_event_bus import AsyncEventBuseb = 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```python
from multi_event_bus import EventBuseb = 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
```commandline
poetry run run_pytest
poetry run run_flake8
poetry run run_mypy
poetry run run_black
```
#### run tests
```commandline
poetry run test
```#### run all (test and black)
```commandline
poetry run all
```