Only one process of multiple processes receives it, use FANOUT #1327
Answered
by
Lancetnik
v2boardbot
asked this question in
Q&A
-
consumer: from faststream import FastStream, Logger
from faststream.rabbit import ExchangeType, RabbitBroker, RabbitExchange, RabbitQueue
broker = RabbitBroker()
app = FastStream(broker)
exch = RabbitExchange("exchange", auto_delete=True, type=ExchangeType.FANOUT)
queue_1 = RabbitQueue("test-q-1", auto_delete=True)
@broker.subscriber(queue_1, exch, no_ack=True)
async def base_handler1(logger: Logger):
logger.info("base_handler1111") consumer start command:faststream run main:app --workers 2 =========================== import asyncio
from faststream import FastStream, Logger
from faststream.rabbit import ExchangeType, RabbitBroker, RabbitExchange, RabbitQueue
broker = RabbitBroker()
app = FastStream(broker)
exch = RabbitExchange("exchange", auto_delete=True, type=ExchangeType.FANOUT)
@app.after_startup
async def send_messages():
for i in range(100):
res = await broker.publish(exchange=exch) # handlers: 1, 2, 3
print(res)
await asyncio.sleep(5) Producer startup command: faststream run client:app |
Beta Was this translation helpful? Give feedback.
Answered by
Lancetnik
Mar 30, 2024
Replies: 1 comment 3 replies
-
The following setup should works fine @broker.subscriber(queue_1, exch)
async def base_handler1(logger: Logger):
...
@broker.subscriber(queue_2, exch) # another queue
async def base_handler1(logger: Logger):
... RMQ message pipeline works the following way: EXCHANGE -> QUQEUE -> SUBSCRIBER |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
v2boardbot
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
FANOUT
exchange deliveres message to all binded queues. So, to consume message double you should bind another queue to this exchange with another routing key/name.The following setup should works fine
RMQ message pipeline works the following way: EXCHANGE -> QUQEUE -> SUBSCRIBER
You tried to consume message multiple times from the same QUEUE, but it is impossible.