Skip to content

Commit

Permalink
chore: polish docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Lancetnik committed Dec 30, 2024
1 parent 313d823 commit 6fb8eae
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
2 changes: 1 addition & 1 deletion docs/docs/en/rabbit/declare.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ These methods require just one argument (`RabbitQueue`/`RabbitExchange`) contain

It is also possible to bind a queue and an exchange using low-level **aio-pika** `RobustQueue.bind` method:

```python linenums="1" hl_lines="15-20 22-27"
```python linenums="1" hl_lines="23-25 27-29 31-34"
{! docs_src/rabbit/bind.py !}
```
15 changes: 6 additions & 9 deletions docs/docs_src/rabbit/bind.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import aio_pika
from faststream import FastStream
from faststream.rabbit import (
ExchangeType,
Expand All @@ -10,10 +11,7 @@
app = FastStream(broker)


some_queue = RabbitQueue(
name="some-queue",
durable=True,
)
some_queue = RabbitQueue("some-queue")

some_exchange = RabbitExchange(
name="some-exchange",
Expand All @@ -22,16 +20,15 @@

@app.after_startup
async def bind_queue_exchange():
queue = await broker.declare_queue(
queue: aio_pika.RobustQueue = await broker.declare_queue(
some_queue
) # This gives a aio_pika.RobustQueue object
)

exchange = await broker.declare_exchange(
exchange: aio_pika.RobustExchange = await broker.declare_exchange(
some_exchange
)

await queue.bind(
queue=queue,
exchange=exchange,
routing_key=queue.name # This parameter is optional
routing_key=queue.name # Optional parameter
)
5 changes: 3 additions & 2 deletions tests/a_docs/rabbit/test_bind.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@ async def test_bind(monkeypatch, async_mock: AsyncMock):

with monkeypatch.context() as m:
m.setattr(RobustQueue, "bind", async_mock)

async with TestApp(app):
assert len(broker.declarer._RabbitDeclarer__queues) == 2 # with `reply-to`
assert len(broker.declarer._RabbitDeclarer__exchanges) == 1

assert some_queue in broker.declarer._RabbitDeclarer__queues
assert some_exchange in broker.declarer._RabbitDeclarer__exchanges

row_exchange = await broker.declarer.declare_exchange(some_exchange)
async_mock.assert_awaited_once_with(
queue=broker.declarer._RabbitDeclarer__queues[some_queue],
exchange=broker.declarer._RabbitDeclarer__exchanges[some_exchange],
exchange=row_exchange,
routing_key=some_queue.name,
)

0 comments on commit 6fb8eae

Please sign in to comment.