Set topic alias when publish retained message
- remove topic alias from message props when storing retained msgs - set topic alias for outbound before sending retained msgs
This commit is contained in:
parent
0e00e3479e
commit
08fd9d00e3
|
|
@ -395,7 +395,7 @@ process_request(?PUBLISH,
|
||||||
dup = Dup,
|
dup = Dup,
|
||||||
packet_id = PacketId,
|
packet_id = PacketId,
|
||||||
payload = Payload,
|
payload = Payload,
|
||||||
props = Props},
|
props = maps:remove('Topic-Alias', Props)},
|
||||||
case EffectiveQos of
|
case EffectiveQos of
|
||||||
?QOS_0 ->
|
?QOS_0 ->
|
||||||
publish_to_queues_with_checks(Msg, State);
|
publish_to_queues_with_checks(Msg, State);
|
||||||
|
|
@ -963,14 +963,15 @@ send_retained_message(TopicFilter0, SubscribeQos,
|
||||||
#mqtt_msg{qos = MsgQos,
|
#mqtt_msg{qos = MsgQos,
|
||||||
retain = Retain,
|
retain = Retain,
|
||||||
payload = Payload,
|
payload = Payload,
|
||||||
props = Props} ->
|
props = Props0} ->
|
||||||
Qos = effective_qos(MsgQos, SubscribeQos),
|
Qos = effective_qos(MsgQos, SubscribeQos),
|
||||||
|
{Topic, Props, State1} = process_topic_alias_outbound(TopicFilter, Props0, State0),
|
||||||
{PacketId, State} = case Qos of
|
{PacketId, State} = case Qos of
|
||||||
?QOS_0 ->
|
?QOS_0 ->
|
||||||
{undefined, State0};
|
{undefined, State1};
|
||||||
?QOS_1 ->
|
?QOS_1 ->
|
||||||
{PacketId0,
|
{PacketId0,
|
||||||
State0#state{packet_id = increment_packet_id(PacketId0)}}
|
State1#state{packet_id = increment_packet_id(PacketId0)}}
|
||||||
end,
|
end,
|
||||||
Packet = #mqtt_packet{
|
Packet = #mqtt_packet{
|
||||||
fixed = #mqtt_packet_fixed{
|
fixed = #mqtt_packet_fixed{
|
||||||
|
|
@ -983,7 +984,7 @@ send_retained_message(TopicFilter0, SubscribeQos,
|
||||||
packet_id = PacketId,
|
packet_id = PacketId,
|
||||||
%% Wildcards are currently not supported when fetching retained
|
%% Wildcards are currently not supported when fetching retained
|
||||||
%% messages. Therefore, TopicFilter must must be a topic name.
|
%% messages. Therefore, TopicFilter must must be a topic name.
|
||||||
topic_name = TopicFilter,
|
topic_name = Topic,
|
||||||
props = Props
|
props = Props
|
||||||
},
|
},
|
||||||
payload = Payload},
|
payload = Payload},
|
||||||
|
|
|
||||||
|
|
@ -125,6 +125,8 @@ cluster_size_1_tests() ->
|
||||||
topic_alias_invalid,
|
topic_alias_invalid,
|
||||||
topic_alias_unknown,
|
topic_alias_unknown,
|
||||||
topic_alias_disallowed,
|
topic_alias_disallowed,
|
||||||
|
topic_alias_in_retained_message,
|
||||||
|
topic_alias_diallowed_retained_message,
|
||||||
extended_auth
|
extended_auth
|
||||||
].
|
].
|
||||||
|
|
||||||
|
|
@ -1958,6 +1960,26 @@ topic_alias_disallowed(Config) ->
|
||||||
|
|
||||||
ok = rpc(Config, persistent_term, put, [Key, DefaultMax]).
|
ok = rpc(Config, persistent_term, put, [Key, DefaultMax]).
|
||||||
|
|
||||||
|
topic_alias_in_retained_message(Config) ->
|
||||||
|
topic_alias_in_retained_message_test(Config, 1, 10, #{'Topic-Alias' => 1}).
|
||||||
|
|
||||||
|
topic_alias_diallowed_retained_message(Config) ->
|
||||||
|
topic_alias_in_retained_message_test(Config, 0, 1, #{}).
|
||||||
|
|
||||||
|
topic_alias_in_retained_message_test(Config, ClientAliasMax, MsgAlias, ExpectedProps) ->
|
||||||
|
Topic = ClientId = atom_to_binary(?FUNCTION_NAME),
|
||||||
|
C = connect(ClientId, Config, [{properties, #{'Topic-Alias-Maximum' => ClientAliasMax}}]),
|
||||||
|
{ok, _} = emqtt:publish(C, Topic, #{'Topic-Alias' => MsgAlias}, <<"m1">>, [{retain, true}, {qos, 1}]),
|
||||||
|
|
||||||
|
{ok, _, [1]} = emqtt:subscribe(C, Topic, [{qos, 1}]),
|
||||||
|
receive {publish, #{payload := <<"m1">>,
|
||||||
|
topic := Topic,
|
||||||
|
retain := true,
|
||||||
|
properties := ExpectedProps}} -> ok
|
||||||
|
after 500 -> ct:fail("Did not receive m1")
|
||||||
|
end,
|
||||||
|
ok = emqtt:disconnect(C).
|
||||||
|
|
||||||
extended_auth(Config) ->
|
extended_auth(Config) ->
|
||||||
{C, Connect} = start_client(?FUNCTION_NAME, Config, 0,
|
{C, Connect} = start_client(?FUNCTION_NAME, Config, 0,
|
||||||
[{properties, #{'Authentication-Method' => <<"OTP">>,
|
[{properties, #{'Authentication-Method' => <<"OTP">>,
|
||||||
|
|
@ -1999,3 +2021,4 @@ assert_nothing_received(Timeout) ->
|
||||||
receive Unexpected -> ct:fail("Received unexpected message: ~p", [Unexpected])
|
receive Unexpected -> ct:fail("Received unexpected message: ~p", [Unexpected])
|
||||||
after Timeout -> ok
|
after Timeout -> ok
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue