From fcbf1bc8904ce219107734ff01538ccc1c001f0f Mon Sep 17 00:00:00 2001 From: JianBo He Date: Mon, 21 Nov 2022 21:41:00 +0800 Subject: [PATCH 1/2] fix(will-msg): fix mountpoint not working for will-msg. --- apps/emqx/src/emqx_channel.erl | 8 ++++++-- apps/emqx/test/emqx_channel_SUITE.erl | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/apps/emqx/src/emqx_channel.erl b/apps/emqx/src/emqx_channel.erl index ea35abfba..3b18c20cb 100644 --- a/apps/emqx/src/emqx_channel.erl +++ b/apps/emqx/src/emqx_channel.erl @@ -2134,10 +2134,14 @@ will_delay_interval(WillMsg) -> 0 ). -publish_will_msg(ClientInfo, Msg = #message{topic = Topic}) -> +publish_will_msg( + ClientInfo = #{mountpoint := MountPoint}, + Msg = #message{topic = Topic} +) -> case emqx_access_control:authorize(ClientInfo, publish, Topic) of allow -> - _ = emqx_broker:publish(Msg), + NMsg = emqx_mountpoint:mount(MountPoint, Msg), + _ = emqx_broker:publish(NMsg), ok; deny -> ?tp( diff --git a/apps/emqx/test/emqx_channel_SUITE.erl b/apps/emqx/test/emqx_channel_SUITE.erl index a3fa3e5bc..153f0417d 100644 --- a/apps/emqx/test/emqx_channel_SUITE.erl +++ b/apps/emqx/test/emqx_channel_SUITE.erl @@ -728,6 +728,22 @@ t_quota_qos2(_) -> del_bucket(), esockd_limiter:stop(). +t_mount_will_msg(_) -> + Self = self(), + ClientInfo = clientinfo(#{mountpoint => <<"prefix/">>}), + Msg = emqx_message:make(test, <<"will_topic">>, <<"will_payload">>), + Channel = channel(#{clientinfo => ClientInfo, will_msg => Msg}), + + ok = meck:expect(emqx_broker, publish, fun(M) -> Self ! {pub, M} end), + + {shutdown, kicked, ok, ?DISCONNECT_PACKET(?RC_ADMINISTRATIVE_ACTION), _} = emqx_channel:handle_call( + kick, Channel + ), + receive + {pub, #message{topic = <<"prefix/will_topic">>}} -> ok + after 200 -> exit(will_message_not_published_or_not_correct) + end. + %%-------------------------------------------------------------------- %% Test cases for handle_deliver %%-------------------------------------------------------------------- From a6ca124772ab7833656aa41a39655e8f5a52c205 Mon Sep 17 00:00:00 2001 From: JianBo He Date: Mon, 21 Nov 2022 21:45:02 +0800 Subject: [PATCH 2/2] chore: update changes --- changes/v5.0.11-en.md | 2 ++ changes/v5.0.11-zh.md | 2 ++ 2 files changed, 4 insertions(+) diff --git a/changes/v5.0.11-en.md b/changes/v5.0.11-en.md index 59ef42b4d..d83f9d435 100644 --- a/changes/v5.0.11-en.md +++ b/changes/v5.0.11-en.md @@ -29,3 +29,5 @@ - Fix that JWT ACL rules are only applied if an `exp` claim is set [#9368](https://github.com/emqx/emqx/pull/9368). - Fix that `/configs/global_zone` API cannot get the default value of the configuration [#9392](https://github.com/emqx/emqx/pull/9392). + +- Fix mountpoint not working for will-msg [#9399](https://github.com/emqx/emqx/pull/9399). diff --git a/changes/v5.0.11-zh.md b/changes/v5.0.11-zh.md index b48c09e7a..6bc12c5cd 100644 --- a/changes/v5.0.11-zh.md +++ b/changes/v5.0.11-zh.md @@ -26,3 +26,5 @@ - 修复 JWT ACL 规则只在设置了超期时间时才生效的问题 [#9368](https://github.com/emqx/emqx/pull/9368)。 - 修复 `/configs/global_zone` API 无法正确获取配置的默认值问题 [#9392](https://github.com/emqx/emqx/pull/9392)。 + +- 修复 mountpoint 配置未对遗嘱消息生效的问题 [#9399](https://github.com/emqx/emqx/pull/9399)