11import uuid
22from typing import Any , Optional
3- import json
4- from proton import Message , Receiver , Sender
3+
4+ from proton import Message
5+ from proton ._data import Data
56from proton .utils import (
67 BlockingConnection ,
78 BlockingReceiver ,
89 BlockingSender ,
910)
1011
11- from proton ._data import Data
12-
1312from .address_helper import exchange_address , queue_address
1413from .common import CommonValues
15- from .configuration_options import (
16- ReceiverOption ,
17- SenderOption ,
18- )
1914from .entities import (
2015 ExchangeSpecification ,
2116 QueueSpecification ,
2217)
18+ from .options import ReceiverOption , SenderOption
2319
24- import pickle
2520
2621class Management :
2722 def __init__ (self , conn : BlockingConnection ):
@@ -59,7 +54,6 @@ def request(
5954 method : str ,
6055 expected_response_codes : list [int ],
6156 ) -> None :
62- print ("im in request" )
6357 self ._request (str (uuid .uuid4 ()), body , path , method , expected_response_codes )
6458
6559 def _request (
@@ -70,63 +64,37 @@ def _request(
7064 method : str ,
7165 expected_response_codes : list [int ],
7266 ) -> None :
73- print ("path is: " + path )
74-
75- ## test exchange message
7667 amq_message = Message (
7768 id = id ,
7869 body = body ,
7970 reply_to = "$me" ,
8071 address = path ,
8172 subject = method ,
82- #properties={"id": id, "to": path, "subject": method, "reply_to": "$me"},
83- )
84-
85- kvBody = {
86- "auto_delete" : False ,
87- "durable" : True ,
88- "type" : "direct" ,
89- "arguments" : {},
90- }
91-
92- amq_message = Message (
93- body = kvBody ,
94- reply_to = "$me" ,
95- address = path ,
96- subject = method ,
97- id = id ,
9873 )
9974
100- message_bytes = amq_message .encode ()
101- list_bytes = list (message_bytes )
102-
10375 if self ._sender is not None :
10476 self ._sender .send (amq_message )
10577
106- msg = self ._receiver .receive ()
107-
108-
109- print ("response received: " + str (msg .subject ))
110-
111- #self._validate_reponse_code(int(msg.properties["http:response"]), expected_response_codes)
78+ if self ._receiver is not None :
79+ msg = self ._receiver .receive ()
11280
113- # TO_COMPLETE HERE
81+ self . _validate_reponse_code ( int ( msg . subject ), expected_response_codes )
11482
11583 # TODO
11684 # def delete_queue(self, name:str):
11785
118- def declare_exchange (self , exchange_specification : ExchangeSpecification ):
86+ def declare_exchange (
87+ self , exchange_specification : ExchangeSpecification
88+ ) -> ExchangeSpecification :
11989 body = {}
12090 body ["auto_delete" ] = exchange_specification .is_auto_delete
12191 body ["durable" ] = exchange_specification .is_durable
122- body ["type" ] = exchange_specification .exchange_type .value
123- # body["internal"] = False
124- body ["arguments" ] = {}
92+ body ["type" ] = exchange_specification .exchange_type .value # type: ignore
93+ body ["internal" ] = exchange_specification . is_internal
94+ body ["arguments" ] = {} # type: ignore
12595
12696 path = exchange_address (exchange_specification .name )
12797
128- print (path )
129-
13098 self .request (
13199 body ,
132100 path ,
@@ -138,11 +106,15 @@ def declare_exchange(self, exchange_specification: ExchangeSpecification):
138106 ],
139107 )
140108
141- def declare_queue (self , queue_specification : QueueSpecification ):
109+ return exchange_specification
110+
111+ def declare_queue (
112+ self , queue_specification : QueueSpecification
113+ ) -> QueueSpecification :
142114 body = {}
143115 body ["auto_delete" ] = queue_specification .is_auto_delete
144116 body ["durable" ] = queue_specification .is_durable
145- body ["arguments" ] = {
117+ body ["arguments" ] = { # type: ignore
146118 "x-queue-type" : queue_specification .queue_type .value ,
147119 "x-dead-letter-exchange" : queue_specification .dead_letter_exchange ,
148120 "x-dead-letter-routing-key" : queue_specification .dead_letter_routing_key ,
@@ -164,8 +136,9 @@ def declare_queue(self, queue_specification: QueueSpecification):
164136 ],
165137 )
166138
167- def delete_exchange ( self , exchange_name : str ):
139+ return queue_specification
168140
141+ def delete_exchange (self , exchange_name : str ) -> None :
169142 path = exchange_address (exchange_name )
170143
171144 print (path )
@@ -179,9 +152,7 @@ def delete_exchange(self, exchange_name:str):
179152 ],
180153 )
181154
182-
183- def delete_queue (self , queue_name :str ):
184-
155+ def delete_queue (self , queue_name : str ) -> None :
185156 path = queue_address (queue_name )
186157
187158 print (path )
@@ -195,11 +166,10 @@ def delete_queue(self, queue_name:str):
195166 ],
196167 )
197168
198- def _validate_reponse_code (self , response_code : int , expected_response_codes : list [int ]) -> None :
199-
200- print ("response code: " + str (response_code ))
201-
202- if response_code == CommonValues .response_code_409 :
169+ def _validate_reponse_code (
170+ self , response_code : int , expected_response_codes : list [int ]
171+ ) -> None :
172+ if response_code == CommonValues .response_code_409 .value :
203173 # TODO replace with a new defined Exception
204174 raise Exception ("ErrPreconditionFailed" )
205175
@@ -209,7 +179,6 @@ def _validate_reponse_code(self, response_code: int, expected_response_codes: li
209179
210180 raise Exception ("wrong response code received" )
211181
212-
213182 # TODO
214183 # def bind(self, bind_specification:BindSpecification):
215184
0 commit comments