Polling Publisher
From the version 1.x this feature is supported out-of-box.
Pattern
https://microservices.io/patterns/data/polling-publisher.html
Usage example
subscribe-polling-publisher.py |
---|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 | import asyncio
import logging
from rabbit import AioRabbitClient, Publish
from rabbit.exchange import Exchange
logging.getLogger().setLevel(logging.DEBUG)
client = AioRabbitClient()
asyncio.create_task(client.persistent_connect())
publish = Publish()
await client.register(publish)
class MyRepo:
def __init__(self, publish, db):
self._publish = publish
self._db = db
async def start_polling():
while True:
await asyncio.sleep(10)
# do some work here and retrieve database event data.
await self._publish.send_event(event)
repo = MyRepo(publish, DB())
asyncio.create_task(repo.start_polling())
|