Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Can't use JetStream with nested routers #1660

Closed
ulbwa opened this issue Aug 9, 2024 · 0 comments · Fixed by #1666
Closed

Bug: Can't use JetStream with nested routers #1660

ulbwa opened this issue Aug 9, 2024 · 0 comments · Fixed by #1666
Labels
bug Something isn't working

Comments

@ulbwa
Copy link
Contributor

ulbwa commented Aug 9, 2024

Describe the bug
When using NATS broker with JetStream and nested routers in FastStream, it is not possible to properly register a subscriber and receive messages.

How to reproduce

from faststream import FastStream
from faststream.nats import JStream, NatsBroker, NatsRouter

broker = NatsBroker()
stream = JStream("service-stream")

service_router = NatsRouter(prefix="service.")
user_router = NatsRouter(prefix="user.")


@user_router.subscriber(
    subject="fetch.nested", queue="service-user-fetch-nested-queue", stream=stream
)
async def fetch_nested_user(message: dict):
    ...


@broker.subscriber(
    subject="service.user.fetch", queue="service-user-fetch-queue", stream=stream
)
async def fetch_user(message: dict):
    ...


service_router.include_router(user_router)
broker.include_router(service_router)
app = FastStream(broker)


@app.after_startup
async def after_startup():
    await broker.publish(dict(a=1), "service.user.fetch")
    await broker.publish(dict(a=1), "service.user.fetch.nested")

Expected behavior

2024-08-10 01:30:34,396 INFO     - FastStream app starting...
2024-08-10 01:30:34,408 INFO     - service-stream | service-user-fetch-queue        | service.user.fetch        |            - `FetchUser` waiting for messages
2024-08-10 01:30:34,412 INFO     - service-stream | service-user-fetch-nested-queue | service.user.fetch.nested |            - `FetchNestedUser` waiting for messages
2024-08-10 01:30:34,415 INFO     - FastStream app started successfully! To exit, press CTRL+C
2024-08-10 01:30:34,416 INFO     - service-stream | service-user-fetch-queue        | service.user.fetch        | 23131352-2 - Received
2024-08-10 01:30:34,417 INFO     - service-stream | service-user-fetch-queue        | service.user.fetch        | 23131352-2 - Processed
2024-08-10 01:30:34,418 INFO     - service-stream | service-user-fetch-nested-queue | service.user.fetch.nested | 23131353-2 - Received
2024-08-10 01:30:34,419 INFO     - service-stream | service-user-fetch-nested-queue | service.user.fetch.nested | 23131353-2 - Processed

Observed behavior

The message does not reach the listener in the nested router:

2024-08-10 01:30:34,396 INFO     - FastStream app starting...
2024-08-10 01:30:34,408 INFO     - service-stream | service-user-fetch-queue        | service.user.fetch        |            - `FetchUser` waiting for messages
2024-08-10 01:30:34,412 INFO     - service-stream | service-user-fetch-nested-queue | service.user.fetch.nested |            - `FetchNestedUser` waiting for messages
2024-08-10 01:30:34,415 INFO     - FastStream app started successfully! To exit, press CTRL+C
2024-08-10 01:30:34,416 INFO     - service-stream | service-user-fetch-queue        | service.user.fetch        | 23131352-2 - Received
2024-08-10 01:30:34,417 INFO     - service-stream | service-user-fetch-queue        | service.user.fetch        | 23131352-2 - Processed
@ulbwa ulbwa added the bug Something isn't working label Aug 9, 2024
github-merge-queue bot pushed a commit that referenced this issue Aug 11, 2024
* fix (#1660): correct patch nested JStream subjects

* lint: run ruff

* tests: fix tabulation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant