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
1514from .configuration_options import (
2120 QueueSpecification ,
2221)
2322
24- import pickle
2523
2624class Management :
2725 def __init__ (self , conn : BlockingConnection ):
@@ -59,7 +57,6 @@ def request(
5957 method : str ,
6058 expected_response_codes : list [int ],
6159 ) -> None :
62- print ("im in request" )
6360 self ._request (str (uuid .uuid4 ()), body , path , method , expected_response_codes )
6461
6562 def _request (
@@ -70,63 +67,37 @@ def _request(
7067 method : str ,
7168 expected_response_codes : list [int ],
7269 ) -> None :
73- print ("path is: " + path )
74-
75- ## test exchange message
7670 amq_message = Message (
7771 id = id ,
7872 body = body ,
7973 reply_to = "$me" ,
8074 address = path ,
8175 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 ,
9876 )
9977
100- message_bytes = amq_message .encode ()
101- list_bytes = list (message_bytes )
102-
10378 if self ._sender is not None :
10479 self ._sender .send (amq_message )
10580
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)
81+ if self ._receiver is not None :
82+ msg = self ._receiver .receive ()
11283
113- # TO_COMPLETE HERE
84+ self . _validate_reponse_code ( int ( msg . subject ), expected_response_codes )
11485
11586 # TODO
11687 # def delete_queue(self, name:str):
11788
118- def declare_exchange (self , exchange_specification : ExchangeSpecification ):
89+ def declare_exchange (
90+ self , exchange_specification : ExchangeSpecification
91+ ) -> ExchangeSpecification :
11992 body = {}
12093 body ["auto_delete" ] = exchange_specification .is_auto_delete
12194 body ["durable" ] = exchange_specification .is_durable
122- body ["type" ] = exchange_specification .exchange_type .value
123- # body["internal"] = False
124- body ["arguments" ] = {}
95+ body ["type" ] = exchange_specification .exchange_type .value # type: ignore
96+ body ["internal" ] = exchange_specification . is_internal
97+ body ["arguments" ] = {} # type: ignore
12598
12699 path = exchange_address (exchange_specification .name )
127100
128- print (path )
129-
130101 self .request (
131102 body ,
132103 path ,
@@ -138,11 +109,15 @@ def declare_exchange(self, exchange_specification: ExchangeSpecification):
138109 ],
139110 )
140111
141- def declare_queue (self , queue_specification : QueueSpecification ):
112+ return exchange_specification
113+
114+ def declare_queue (
115+ self , queue_specification : QueueSpecification
116+ ) -> QueueSpecification :
142117 body = {}
143118 body ["auto_delete" ] = queue_specification .is_auto_delete
144119 body ["durable" ] = queue_specification .is_durable
145- body ["arguments" ] = {
120+ body ["arguments" ] = { # type: ignore
146121 "x-queue-type" : queue_specification .queue_type .value ,
147122 "x-dead-letter-exchange" : queue_specification .dead_letter_exchange ,
148123 "x-dead-letter-routing-key" : queue_specification .dead_letter_routing_key ,
@@ -164,8 +139,9 @@ def declare_queue(self, queue_specification: QueueSpecification):
164139 ],
165140 )
166141
167- def delete_exchange ( self , exchange_name : str ):
142+ return queue_specification
168143
144+ def delete_exchange (self , exchange_name : str ) -> None :
169145 path = exchange_address (exchange_name )
170146
171147 print (path )
@@ -179,9 +155,7 @@ def delete_exchange(self, exchange_name:str):
179155 ],
180156 )
181157
182-
183- def delete_queue (self , queue_name :str ):
184-
158+ def delete_queue (self , queue_name : str ) -> None :
185159 path = queue_address (queue_name )
186160
187161 print (path )
@@ -195,11 +169,10 @@ def delete_queue(self, queue_name:str):
195169 ],
196170 )
197171
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 :
172+ def _validate_reponse_code (
173+ self , response_code : int , expected_response_codes : list [int ]
174+ ) -> None :
175+ if response_code == CommonValues .response_code_409 .value :
203176 # TODO replace with a new defined Exception
204177 raise Exception ("ErrPreconditionFailed" )
205178
@@ -209,7 +182,6 @@ def _validate_reponse_code(self, response_code: int, expected_response_codes: li
209182
210183 raise Exception ("wrong response code received" )
211184
212-
213185 # TODO
214186 # def bind(self, bind_specification:BindSpecification):
215187
0 commit comments