I want to have two faust agents listening the same kafka topic, but every agent uses its own filter before process the events, and their event sets doesn't intersect.
In the documentation we have an example: https://faust.readthedocs.io/en/latest/userguide/streams.html#id4
If two agents use streams subscribed to the same topic:
topic = app.topic('orders') @app.agent(topic) async def processA(stream): async for value in stream: print(f'A: {value}') @app.agent(topic) async def processB(stream): async for value in stream: print(f'B: {value}')
The Conductor will forward every message received on the “orders” topic to both of the agents, increasing the reference count whenever it enters an agents stream.
The reference count decreases when the event is acknowledged, and when it reaches zero the consumer will consider that offset as “done” and can commit it.
And below for filters https://faust.readthedocs.io/en/latest/userguide/streams.html#id13:
@app.agent() async def process(stream): async for value in stream.filter(lambda: v > 1000).group_by(...): ...
I use some complicated filter but as a result divide the stream in two parts for two agents with completely different logic. (I don't use group_by)
If two agents are working together everything is OK. But if I stop them and restart each will process the stream from the beginning. Because every event was not acknowledged by one of the agents. If I acknowledge all events in every agent when if one of the agents will not be started the second will clean the topic. (If one is crushed and restarted the conductor will see three subscribers as it's waiting 20 min the crushed agent for response).
I just want to separate events on two parts. How can I do the appropriate synchronization in this case?