Skip to content

Commit b112801

Browse files
committed
STOMP: move everything to binaries
1 parent 1f8a71c commit b112801

3 files changed

Lines changed: 39 additions & 39 deletions

File tree

deps/rabbitmq_mqtt/test/protocol_interop_SUITE.erl

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -482,12 +482,12 @@ amqp_mqtt(Qos, Config) ->
482482

483483
mqtt_stomp_mqtt(Config) ->
484484
{ok, StompC0} = stomp_connect(Config),
485-
ok = stomp_send(StompC0, "SUBSCRIBE", [{"destination", "/topic/t.1"},
486-
{"receipt", "my-receipt"},
487-
{"id", "subscription-888"},
488-
{"durable", "true"}]),
489-
{#stomp_frame{command = "RECEIPT",
490-
headers = [{"receipt-id","my-receipt"}]}, StompC1} = stomp_recv(StompC0),
485+
ok = stomp_send(StompC0, 'SUBSCRIBE', [{<<"destination">>, <<"/topic/t.1">>},
486+
{<<"receipt">>, <<"my-receipt">>},
487+
{<<"id">>, <<"subscription-888">>},
488+
{<<"durable">>, <<"true">>}]),
489+
{#stomp_frame{command = 'RECEIPT',
490+
headers = [{<<"receipt-id">>,<<"my-receipt">>}]}, StompC1} = stomp_recv(StompC0),
491491

492492
%% MQTT 5.0 to STOMP 1.2
493493
C = connect(<<"my-mqtt-client">>, Config),
@@ -513,40 +513,40 @@ mqtt_stomp_mqtt(Config) ->
513513
'User-Property' => UserProperty},
514514
RequestPayload, [{qos, 1}]),
515515

516-
{#stomp_frame{command = "MESSAGE",
516+
{#stomp_frame{command = 'MESSAGE',
517517
headers = Headers0,
518-
body_iolist = Body} = Msg1, StompC2} = stomp_recv(StompC1),
518+
body_iolist_rev = BodyRev} = Msg1, StompC2} = stomp_recv(StompC1),
519+
Body = lists:reverse(BodyRev),
519520
?assertEqual(RequestPayload, iolist_to_binary(Body)),
520-
Headers1 = maps:from_list(Headers0),
521-
Headers = maps:map(fun(_K, V) -> unicode:characters_to_binary(V) end, Headers1),
521+
Headers = maps:from_list(Headers0),
522522
ct:pal("Received STOMP 1.2 message:~n~p~n"
523523
"with headers map:~n~p", [Msg1, Headers]),
524524
?assertMatch(
525-
#{"content-type" := ContentType,
526-
"correlation-id" := Correlation,
527-
"destination" := <<"/topic/t.1">>,
525+
#{<<"content-type">> := ContentType,
526+
<<"correlation-id">> := Correlation,
527+
<<"destination">> := <<"/topic/t.1">>,
528528
%% With Native STOMP, this should be translated to
529529
%% reply-to: /topic/response.topic
530-
"x-reply-to-topic" := <<"response.topic">>,
531-
"subscription" := <<"subscription-888">>,
532-
"persistent" := <<"true">>,
530+
<<"x-reply-to-topic">> := <<"response.topic">>,
531+
<<"subscription">> := <<"subscription-888">>,
532+
<<"persistent">> := <<"true">>,
533533
%% The STOMP spec mandates headers to be encoded as UTF-8, but unfortunately the RabbitMQ
534534
%% STOMP implementation (as of 3.13) does not adhere and therefore does not provide UTF-8 support.
535-
% "rabbit🐇" := <<"carrot🥕"/utf8>>,
536-
% "x-rabbit🐇" := <<"carrot🥕"/utf8>>,
537-
"key" := <<"val1">>,
538-
"x-key" := <<"val1">>
535+
% <<"rabbit🐇"/utf8>> := <<"carrot🥕"/utf8>>,
536+
% <<"x-rabbit🐇"/utf8>> := <<"carrot🥕"/utf8>>,
537+
<<"key">> := <<"val1">>,
538+
<<"x-key">> := <<"val1">>
539539
},
540540
Headers),
541541

