22from rabbitmq_amqp_python_client import (
33 BindingSpecification ,
44 Connection ,
5- Delivery ,
65 Event ,
76 ExchangeSpecification ,
87 Message ,
8+ MessageAck ,
99 MessagingHandler ,
1010 QuorumQueueSpecification ,
1111 exchange_address ,
@@ -20,18 +20,19 @@ def __init__(self):
2020 self ._count = 0
2121
2222 def on_message (self , event : Event ):
23- print ("received message: " + event .message .body )
23+ print ("received message: " + str ( event .message .annotations ) )
2424
25- dlv = event .delivery
25+ # annotations = {}
26+ # annotations[symbol('x-opt-string')] = 'x-test1'
27+ # MessageAck.requeue_with_annotations(event, annotations)
2628
27- dlv .update (Delivery .ACCEPTED )
28- dlv .settle ()
29+ MessageAck .accept (event )
2930
3031 print ("count " + str (self ._count ))
3132
3233 self ._count = self ._count + 1
3334
34- if self ._count == 100000 :
35+ if self ._count == 100 :
3536 print ("closing receiver" )
3637 event .receiver .close ()
3738 event .connection .close ()
@@ -42,9 +43,6 @@ def on_connection_closed(self, event: Event):
4243 def on_link_closed (self , event : Event ) -> None :
4344 print ("link closed" )
4445
45- def on_rejected (self , event : Event ) -> None :
46- print ("rejected" )
47-
4846
4947def create_connection () -> Connection :
5048 connection = Connection ("amqp://guest:guest@localhost:5672/" )
@@ -58,7 +56,7 @@ def main() -> None:
5856 exchange_name = "test-exchange"
5957 queue_name = "example-queue"
6058 routing_key = "routing-key"
61- messages_to_publish = 100000
59+ messages_to_publish = 100
6260
6361 print ("connection to amqp server" )
6462 connection = create_connection ()
@@ -121,14 +119,14 @@ def main() -> None:
121119 management .unbind (bind_name )
122120
123121 print ("delete queue" )
124- management .delete_queue (queue_name )
122+ # management.delete_queue(queue_name)
125123
126124 print ("delete exchange" )
127125 management .delete_exchange (exchange_name )
128126
129127 print ("closing connections" )
130128 management .close ()
131- consumer .close ()
129+ # consumer.close()
132130 print ("after management closing" )
133131 connection .close ()
134132 print ("after connection closing" )
0 commit comments