faststream icon indicating copy to clipboard operation
faststream copied to clipboard

Feature: Broker event handlers

Open frct1 opened this issue 1 year ago • 4 comments

Is your feature request related to a problem? Please describe. If multiple brokers are used user might need to stop processing messages if depends on other broker,

Describe the solution you'd like Handle connected/disconnected/reconnected events. Probably, multiple FastStream app instances might be instantiated. As i understand, other brokers that not referred by any FastStream app are not re-connecting automatically in case of network failures or something else. Probably reconnect feature could be enabled for a broker that not referenced by any app.

Feature code example

from faststream import FastStream

kafka_broker = KafkaBroker(bootstrap_servers= "127.0.0.1:9092")

rabbit_broker = RabbitBroker("amqp://127.0.0.1:5672", virtualhost="/")

@kafka_broker.on_disconnect
async def kafka_disconnected_cb():
  pass
  
@rabbit_broker.on_disconnect
async def rabbit_disconnected_cb():
  pass
...

ref1: https://github.com/airtai/faststream/issues/526

frct1 avatar Jun 21 '24 08:06 frct1

All our running brokers should reconnect automatically. But, adding special hooks to check it is a great point, thank your for the idea!

Lancetnik avatar Jun 21 '24 09:06 Lancetnik

@Lancetnik I would like to work on this if this issue is still available. Let me know and I will start working on a PR

MrPranav101 avatar Oct 15 '24 19:10 MrPranav101

@Lancetnik I would like to work on this if this issue is still available. Let me know and I will start working on a PR

I can even assign it to you 😄

Lancetnik avatar Oct 15 '24 20:10 Lancetnik

I need something similar but for RabbitMQ

alteest avatar Dec 02 '24 13:12 alteest