Skip to content

Commit

Permalink
Merge pull request emqx#14182 from thalesmg/20241107-m-delayed-publis…
Browse files Browse the repository at this point in the history
…h-api-200

fix(publish api): return 200 for delayed messages
  • Loading branch information
thalesmg authored Nov 11, 2024
2 parents c5f07c5 + 98868c3 commit f95795f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions apps/emqx_management/src/emqx_mgmt_api_publish.erl
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,8 @@ is_ok_deliver({_NodeOrShare, _MatchedTopic, {error, _}}) -> false.
%% No preceding payload format indicator to compare against.
%% Content-Type check should be done at HTTP layer but not here.
%% 153 Payload format invalid 400
publish_result_to_http_reply(#message{topic = <<"$delayed/", _/binary>>} = Message, []) ->
{?ALL_IS_WELL, make_publish_response(Message)};
publish_result_to_http_reply(_Message, []) ->
%% matched no subscriber
{?PARTIALLY_OK, make_publish_error_response(?RC_NO_MATCHING_SUBSCRIBERS)};
Expand Down
21 changes: 21 additions & 0 deletions apps/emqx_management/test/emqx_mgmt_api_publish_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,27 @@ t_publish_offline_api(_) ->
ResponseMap = decode_json(Response),
?assertEqual([<<"id">>], lists:sort(maps:keys(ResponseMap))).

%% Checks that we return HTTP response status code 200 for delayed messages, even if there
%% are no subscribers at the time of publishing.
t_delayed_message_always_200({init, Config}) ->
Config;
t_delayed_message_always_200({'end', _Config}) ->
ok;
t_delayed_message_always_200(Config) when is_list(Config) ->
Request = #{
<<"topic">> => <<"$delayed/1/t">>,
<<"payload">> => <<"delayed">>
},
?assertMatch(
{200, #{<<"id">> := _}},
emqx_mgmt_api_test_util:simple_request(
post,
emqx_mgmt_api_test_util:api_path(["publish"]),
Request
)
),
ok.

receive_assert(Topic, Qos, Payload) ->
receive
{publish, Message} ->
Expand Down
1 change: 1 addition & 0 deletions changes/ce/fix-14182.en.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Previously, if a delayed message was published via the `POST /publish` HTTP API, a 202 reponse with the reason code 16 ("no matching subscribers") would be returned. Now, a 200 response is sent along with the message identifier.

0 comments on commit f95795f

Please sign in to comment.