11import uuid
22from typing import Any , Optional
3-
3+ import json
44from proton import Message , Receiver , Sender
55from proton .utils import (
66 BlockingConnection ,
77 BlockingReceiver ,
88 BlockingSender ,
99)
1010
11+ from proton ._data import Data
12+
1113from .address_helper import exchange_address , queue_address
1214from .common import CommonValues
1315from .configuration_options import (
1921 QueueSpecification ,
2022)
2123
24+ import pickle
2225
2326class Management :
2427 def __init__ (self , conn : BlockingConnection ):
25- self ._sender : Optional [Sender ] = None
26- self ._receiver : Optional [Receiver ] = None
28+ self ._sender : Optional [BlockingSender ] = None
29+ self ._receiver : Optional [BlockingReceiver ] = None
2730 self ._conn = conn
2831
2932 def open (self ) -> None :
@@ -67,25 +70,46 @@ def _request(
6770 method : str ,
6871 expected_response_codes : list [int ],
6972 ) -> None :
73+ print ("path is: " + path )
74+
75+ ## test exchange message
7076 amq_message = Message (
71- id = id ,
77+ id = '84caea92-8e38-41d4-993f-de12b2a3d9a2' ,
7278 body = body ,
7379 reply_to = "$me" ,
7480 address = path ,
7581 subject = method ,
76- properties = {"id" : id , "to" : path , "subject" : method , "reply_to" : "$me" },
82+ #properties={"id": id, "to": path, "subject": method, "reply_to": "$me"},
83+ )
84+
85+ ## test empty message
86+ amq_message = Message (
87+ #id='84caea92-8e38-41d4-993f-de12b2a3d9a2',
88+ body = Data .NULL ,
89+ #reply_to="$me",
90+ #address=path,
91+ #subject=method,
92+ #properties={"id": id, "to": path, "subject": method, "reply_to": "$me"},
7793 )
7894
79- print ("message: " + str (amq_message ))
95+ message_bytes = amq_message .encode ()
96+
97+ #print("received " + str(message_bytes.format(binary)))
98+
99+ list_bytes = list (message_bytes )
100+ print ("message: " + str (list_bytes ))
80101
81102 if self ._sender is not None :
82- print ("sending: " + method )
83103 self ._sender .send (amq_message )
84104
85105 msg = self ._receiver .receive ()
86106
107+ #message_bytes= msg.encode()
108+
87109 print ("received " + str (msg ))
88110
111+ #self._validate_reponse_code(int(msg.properties["http:response"]), expected_response_codes)
112+
89113 # TO_COMPLETE HERE
90114
91115 # TODO
@@ -96,8 +120,8 @@ def declare_exchange(self, exchange_specification: ExchangeSpecification):
96120 body ["auto_delete" ] = exchange_specification .is_auto_delete
97121 body ["durable" ] = exchange_specification .is_durable
98122 body ["type" ] = exchange_specification .exchange_type .value
99- body ["internal" ] = False
100- body ["arguments" ] = exchange_specification . arguments
123+ # body["internal"] = False
124+ body ["arguments" ] = {}
101125
102126 path = exchange_address (exchange_specification .name )
103127
@@ -140,8 +164,51 @@ def declare_queue(self, queue_specification: QueueSpecification):
140164 ],
141165 )
142166
143- # TODO
144- # def delete_exchange(self, name:str):
167+ def delete_exchange (self , exchange_name :str ):
168+
169+ path = exchange_address (exchange_name )
170+
171+ print (path )
172+
173+ self .request (
174+ Data .NULL ,
175+ path ,
176+ CommonValues .command_delete .value ,
177+ [
178+ CommonValues .response_code_200 .value ,
179+ ],
180+ )
181+
182+
183+ def delete_queue (self , queue_name :str ):
184+
185+ path = queue_address (queue_name )
186+
187+ print (path )
188+
189+ self .request (
190+ None ,
191+ path ,
192+ CommonValues .command_delete .value ,
193+ [
194+ CommonValues .response_code_200 .value ,
195+ ],
196+ )
197+
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 :
203+ # TODO replace with a new defined Exception
204+ raise Exception ("ErrPreconditionFailed" )
205+
206+ for code in expected_response_codes :
207+ if code == response_code :
208+ return None
209+
210+ raise Exception ("wrong response code received" )
211+
145212
146213 # TODO
147214 # def bind(self, bind_specification:BindSpecification):
0 commit comments