File tree Expand file tree Collapse file tree 5 files changed +43
-9
lines changed
rabbitmq_amqp_python_client Expand file tree Collapse file tree 5 files changed +43
-9
lines changed Original file line number Diff line number Diff line change @@ -70,7 +70,7 @@ def main() -> None:
70
70
exchange_name = "test-exchange"
71
71
queue_name = "example-queue"
72
72
routing_key = "routing-key"
73
- messages_to_publish = 100
73
+ messages_to_publish = 100000
74
74
75
75
print ("connection to amqp server" )
76
76
connection = create_connection ()
@@ -109,7 +109,13 @@ def main() -> None:
109
109
110
110
# publish 10 messages
111
111
for i in range (messages_to_publish ):
112
- publisher .publish (Message (body = "test" ))
112
+ status = publisher .publish (Message (body = "test" ))
113
+ if status .ACCEPTED :
114
+ print ("message accepted" )
115
+ elif status .RELEASED :
116
+ print ("message not routed" )
117
+ elif status .REJECTED :
118
+ print ("message not rejected" )
113
119
114
120
publisher .close ()
115
121
Original file line number Diff line number Diff line change 52
52
"AddressHelper" ,
53
53
"AMQPMessagingHandler" ,
54
54
"ArgumentOutOfRangeException" ,
55
+ "Delivery" ,
55
56
]
Original file line number Diff line number Diff line change @@ -21,6 +21,21 @@ def test(self, link: Link) -> bool:
21
21
return bool (link .is_sender )
22
22
23
23
24
+ class SenderOptionUnseattle (LinkOption ): # type: ignore
25
+ def __init__ (self , addr : str ):
26
+ self ._addr = addr
27
+
28
+ def apply (self , link : Link ) -> None :
29
+ link .source .address = self ._addr
30
+ link .snd_settle_mode = Link .SND_UNSETTLED
31
+ link .rcv_settle_mode = Link .RCV_FIRST
32
+ link .properties = PropertyDict ({symbol ("paired" ): True })
33
+ link .source .dynamic = False
34
+
35
+ def test (self , link : Link ) -> bool :
36
+ return bool (link .is_sender )
37
+
38
+
24
39
class ReceiverOption (LinkOption ): # type: ignore
25
40
def __init__ (self , addr : str ):
26
41
self ._addr = addr
Original file line number Diff line number Diff line change 1
1
import logging
2
2
from typing import Optional
3
3
4
- from .options import SenderOption
4
+ from .options import SenderOptionUnseattle
5
+ from .qpid .proton ._delivery import Delivery
5
6
from .qpid .proton ._message import Message
6
7
from .qpid .proton .utils import (
7
8
BlockingConnection ,
@@ -23,14 +24,14 @@ def _open(self) -> None:
23
24
logger .debug ("Creating Sender" )
24
25
self ._sender = self ._create_sender (self ._addr )
25
26
26
- def publish (self , message : Message ) -> None :
27
+ def publish (self , message : Message ) -> Delivery :
27
28
if self ._sender is not None :
28
- self ._sender .send (message )
29
+ return self ._sender .send (message )
29
30
30
31
def close (self ) -> None :
31
32
logger .debug ("Closing Sender" )
32
33
if self ._sender is not None :
33
34
self ._sender .close ()
34
35
35
36
def _create_sender (self , addr : str ) -> BlockingSender :
36
- return self ._conn .create_sender (addr , options = SenderOption (addr ))
37
+ return self ._conn .create_sender (addr , options = SenderOptionUnseattle (addr ))
Original file line number Diff line number Diff line change @@ -18,17 +18,24 @@ def test_publish_queue(connection: Connection) -> None:
18
18
19
19
raised = False
20
20
21
+ publisher = None
22
+ accepted = False
23
+
21
24
try :
22
25
publisher = connection .publisher ("/queues/" + queue_name )
23
- publisher .publish (Message (body = "test" ))
26
+ status = publisher .publish (Message (body = "test" ))
27
+ if status .ACCEPTED :
28
+ accepted = True
24
29
except Exception :
25
30
raised = True
26
31
27
- publisher .close ()
32
+ if publisher is not None :
33
+ publisher .close ()
28
34
29
35
management .delete_queue (queue_name )
30
36
management .close ()
31
37
38
+ assert accepted is True
32
39
assert raised is False
33
40
34
41
@@ -75,10 +82,13 @@ def test_publish_exchange(connection: Connection) -> None:
75
82
addr = AddressHelper .exchange_address (exchange_name , routing_key )
76
83
77
84
raised = False
85
+ accepted = False
78
86
79
87
try :
80
88
publisher = connection .publisher (addr )
81
- publisher .publish (Message (body = "test" ))
89
+ status = publisher .publish (Message (body = "test" ))
90
+ if status .ACCEPTED :
91
+ accepted = True
82
92
except Exception :
83
93
raised = True
84
94
@@ -88,6 +98,7 @@ def test_publish_exchange(connection: Connection) -> None:
88
98
management .delete_queue (queue_name )
89
99
management .close ()
90
100
101
+ assert accepted is True
91
102
assert raised is False
92
103
93
104
You can’t perform that action at this time.
0 commit comments