542542
%% STOMP 1.2 to MQTT 5.0
543-
ok = stomp_send(StompC2, "SEND",
544-
[{"destination", "/topic/response.topic"},
545-
{"persistent", "true"},
546-
{"content-type", "application/json"},
547-
{"correlation-id", binary_to_list(Correlation)},
548-
{"x-key", "val4"}],
549-
["{\"my\" : \"response\"}"]),
543+
ok = stomp_send(StompC2, 'SEND',
544+
[{<<"destination">>, <<"/topic/response.topic">>},
545+
{<<"persistent">>, <<"true">>},
546+
{<<"content-type">>, <<"application/json">>},
547+
{<<"correlation-id">>, Correlation},
548+
{<<"x-key">>, <<"val4">>}],
549+
[<<"{\"my\" : \"response\"}">>]),
550550
ok = stomp_disconnect(StompC2),
551551

552552
receive {publish, MqttMsg} ->
@@ -713,12 +713,12 @@ stomp_connect(Config) ->
713713
Port = rabbit_ct_broker_helpers:get_node_config(Config, 0, tcp_port_stomp),
714714
{ok, Sock} = gen_tcp:connect(localhost, Port, [{active, false}, binary]),
715715
Client0 = {Sock, []},
716-
stomp_send(Client0, "CONNECT", [{"accept-version", "1.2"}]),
717-
{#stomp_frame{command = "CONNECTED"}, Client1} = stomp_recv(Client0),
716+
stomp_send(Client0, 'CONNECT', [{<<"accept-version">>, <<"1.2">>}]),
717+
{#stomp_frame{command = 'CONNECTED'}, Client1} = stomp_recv(Client0),
718718
{ok, Client1}.
719719

720720
stomp_disconnect(Client = {Sock, _}) ->
721-
stomp_send(Client, "DISCONNECT"),
721+
stomp_send(Client, 'DISCONNECT'),
722722
gen_tcp:close(Sock).
723723

724724
stomp_send(Client, Command) ->
@@ -729,9 +729,9 @@ stomp_send(Client, Command, Headers) ->
729729

730730
stomp_send({Sock, _}, Command, Headers, Body) ->
731731
Frame = rabbit_stomp_frame:serialize(
732-
#stomp_frame{command = list_to_binary(Command),
733-
headers = Headers,
734-
body_iolist = Body}),
732+
#stomp_frame{command = Command,
733+
headers = Headers,
734+
body_iolist_rev = Body}),
735735
gen_tcp:send(Sock, Frame).
736736

737737
stomp_recv({_Sock, []} = Client) ->

deps/rabbitmq_stomp/Makefile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ PLT_APPS += rabbitmq_cli elixir ssl
3838
DEP_EARLY_PLUGINS = rabbit_common/mk/rabbitmq-early-plugin.mk
3939
DEP_PLUGINS = rabbit_common/mk/rabbitmq-plugin.mk
4040

41-
# Generate per-function CT test cases from Python test files
42-
test/python_SUITE_generated.hrl: $(wildcard test/python_SUITE_data/src/*.py) test/generate_python_tests.py
43-
python3 test/generate_python_tests.py test/python_SUITE_data/src $@
44-
45-
test/python_SUITE.erl:: test/python_SUITE_generated.hrl
41+
# Regenerate per-function CT test cases from Python test files.
42+
# The generated .hrl is committed; this rule updates it when Python sources change.
43+
# Runs only when python3 is available.
44+
test/python_SUITE_generated.hrl:: $(wildcard test/python_SUITE_data/src/*.py) test/generate_python_tests.py
45+
$(if $(shell which python3 2>/dev/null),python3 test/generate_python_tests.py test/python_SUITE_data/src $@,@echo "python3 not found, using committed $@")
4646

4747
include ../../rabbitmq-components.mk
4848
include ../../erlang.mk

deps/rabbitmq_web_stomp/src/rabbit_web_stomp_handler.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ handle_data1(Bytes, State = #state{proc_state = ProcState,
357357
end.
358358

359359
maybe_block(State = #state{state = blocking, heartbeat = Heartbeat},
360-
#stomp_frame{command = "SEND"}) ->
360+
#stomp_frame{command = 'SEND'}) ->
361361
rabbit_heartbeat:pause_monitor(Heartbeat),
362362
State#state{state = blocked};
363363
maybe_block(State, _) ->

0 commit comments

Comments
 (0)