fix(emqx_channel): EMQ X replaces MQTT properties when node connects using "topic-alias-maximum" property
This commit is contained in:
parent
00bc525d8e
commit
0817761aee
|
@ -1212,14 +1212,17 @@ process_alias(_Packet, Channel) -> {ok, Channel}.
|
|||
%% Packing Topic Alias
|
||||
|
||||
packing_alias(Packet = #mqtt_packet{
|
||||
variable = #mqtt_packet_publish{topic_name = Topic} = Publish
|
||||
variable = #mqtt_packet_publish{
|
||||
topic_name = Topic,
|
||||
properties = Prop
|
||||
} = Publish
|
||||
},
|
||||
Channel = ?IS_MQTT_V5 = #channel{topic_aliases = TopicAliases, alias_maximum = Limits}) ->
|
||||
case find_alias(outbound, Topic, TopicAliases) of
|
||||
{ok, AliasId} ->
|
||||
NPublish = Publish#mqtt_packet_publish{
|
||||
topic_name = <<>>,
|
||||
properties = #{'Topic-Alias' => AliasId}
|
||||
properties = maps:merge(Prop, #{'Topic-Alias' => AliasId})
|
||||
},
|
||||
{Packet#mqtt_packet{variable = NPublish}, Channel};
|
||||
error ->
|
||||
|
@ -1232,7 +1235,7 @@ packing_alias(Packet = #mqtt_packet{
|
|||
NChannel = Channel#channel{topic_aliases = NTopicAliases},
|
||||
NPublish = Publish#mqtt_packet_publish{
|
||||
topic_name = Topic,
|
||||
properties = #{'Topic-Alias' => AliasId}
|
||||
properties = maps:merge(Prop, #{'Topic-Alias' => AliasId})
|
||||
},
|
||||
{Packet#mqtt_packet{variable = NPublish}, NChannel};
|
||||
false -> {Packet, Channel}
|
||||
|
|
|
@ -554,15 +554,29 @@ t_process_alias(_) ->
|
|||
emqx_channel:process_alias(#mqtt_packet{variable = Publish}, Channel).
|
||||
|
||||
t_packing_alias(_) ->
|
||||
Packet1 = #mqtt_packet{variable = #mqtt_packet_publish{topic_name = <<"x">>}},
|
||||
Packet1 = #mqtt_packet{variable = #mqtt_packet_publish{
|
||||
topic_name = <<"x">>,
|
||||
properties = #{'User-Property' => [{<<"k">>, <<"v">>}]}
|
||||
}},
|
||||
Packet2 = #mqtt_packet{variable = #mqtt_packet_publish{topic_name = <<"y">>}},
|
||||
Channel = emqx_channel:set_field(alias_maximum, #{outbound => 1}, channel()),
|
||||
|
||||
{RePacket1, NChannel1} = emqx_channel:packing_alias(Packet1, Channel),
|
||||
?assertEqual(#mqtt_packet{variable = #mqtt_packet_publish{topic_name = <<"x">>, properties = #{'Topic-Alias' => 1}}}, RePacket1),
|
||||
?assertEqual(#mqtt_packet{variable = #mqtt_packet_publish{
|
||||
topic_name = <<"x">>,
|
||||
properties = #{
|
||||
'Topic-Alias' => 1,
|
||||
'User-Property' => [{<<"k">>, <<"v">>}]
|
||||
}
|
||||
}}, RePacket1),
|
||||
|
||||
{RePacket2, NChannel2} = emqx_channel:packing_alias(Packet1, NChannel1),
|
||||
?assertEqual(#mqtt_packet{variable = #mqtt_packet_publish{topic_name = <<>>, properties = #{'Topic-Alias' => 1}}}, RePacket2),
|
||||
?assertEqual(#mqtt_packet{variable = #mqtt_packet_publish{
|
||||
topic_name = <<>>,
|
||||
properties = #{
|
||||
'Topic-Alias' => 1,
|
||||
'User-Property' => [{<<"k">>, <<"v">>}]
|
||||
}}}, RePacket2),
|
||||
|
||||
{RePacket3, _} = emqx_channel:packing_alias(Packet2, NChannel2),
|
||||
?assertEqual(#mqtt_packet{variable = #mqtt_packet_publish{topic_name = <<"y">>, properties = #{}}}, RePacket3),
|
||||
|
|
Loading…
Reference in New Issue