Explorar el Código

refactor: move ?REDISPATCH_TO macro to emqx_mqtt.hrl

JimMoen hace 2 años
padre
commit
d563121284

+ 2 - 0
apps/emqx/include/emqx_mqtt.hrl

@@ -675,6 +675,8 @@ end).
 -define(QUEUE, "$queue").
 -define(SHARE(Group, Topic), emqx_topic:join([<<?SHARE>>, Group, Topic])).
 
+-define(REDISPATCH_TO(GROUP, TOPIC), {GROUP, TOPIC}).
+
 -define(SHARE_EMPTY_FILTER, share_subscription_topic_cannot_be_empty).
 -define(SHARE_EMPTY_GROUP, share_subscription_group_name_cannot_be_empty).
 -define(SHARE_RECURSIVELY, '$share_cannot_be_used_as_real_topic_filter').

+ 1 - 1
apps/emqx/src/emqx_session.erl

@@ -412,7 +412,7 @@ enrich_delivers(ClientInfo, [D | Rest], UpgradeQoS, Session) ->
 enrich_deliver(ClientInfo, {deliver, Topic, Msg}, UpgradeQoS, Session) ->
     SubOpts =
         case Msg of
-            #message{headers = #{redispatch_to := {Group, T}}} ->
+            #message{headers = #{redispatch_to := ?REDISPATCH_TO(Group, T)}} ->
                 ?IMPL(Session):get_subscription(emqx_topic:make_shared_record(Group, T), Session);
             _ ->
                 ?IMPL(Session):get_subscription(Topic, Session)

+ 0 - 1
apps/emqx/src/emqx_shared_sub.erl

@@ -95,7 +95,6 @@
 -define(ACK, shared_sub_ack).
 -define(NACK(Reason), {shared_sub_nack, Reason}).
 -define(NO_ACK, no_ack).
--define(REDISPATCH_TO(GROUP, TOPIC), {GROUP, TOPIC}).
 -define(SUBSCRIBER_DOWN, noproc).
 
 -type redispatch_to() :: ?REDISPATCH_TO(emqx_types:group(), emqx_types:topic()).

+ 1 - 1
apps/emqx/test/emqx_broker_SUITE.erl

@@ -309,7 +309,7 @@ t_shared_subscribe(Config) when is_list(Config) ->
     ?assert(
         receive
             {deliver, <<"topic">>, #message{
-                headers = #{redispatch_to := {<<"group">>, <<"topic">>}},
+                headers = #{redispatch_to := ?REDISPATCH_TO(<<"group">>, <<"topic">>)},
                 payload = <<"hello">>
             }} ->
                 true;

+ 2 - 1
apps/emqx_rule_engine/test/emqx_rule_events_SUITE.erl

@@ -20,6 +20,7 @@
 -compile(nowarn_export_all).
 
 -include_lib("eunit/include/eunit.hrl").
+-include_lib("emqx/include/emqx_mqtt.hrl").
 
 all() -> emqx_common_test_helpers:all(?MODULE).
 
@@ -42,7 +43,7 @@ t_printable_maps(_) ->
         peerhost => {127, 0, 0, 1},
         peername => {{127, 0, 0, 1}, 9980},
         sockname => {{127, 0, 0, 1}, 1883},
-        redispatch_to => {<<"group">>, <<"sub/topic/+">>},
+        redispatch_to => ?REDISPATCH_TO(<<"group">>, <<"sub/topic/+">>),
         shared_dispatch_ack => {self(), ref}
     },
     Converted = emqx_rule_events:printable_maps(Headers),