Skip to content

Commit

Permalink
Merge pull request #128 from emqx/fix-puback-hook-arity
Browse files Browse the repository at this point in the history
fix: puback hook with 5 arity
  • Loading branch information
JimMoen authored Jun 12, 2024
2 parents 37022d0 + 4e4f98f commit b46f0c5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,14 @@ test/ct.cover.spec
/.idea/
rebar3.crashdump
rebar3
erlang_ls.config
# VSCode files
.vs/
.vscode/
# Emacs Backup files
*~
# Emacs temporary files
.#*
*#
# For direnv
.envrc
11 changes: 11 additions & 0 deletions gitignore_template
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,14 @@ test/ct.cover.spec
/.idea/
rebar3.crashdump
rebar3
erlang_ls.config
# VSCode files
.vs/
.vscode/
# Emacs Backup files
*~
# Emacs temporary files
.#*
*#
# For direnv
.envrc
9 changes: 4 additions & 5 deletions src/emqx_plugin_template.erl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

%% Message Pubsub Hooks
-export([ on_message_publish/2
, on_message_puback/4
, on_message_puback/5
, on_message_delivered/3
, on_message_acked/3
, on_message_dropped/4
Expand Down Expand Up @@ -167,13 +167,12 @@ on_message_publish(Message, _Env) ->
io:format("Publish ~p~n", [emqx_message:to_map(Message)]),
{ok, Message}.

on_message_puback(_PacketId, #message{topic = _Topic} = Message, PubRes, _Env) ->
NewRC = case PubRes of
on_message_puback(_PacketId, #message{topic = _Topic} = Message, _PubRes, RC, _Env) ->
NewRC = case RC of
%% Demo: some service do not want to expose the error code (129) to client;
%% so here it remap 129 to 128
129 -> 128;
_ ->
PubRes
_ -> RC
end,
io:format("Puback ~p RC: ~p~n",
[emqx_message:to_map(Message), NewRC]),
Expand Down

0 comments on commit b46f0c5

Please sign in to comment.