Skip to content

Commit 61f13d0

Browse files
committed
Add UUID conversion to mc_mqtt
1 parent 95c5f2e commit 61f13d0

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

deps/rabbitmq_mqtt/src/mc_mqtt.erl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,12 @@ x_header(_Key, #mqtt_msg{}) ->
397397
undefined.
398398

399399
property(correlation_id, #mqtt_msg{props = #{'Correlation-Data' := Corr}}) ->
400-
{binary, Corr};
400+
case mc_util:urn_string_to_uuid(Corr) of
401+
{ok, UUId} ->
402+
{uuid, UUId};
403+
_ ->
404+
{binary, Corr}
405+
end;
401406
property(_Key, #mqtt_msg{}) ->
402407
undefined.
403408

deps/rabbitmq_mqtt/test/mc_mqtt_SUITE.erl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,6 @@ mqtt_amqp_alt(_Config) ->
397397
[{<<"key-2">>, <<"val-2">>},
398398
{<<"key-1">>, <<"val-1">>},
399399
{<<"x-stream-filter">>, <<"apple">>}],
400-
%% TODO uuid
401400
'Correlation-Data' => CorrId,
402401
'Message-Expiry-Interval' => 1001,
403402
'Response-Topic' => <<"tmp/blah/responses">>
@@ -438,9 +437,11 @@ amqp_mqtt(_Config) ->
438437
thead2('x-list', list, [utf8(<<"l">>)]),
439438
thead2('x-map', map, [{utf8(<<"k">>), utf8(<<"v">>)}])
440439
],
440+
CorrIdOut = <<"urn:uuid:550e8400-e29b-41d4-a716-446655440000">>,
441+
{ok, CorrUUId} = mc_util:urn_string_to_uuid(CorrIdOut),
441442
M = #'v1_0.message_annotations'{content = MAC},
442443
P = #'v1_0.properties'{content_type = {symbol, <<"text/plain">>},
443-
correlation_id = {utf8, <<"corr-id">>},
444+
correlation_id = {uuid, CorrUUId},
444445
creation_time = {timestamp, 10000}
445446
},
446447
AC = [
@@ -469,6 +470,7 @@ amqp_mqtt(_Config) ->
469470
routing_keys => [<<"apple">>]},
470471
AMsg = mc:init(mc_amqp, [H, M, P, A, D], Anns),
471472
Msg = mc:convert(mc_mqtt, AMsg, Env),
473+
?assertMatch({uuid, CorrUUId}, mc:correlation_id(Msg)),
472474
Mqtt = mc:protocol_state(Msg),
473475
?assertMatch(
474476
#mqtt_msg{qos = 1,
@@ -493,11 +495,9 @@ amqp_mqtt(_Config) ->
493495
{<<"boolean">>,<<"true">>},
494496
{<<"boolean2">>,<<"false">>},
495497
{<<"null">>,<<>>}],
496-
'Correlation-Data' := <<"corr-id">>
497-
% 'Message-Expiry-Interval' := 20000
498+
'Correlation-Data' := CorrIdOut
498499
}
499500
}, Mqtt),
500-
501501
ok.
502502

503503
mqtt_msg() ->

0 commit comments

Comments
 (0)