Skip to content

Feature: broker-level topic configuration #2451

@Lancetnik

Description

@Lancetnik

Currently, users have to manually set up all incoming and outgoing topics in the @router.subscriber() and @router.publisher() decorators. It would be great if we could define topic configurations at the broker level.

If users want to specify topics from the settings, they have several options:

All these alternatives require additional work from the user and are not as declarative as we'd like.
Therefore, I propose providing users with a more flexible configuration option. Something like this:

@router.subscriber(Config("IN_TOPIC"))
async def handler(message: Message):
    ...

def main():
    broker = Broker(config={
        "IN_TOPIC": "test-topic",
    })
    broker.include_router(router)

This way, we can make any static routing definition truly lazy, and we don't need to rely on global state. This also allows for more flexible configuration options. The approach should be the same for both subscribers and publishers.

The configuration can be used as a value for any option, including nested ones. This is especially useful for complex configurations. For example

@rabbit_broker.subscriber(
    queue=RabbitQueue(name="test", routing_key=Config("ROUTING_KEY"))
    exchange=Config("EXCHANGE_NAME")
)
async def handler(message: Message): ...

Metadata

Metadata

Assignees

Labels

CoreIssues related to core FastStream functionality and affects to all brokersenhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions