chore(exhook): upgrade to 0.6.2
This commit is contained in:
parent
7eb6588cc9
commit
4585306774
|
@ -19,7 +19,7 @@
|
||||||
2. 将 `emqx-extension-hook` 重命名为 `emqx-exhook`
|
2. 将 `emqx-extension-hook` 重命名为 `emqx-exhook`
|
||||||
|
|
||||||
|
|
||||||
旧版本的设计参考:[emqx-extension-hook design in v4.2.0](https://github.com/emqx/emqx-exhook/blob/v4.2.0/docs/design.md)
|
旧版本的设计:[emqx-extension-hook design in v4.2.0](https://github.com/emqx/emqx-exhook/blob/v4.2.0/docs/design.md)
|
||||||
|
|
||||||
## 设计
|
## 设计
|
||||||
|
|
||||||
|
@ -39,13 +39,13 @@
|
||||||
`emqx-exhook` 通过 gRPC 的方式向用户部署的 gRPC 服务发送钩子的请求,并处理其返回的值。
|
`emqx-exhook` 通过 gRPC 的方式向用户部署的 gRPC 服务发送钩子的请求,并处理其返回的值。
|
||||||
|
|
||||||
|
|
||||||
和 emqx 原生的钩子一致,emqx-exhook 也支持链式的方式计算和返回:
|
和 emqx 原生的钩子一致,emqx-exhook 也按照链式的方式执行:
|
||||||
|
|
||||||
<img src="https://docs.emqx.net/broker/latest/cn/advanced/assets/chain_of_responsiblity.png" style="zoom:50%;" />
|
<img src="https://docs.emqx.net/broker/latest/cn/advanced/assets/chain_of_responsiblity.png" style="zoom:50%;" />
|
||||||
|
|
||||||
### gRPC 服务示例
|
### gRPC 服务示例
|
||||||
|
|
||||||
用户需要实现的方法,和数据类型的定义在 `priv/protos/exhook.proto` 文件中。例如,其支持的接口有:
|
用户需要实现的方法,和数据类型的定义在 `priv/protos/exhook.proto` 文件中:
|
||||||
|
|
||||||
```protobuff
|
```protobuff
|
||||||
syntax = "proto3";
|
syntax = "proto3";
|
|
@ -1,11 +1,11 @@
|
||||||
%%-*- mode: erlang -*-
|
%%-*- mode: erlang -*-
|
||||||
{plugins,
|
{plugins,
|
||||||
[rebar3_proper,
|
[rebar3_proper,
|
||||||
{grpc_plugin, {git, "https://github.com/HJianBo/grpcbox_plugin", {tag, "v0.10.0"}}}
|
{grpc_plugin, {git, "https://github.com/HJianBo/grpc_plugin", {tag, "v0.10.2"}}}
|
||||||
]}.
|
]}.
|
||||||
|
|
||||||
{deps,
|
{deps,
|
||||||
[{grpc, {git, "https://github.com/emqx/grpc", {tag, "0.6.0"}}}
|
[{grpc, {git, "https://github.com/emqx/grpc-erl", {tag, "0.6.2"}}}
|
||||||
]}.
|
]}.
|
||||||
|
|
||||||
{grpc,
|
{grpc,
|
||||||
|
@ -15,7 +15,9 @@
|
||||||
]}.
|
]}.
|
||||||
|
|
||||||
{provider_hooks,
|
{provider_hooks,
|
||||||
[{pre, [{compile, {grpc, gen}}]}]}.
|
[{pre, [{compile, {grpc, gen}},
|
||||||
|
{clean, {grpc, clean}}]}
|
||||||
|
]}.
|
||||||
|
|
||||||
{edoc_opts, [{preprocess, true}]}.
|
{edoc_opts, [{preprocess, true}]}.
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,12 @@
|
||||||
, on_session_terminated/3
|
, on_session_terminated/3
|
||||||
]).
|
]).
|
||||||
|
|
||||||
|
-export([ on_message_publish/1
|
||||||
|
, on_message_dropped/3
|
||||||
|
, on_message_delivered/2
|
||||||
|
, on_message_acked/2
|
||||||
|
]).
|
||||||
|
|
||||||
%% Utils
|
%% Utils
|
||||||
-export([ message/1
|
-export([ message/1
|
||||||
, stringfy/1
|
, stringfy/1
|
||||||
|
@ -71,8 +77,15 @@
|
||||||
, {'session.discarded', {?MODULE, on_session_discarded, []}}
|
, {'session.discarded', {?MODULE, on_session_discarded, []}}
|
||||||
, {'session.takeovered', {?MODULE, on_session_takeovered, []}}
|
, {'session.takeovered', {?MODULE, on_session_takeovered, []}}
|
||||||
, {'session.terminated', {?MODULE, on_session_terminated, []}}
|
, {'session.terminated', {?MODULE, on_session_terminated, []}}
|
||||||
|
%]).
|
||||||
|
, {'message.publish', {?MODULE, on_message_publish, []}}
|
||||||
|
, {'message.delivered', {?MODULE, on_message_delivered, []}}
|
||||||
|
, {'message.acked', {?MODULE, on_message_acked, []}}
|
||||||
|
, {'message.dropped', {?MODULE, on_message_dropped, []}}
|
||||||
]).
|
]).
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% Clients
|
%% Clients
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
|
@ -185,6 +198,45 @@ on_session_terminated(ClientInfo, Reason, _SessInfo) ->
|
||||||
reason => stringfy(Reason)},
|
reason => stringfy(Reason)},
|
||||||
cast('session.terminated', Req).
|
cast('session.terminated', Req).
|
||||||
|
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
|
%% Message
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
|
|
||||||
|
on_message_publish(#message{topic = <<"$SYS/", _/binary>>}) ->
|
||||||
|
ok;
|
||||||
|
on_message_publish(Message) ->
|
||||||
|
Req = #{message => message(Message)},
|
||||||
|
case call_fold('message.publish', Req,
|
||||||
|
fun emqx_exhook_handler:merge_responsed_message/2) of
|
||||||
|
{StopOrOk, #{message := NMessage}} ->
|
||||||
|
{StopOrOk, assign_to_message(NMessage, Message)};
|
||||||
|
_ -> {ok, Message}
|
||||||
|
end.
|
||||||
|
|
||||||
|
on_message_dropped(#message{topic = <<"$SYS/", _/binary>>}, _By, _Reason) ->
|
||||||
|
ok;
|
||||||
|
on_message_dropped(Message, _By, Reason) ->
|
||||||
|
Req = #{message => message(Message),
|
||||||
|
reason => stringfy(Reason)
|
||||||
|
},
|
||||||
|
cast('message.dropped', Req).
|
||||||
|
|
||||||
|
on_message_delivered(_ClientInfo, #message{topic = <<"$SYS/", _/binary>>}) ->
|
||||||
|
ok;
|
||||||
|
on_message_delivered(ClientInfo, Message) ->
|
||||||
|
Req = #{clientinfo => clientinfo(ClientInfo),
|
||||||
|
message => message(Message)
|
||||||
|
},
|
||||||
|
cast('message.delivered', Req).
|
||||||
|
|
||||||
|
on_message_acked(_ClientInfo, #message{topic = <<"$SYS/", _/binary>>}) ->
|
||||||
|
ok;
|
||||||
|
on_message_acked(ClientInfo, Message) ->
|
||||||
|
Req = #{clientinfo => clientinfo(ClientInfo),
|
||||||
|
message => message(Message)
|
||||||
|
},
|
||||||
|
cast('message.acked', Req).
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% Types
|
%% Types
|
||||||
|
|
||||||
|
|
|
@ -9,11 +9,11 @@
|
||||||
{parse_transform}]}.
|
{parse_transform}]}.
|
||||||
{plugins,
|
{plugins,
|
||||||
[rebar3_proper,
|
[rebar3_proper,
|
||||||
{grpc_plugin, {git, "https://github.com/HJianBo/grpcbox_plugin", {tag, "v0.10.0"}}}
|
{grpc_plugin, {git, "https://github.com/HJianBo/grpc_plugin", {tag, "v0.10.2"}}}
|
||||||
]}.
|
]}.
|
||||||
|
|
||||||
{deps,
|
{deps,
|
||||||
[{grpc, {git, "https://github.com/emqx/grpc", {tag, "0.6.0"}}}
|
[{grpc, {git, "https://github.com/emqx/grpc-erl", {tag, "0.6.2"}}}
|
||||||
]}.
|
]}.
|
||||||
|
|
||||||
{grpc,
|
{grpc,
|
||||||
|
@ -21,10 +21,12 @@
|
||||||
{protos, ["priv/protos"]},
|
{protos, ["priv/protos"]},
|
||||||
{gpb_opts, [{module_name_prefix, "emqx_"},
|
{gpb_opts, [{module_name_prefix, "emqx_"},
|
||||||
{module_name_suffix, "_pb"}]}
|
{module_name_suffix, "_pb"}]}
|
||||||
]}.
|
]}.
|
||||||
|
|
||||||
{provider_hooks,
|
{provider_hooks,
|
||||||
[{pre, [{compile, {grpc, gen}}]}]}.
|
[{pre, [{compile, {grpc, gen}},
|
||||||
|
{clean, {grpc, clean}}]}
|
||||||
|
]}.
|
||||||
|
|
||||||
{xref_checks, [undefined_function_calls, undefined_functions,
|
{xref_checks, [undefined_function_calls, undefined_functions,
|
||||||
locals_not_used, deprecated_function_calls,
|
locals_not_used, deprecated_function_calls,
|
||||||
|
|
Loading…
Reference in New Issue