Skip to content

Commit 86eafcd

Browse files
committed
broker: automaticly set exchange on send
1 parent d2bd79a commit 86eafcd

2 files changed

Lines changed: 3 additions & 1 deletion

File tree

microagent/broker.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ class BoundQueue(QueueProtocol):
160160
queue: Queue
161161

162162
async def send(self, message: dict, **options: Any) -> None:
163+
if 'exchange' not in options and self.queue.exchange:
164+
options['exchange'] = self.queue.exchange
163165
await self.broker.send(self.queue.name, self.queue.serialize(message), **options)
164166

165167
async def length(self) -> int:

tests/test_broker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ async def test_Broker_send_ok(broker, test_queue):
144144

145145
async def test_Broker_send_ok_to_exchange(broker, else_queue):
146146
await broker.ex.send({'uid': 1})
147-
broker.send.assert_called_once_with('else_queue', '{"uid": 1}')
147+
broker.send.assert_called_once_with('else_queue', '{"uid": 1}', exchange='ex')
148148

149149

150150
async def test_Broker_prepared_data_ok(broker, test_queue):

0 commit comments

Comments
 (0)