faststream icon indicating copy to clipboard operation
faststream copied to clipboard

RFE: NATS same subject subscription not registering handlers

Open frct1 opened this issue 1 year ago • 1 comments

Describe the bug In some cases user might need to process same message in multiple handlers, following same as docs code doesn't give documented result.

How to reproduce Include source code:

from faststream import FastStream, Logger
from faststream.nats import NatsBroker

broker = NatsBroker("nats://127.0.0.1:4222", name="Faststream Client")
app = FastStream(broker)


@broker.subscriber("test-subj-1", "workers")
async def base_handler1(logger: Logger):
    logger.info("base_handler1")


@broker.subscriber("test-subj-1", "workers")
async def base_handler2(logger: Logger):
    logger.info("base_handler2")


@broker.subscriber("test-subj-2", "workers")
async def base_handler3(logger: Logger):
    logger.info("base_handler3")

...

And/Or steps to reproduce the behavior:

  1. Just wrap up basic code from docs

Expected behavior Handlers are being registered as nats subscribers

Observed behavior 2024-03-17 01:10:43,038 INFO - FastStream app starting... 2024-03-17 01:10:43,041 INFO - workers | test-subj-1 | - BaseHandler1 waiting for messages 2024-03-17 01:10:43,042 INFO - workers | test-subj-2 | - BaseHandler3 waiting for messages

Environment

> faststream -v
Running FastStream 0.4.7 with CPython 3.11.5 on Darwin

Additional context No additional context

frct1 avatar Mar 16 '24 18:03 frct1

@frct1 it's not a bug. You can't create consumer on the same subject - this syntax is using to filtering feature

But, this syntax will be deprecated in 0.5.0 in prior to the following one

subscriber = broker.subscriber("test")

@subscriber(filter=filter1)
async def handler1():
    ....

@subscriber(filter=filter2)
async def handler2():
    ....

And, finally, in 0.6.0 I am planning to remove deprecated filter syntax and allow use to create any subscribers he want

But now, please, use multiple interactors in the same handler or create multiple consumer applications

Lancetnik avatar Mar 17 '24 10:03 Lancetnik