Hooks Design

Feng Lee edited this page Jul 16, 2015 · 8 revisions


emqttd supported a simple hooks mechanism in 0.8.0 release to extend the broker. The designed is improved in 0.9.0 release.


emqttd_broker Hook API:

-export([hook/3, unhook/2, foreach_hooks/2, foldl_hooks/3]).


-spec hook(Hook :: atom(), Name :: any(), MFA :: mfa()) -> ok | {error, any()}.
hook(Hook, Name, MFA) ->


-spec unhook(Hook :: atom(), Name :: any()) -> ok | {error, any()}.
unhook(Hook, Name) ->

Foreach Hooks

-spec foreach_hooks(Hook :: atom(), Args :: list()) -> any().
foreach_hooks(Hook, Args) ->

Foldl Hooks

-spec foldl_hooks(Hook :: atom(), Args :: list(), Acc0 :: any()) -> any().
foldl_hooks(Hook, Args, Acc0) ->


Name Type Description
client.connected foreach Run when client connected successfully
client.subscribe foldl Run before client subscribe topics
client.subscribe.after foreach Run After client subscribe topics
client.unsubscribe foldl Run when client unsubscribe topics
message.publish foldl Run when message is published
message.acked foreach Run when message is acked
client.disconnected foreach Run when client is disconnnected

End-to-End Message Pub/Ack

Could use 'message.publish', 'message.acked' hooks to implement end-to-end message pub/ack:

 PktId <-- --> MsgId <-- --> MsgId <-- --> PktId
     |<--- Qos --->|<---PubSub--->|<-- Qos -->|


The design is experimental.

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.