8
8
9
9
-feature (maybe_expr , enable ).
10
10
11
+ -include_lib (" amqp10_common/include/amqp10_framing.hrl" ).
12
+
11
13
-export [attach_management_link_pair_sync / 2 ,
12
14
detach_management_link_pair_sync / 1 ,
13
15
declare_queue / 2 ,
@@ -140,9 +142,7 @@ declare_queue(LinkPair, QueueProperties) ->
140
142
end , [], V ),
141
143
{N , [{{utf8 , <<" arguments" >>}, {map , KVList }} | L0 ]}
142
144
end , {undefined , []}, QueueProperties ),
143
- Body1 = {map , Body0 },
144
- Body = iolist_to_binary (amqp10_framing :encode_bin (Body1 )),
145
-
145
+ Body = {map , Body0 },
146
146
QNameQuoted = uri_string :quote (QName ),
147
147
Props = #{subject => <<" PUT" >>,
148
148
to => <<" /queues/" , QNameQuoted /binary >>},
@@ -151,9 +151,10 @@ declare_queue(LinkPair, QueueProperties) ->
151
151
{ok , Resp } ->
152
152
case amqp10_msg :properties (Resp ) of
153
153
#{subject := <<" 201" >>} ->
154
- RespBody = amqp10_msg :body_bin (Resp ),
155
- [{map , KVList }] = amqp10_framing :decode_bin (RespBody ),
156
- {ok , proplists :to_map (KVList )};
154
+ # 'v1_0.amqp_value' {content = {binary , RespBin }} = amqp10_msg :body (Resp ),
155
+ [undefined ] = amqp10_framing :decode_bin (RespBin ),
156
+ % {ok, proplists:to_map(KVList)};
157
+ {ok , #{}};
157
158
Other ->
158
159
{error , Other }
159
160
end ;
@@ -179,14 +180,12 @@ bind(DestinationKind, LinkPair, Destination, Source, BindingKey, BindingArgument
179
180
when is_binary (Key ) ->
180
181
[{{utf8 , Key }, TaggedVal } | L ]
181
182
end , [], BindingArguments ),
182
- Body0 = {map , [
183
- {{utf8 , <<" source" >>}, {utf8 , Source }},
184
- {{utf8 , DestinationKind }, {utf8 , Destination }},
185
- {{utf8 , <<" binding_key" >>}, {utf8 , BindingKey }},
186
- {{utf8 , <<" arguments" >>}, {map , KVList }}
187
- ]},
188
- Body = iolist_to_binary (amqp10_framing :encode_bin (Body0 )),
189
-
183
+ Body = {map , [
184
+ {{utf8 , <<" source" >>}, {utf8 , Source }},
185
+ {{utf8 , DestinationKind }, {utf8 , Destination }},
186
+ {{utf8 , <<" binding_key" >>}, {utf8 , BindingKey }},
187
+ {{utf8 , <<" arguments" >>}, {map , KVList }}
188
+ ]},
190
189
Props = #{subject => <<" POST" >>,
191
190
to => <<" /bindings" >>},
192
191
@@ -235,12 +234,12 @@ unbind(DestinationChar, LinkPair, Destination, Source, BindingKey, BindingArgume
235
234
Props = #{subject => <<" GET" >>,
236
235
to => Uri0 },
237
236
238
- case request (LinkPair , Props , <<>> ) of
237
+ case request (LinkPair , Props , undefined ) of
239
238
{ok , Resp } ->
240
239
case amqp10_msg :properties (Resp ) of
241
240
#{subject := <<" 200" >>} ->
242
- RespBody = amqp10_msg :body_bin (Resp ),
243
- [{list , Bindings }] = amqp10_framing :decode_bin (RespBody ),
241
+ # 'v1_0.amqp_value' { content = { binary , RespBin }} = amqp10_msg :body (Resp ),
242
+ [{list , Bindings }] = amqp10_framing :decode_bin (RespBin ),
244
243
case search_binding_uri (BindingArguments , Bindings ) of
245
244
{ok , Uri } ->
246
245
delete_binding (LinkPair , Uri );
@@ -278,7 +277,7 @@ search_binding_uri(BindingArguments, [{map, Binding} | Bindings]) ->
278
277
delete_binding (LinkPair , BindingUri ) ->
279
278
Props = #{subject => <<" DELETE" >>,
280
279
to => BindingUri },
281
- case request (LinkPair , Props , <<>> ) of
280
+ case request (LinkPair , Props , undefined ) of
282
281
{ok , Resp } ->
283
282
case amqp10_msg :properties (Resp ) of
284
283
#{subject := <<" 204" >>} ->
@@ -307,15 +306,15 @@ purge_or_delete_queue(LinkPair, QueueName, PathSuffix) ->
307
306
HttpRequestTarget = <<" /queues/" , QNameQuoted /binary , PathSuffix /binary >>,
308
307
Props = #{subject => <<" DELETE" >>,
309
308
to => HttpRequestTarget },
310
- case request (LinkPair , Props , <<>> ) of
309
+ case request (LinkPair , Props , undefined ) of
311
310
{ok , Resp } ->
312
311
case amqp10_msg :properties (Resp ) of
313
312
#{subject := <<" 200" >>} ->
314
- RespBody = amqp10_msg :body_bin (Resp ),
313
+ # 'v1_0.amqp_value' { content = { binary , RespBin }} = amqp10_msg :body (Resp ),
315
314
[{map , [
316
315
{{utf8 , <<" message_count" >>}, {ulong , Count }}
317
316
]
318
- }] = amqp10_framing :decode_bin (RespBody ),
317
+ }] = amqp10_framing :decode_bin (RespBin ),
319
318
{ok , #{message_count => Count }};
320
319
_ ->
321
320
{error , Resp }
@@ -325,7 +324,7 @@ purge_or_delete_queue(LinkPair, QueueName, PathSuffix) ->
325
324
end .
326
325
327
326
-spec declare_exchange (link_pair (), exchange_properties ()) ->
328
- { ok , map ()} | {error , term ()}.
327
+ ok | {error , term ()}.
329
328
declare_exchange (LinkPair , ExchangeProperties ) ->
330
329
{XName , Body0 } = maps :fold (
331
330
fun (name , V , {undefined , L }) when is_binary (V ) ->
@@ -346,8 +345,7 @@ declare_exchange(LinkPair, ExchangeProperties) ->
346
345
end , [], V ),
347
346
{N , [{{utf8 , <<" arguments" >>}, {map , KVList }} | L0 ]}
348
347
end , {undefined , []}, ExchangeProperties ),
349
- Body1 = {map , Body0 },
350
- Body = iolist_to_binary (amqp10_framing :encode_bin (Body1 )),
348
+ Body = {map , Body0 },
351
349
352
350
XNameQuoted = uri_string :quote (XName ),
353
351
Props = #{subject => <<" PUT" >>,
@@ -357,9 +355,9 @@ declare_exchange(LinkPair, ExchangeProperties) ->
357
355
{ok , Resp } ->
358
356
case amqp10_msg :properties (Resp ) of
359
357
#{subject := <<" 201" >>} ->
360
- RespBody = amqp10_msg :body_bin (Resp ),
361
- [{ map , KVList } ] = amqp10_framing :decode_bin (RespBody ),
362
- { ok , proplists : to_map ( KVList )} ;
358
+ # 'v1_0.amqp_value' { content = { binary , RespBin }} = amqp10_msg :body (Resp ),
359
+ [undefined ] = amqp10_framing :decode_bin (RespBin ),
360
+ ok ;
363
361
_ ->
364
362
{error , Resp }
365
363
end ;
@@ -373,7 +371,7 @@ delete_exchange(LinkPair, ExchangeName) ->
373
371
XNameQuoted = uri_string :quote (ExchangeName ),
374
372
Props = #{subject => <<" DELETE" >>,
375
373
to => <<" /exchanges/" , XNameQuoted /binary >>},
376
- case request (LinkPair , Props , <<>> ) of
374
+ case request (LinkPair , Props , undefined ) of
377
375
{ok , Resp } ->
378
376
case amqp10_msg :properties (Resp ) of
379
377
#{subject := <<" 204" >>} ->
@@ -385,14 +383,15 @@ delete_exchange(LinkPair, ExchangeName) ->
385
383
Err
386
384
end .
387
385
388
- -spec request (link_pair (), amqp10_msg :amqp10_properties (), binary ()) ->
386
+ -spec request (link_pair (), amqp10_msg :amqp10_properties (), undefined | amqp10_prim ()) ->
389
387
{ok , Response :: amqp10_msg :amqp10_msg ()} | {error , term ()}.
390
388
request (# link_pair {outgoing_link = OutgoingLink ,
391
389
incoming_link = IncomingLink }, Properties , Body ) ->
392
390
MessageId = message_id (),
393
391
Properties1 = Properties #{message_id => {binary , MessageId },
394
392
reply_to => <<" $me" >>},
395
- Request = amqp10_msg :new (<<>>, Body , true ),
393
+ BodyBin = iolist_to_binary (amqp10_framing :encode_bin (Body )),
394
+ Request = amqp10_msg :new (<<>>, # 'v1_0.amqp_value' {content = {binary , BodyBin }}, true ),
396
395
Request1 = amqp10_msg :set_properties (Properties1 , Request ),
397
396
ok = amqp10_client :flow_link_credit (IncomingLink , 1 , never ),
398
397
case amqp10_client :send_msg (OutgoingLink , Request1 ) of
0 commit comments