fix(api): publish API only returns message ID
This commit is contained in:
parent
6f077c47e7
commit
c2f176c1e7
|
@ -109,15 +109,15 @@ fields(publish_message_info) ->
|
||||||
[
|
[
|
||||||
{id,
|
{id,
|
||||||
hoconsc:mk(binary(), #{
|
hoconsc:mk(binary(), #{
|
||||||
desc => <<"Internal Message ID">>
|
desc => <<"A globally unique message ID">>
|
||||||
})}
|
})}
|
||||||
] ++ fields(message).
|
].
|
||||||
|
|
||||||
publish(post, #{body := Body}) ->
|
publish(post, #{body := Body}) ->
|
||||||
case message(Body) of
|
case message(Body) of
|
||||||
{ok, Message} ->
|
{ok, Message} ->
|
||||||
_ = emqx_mgmt:publish(Message),
|
_ = emqx_mgmt:publish(Message),
|
||||||
{200, format_message(Message)};
|
{200, format_message_response(Message)};
|
||||||
{error, R} ->
|
{error, R} ->
|
||||||
{400, 'BAD_REQUEST', to_binary(R)}
|
{400, 'BAD_REQUEST', to_binary(R)}
|
||||||
end.
|
end.
|
||||||
|
@ -126,7 +126,7 @@ publish_batch(post, #{body := Body}) ->
|
||||||
case messages(Body) of
|
case messages(Body) of
|
||||||
{ok, Messages} ->
|
{ok, Messages} ->
|
||||||
_ = [emqx_mgmt:publish(Message) || Message <- Messages],
|
_ = [emqx_mgmt:publish(Message) || Message <- Messages],
|
||||||
{200, format_message(Messages)};
|
{200, format_message_response(Messages)};
|
||||||
{error, R} ->
|
{error, R} ->
|
||||||
{400, 'BAD_REQUEST', to_binary(R)}
|
{400, 'BAD_REQUEST', to_binary(R)}
|
||||||
end.
|
end.
|
||||||
|
@ -167,19 +167,10 @@ messages([MessageMap | List], Res) ->
|
||||||
{error, R}
|
{error, R}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
format_message(Messages) when is_list(Messages) ->
|
format_message_response(Messages) when is_list(Messages) ->
|
||||||
[format_message(Message) || Message <- Messages];
|
[format_message_response(Message) || Message <- Messages];
|
||||||
format_message(#message{
|
format_message_response(#message{id = ID}) ->
|
||||||
id = ID, qos = Qos, from = From, topic = Topic, payload = Payload, flags = Flags
|
#{id => emqx_guid:to_hexstr(ID)}.
|
||||||
}) ->
|
|
||||||
#{
|
|
||||||
id => emqx_guid:to_hexstr(ID),
|
|
||||||
qos => Qos,
|
|
||||||
topic => Topic,
|
|
||||||
payload => Payload,
|
|
||||||
retain => maps:get(retain, Flags, false),
|
|
||||||
clientid => to_binary(From)
|
|
||||||
}.
|
|
||||||
|
|
||||||
to_binary(Data) when is_binary(Data) ->
|
to_binary(Data) when is_binary(Data) ->
|
||||||
Data;
|
Data;
|
||||||
|
|
Loading…
Reference in New Issue