feat(broker): reflect persisted messages in publish result

In order for callers to distinguish between silently dropped and
durably persisted message w/o matching subscribers.
This commit is contained in:
Andrew Mayorov 2023-09-18 14:46:31 +04:00
parent f4953e719b
commit e713fc38aa
No known key found for this signature in database
GPG Key ID: 2837C62ACFBFED5D
2 changed files with 12 additions and 2 deletions

View File

@ -224,8 +224,17 @@ publish(Msg) when is_record(Msg, message) ->
}),
[];
Msg1 = #message{topic = Topic} ->
_ = emqx_persistent_message:persist(Msg1),
route(aggre(emqx_router:match_routes(Topic)), delivery(Msg1))
PersistRes = persist_publish(Msg1),
PersistRes ++ route(aggre(emqx_router:match_routes(Topic)), delivery(Msg1))
end.
persist_publish(Msg) ->
case emqx_persistent_message:persist(Msg) of
ok ->
[persisted];
{_SkipOrError, _Reason} ->
% TODO: log errors?
[]
end.
%% Called internally

View File

@ -244,6 +244,7 @@
-type publish_result() :: [
{node(), topic(), deliver_result()}
| {share, topic(), deliver_result()}
| persisted
].
-type route() :: #route{}.
-type route_entry() :: {topic(), node()} | {topic, group()}.