11import time
22
33from rabbitmq_amqp_python_client import (
4+ BindingSpecification ,
45 Connection ,
6+ ExchangeSpecification ,
57 Message ,
68 QuorumQueueSpecification ,
9+ exchange_address ,
710)
811
912
10- def test_publish_exchange (connection : Connection ) -> None :
13+ def test_publish_queue (connection : Connection ) -> None :
1114
1215 queue_name = "test-queue"
1316 management = connection .management ()
@@ -29,6 +32,43 @@ def test_publish_exchange(connection: Connection) -> None:
2932 management .delete_queue (queue_name )
3033
3134
35+ def test_publish_exchange (connection : Connection ) -> None :
36+
37+ exchange_name = "test-exchange"
38+ queue_name = "test-queue"
39+ management = connection .management ()
40+ routing_key = "routing-key"
41+
42+ management .declare_exchange (ExchangeSpecification (name = exchange_name , arguments = {}))
43+
44+ management .declare_queue (QuorumQueueSpecification (name = queue_name ))
45+
46+ management .bind (
47+ BindingSpecification (
48+ source_exchange = exchange_name ,
49+ destination_queue = queue_name ,
50+ binding_key = routing_key ,
51+ )
52+ )
53+
54+ addr = exchange_address (exchange_name , routing_key )
55+
56+ raised = False
57+
58+ try :
59+ publisher = connection .publisher (addr )
60+ publisher .publish (Message (body = "test" ))
61+ except Exception :
62+ raised = True
63+
64+ assert raised is False
65+
66+ publisher .close ()
67+
68+ management .delete_exchange (exchange_name )
69+ management .delete_queue (queue_name )
70+
71+
3272def test_publish_purge (connection : Connection ) -> None :
3373 connection = Connection ("amqp://guest:guest@localhost:5672/" )
3474 connection .dial ()
0 commit comments