Skip to content

RabbitMQ Routing Key Binding & Queue Declaration #876

Answered by Lancetnik
bnugent2 asked this question in Q&A
Discussion options

You must be logged in to vote

@bnugent2 So, you can manually declare any queue/exchange in your on_startup event and bind them each other

from faststream import FastStream
from faststream.rabbit import RabbitBroker, RabbitExchange, RabbitQueue

broker = RabbitBroker()
app = FastStream(broker)

@app.after_startup
async def declare():
    queue = await broker.declare_queue(RabbitQueue("test"))
    exchange = await broker.declare_exchange(RabbitExchange("test"))

    await queue.bind(
        exchange,
        routing_key="custom-key",
    )

Also, with the 0.2.9 release, publishers will automatically register exchanges (but not queue) too

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
5 replies
@davorrunje
Comment options

@betaboon
Comment options

@Lancetnik
Comment options

@betaboon
Comment options

@Lancetnik
Comment options

Answer selected by Lancetnik
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants