From 2566f50c4eef995e093848c2194d917798792e5d Mon Sep 17 00:00:00 2001 From: JianBo He Date: Thu, 21 Jul 2022 11:01:18 +0800 Subject: [PATCH] fix(exhook): ensuring that exhook dispatches the client events are sequential porting by: https://github.com/emqx/emqx/pull/8311 --- CHANGES-5.0.md | 1 + apps/emqx_exhook/rebar.config | 3 +-- apps/emqx_exhook/src/emqx_exhook_server.erl | 15 ++++++++++++++- apps/emqx_gateway/rebar.config | 3 +-- rebar.config | 1 + 5 files changed, 18 insertions(+), 5 deletions(-) diff --git a/CHANGES-5.0.md b/CHANGES-5.0.md index 8f390df9d..3a6a2f953 100644 --- a/CHANGES-5.0.md +++ b/CHANGES-5.0.md @@ -14,6 +14,7 @@ * Fix AuthN JWKS SSL schema. Using schema in `emqx_schema`. [#8458](https://github.com/emqx/emqx/pull/8458) * `sentinel` field should be required when AuthN/AuthZ Redis using sentinel mode. [#8458](https://github.com/emqx/emqx/pull/8458) * Fix bad swagger format. [#8517](https://github.com/emqx/emqx/pull/8517) +* Ensuring that exhook dispatches the client events are sequential. ## Enhancements diff --git a/apps/emqx_exhook/rebar.config b/apps/emqx_exhook/rebar.config index 235d4be1b..fad539ed1 100644 --- a/apps/emqx_exhook/rebar.config +++ b/apps/emqx_exhook/rebar.config @@ -5,8 +5,7 @@ ]}. {deps, [ - {emqx, {path, "../emqx"}}, - {grpc, {git, "https://github.com/emqx/grpc-erl", {tag, "0.6.4"}}} + {emqx, {path, "../emqx"}} ]}. {grpc, [ diff --git a/apps/emqx_exhook/src/emqx_exhook_server.erl b/apps/emqx_exhook/src/emqx_exhook_server.erl index 286d062dd..832915e3f 100644 --- a/apps/emqx_exhook/src/emqx_exhook_server.erl +++ b/apps/emqx_exhook/src/emqx_exhook_server.erl @@ -369,8 +369,11 @@ match_topic_filter(TopicName, TopicFilter) -> -spec do_call(binary(), atom(), atom(), map(), map()) -> {ok, map()} | {error, term()}. do_call(ChannName, Hookpoint, Fun, Req, ReqOpts) -> - Options = ReqOpts#{channel => ChannName}, NReq = Req#{meta => emqx_exhook_handler:request_meta()}, + Options = ReqOpts#{ + channel => ChannName, + key_dispatch => key_dispatch(NReq) + }, ?SLOG(debug, #{ msg => "do_call", module => ?PB_CLIENT_MOD, @@ -481,3 +484,13 @@ available_hooks() -> 'session.terminated' | message_hooks() ]. + +%% @doc Get dispatch_key for each request +key_dispatch(_Req = #{clientinfo := #{clientid := ClientId}}) -> + ClientId; +key_dispatch(_Req = #{conninfo := #{clientid := ClientId}}) -> + ClientId; +key_dispatch(_Req = #{message := #{from := From}}) -> + From; +key_dispatch(_Req) -> + self(). diff --git a/apps/emqx_gateway/rebar.config b/apps/emqx_gateway/rebar.config index 49279e35e..272783758 100644 --- a/apps/emqx_gateway/rebar.config +++ b/apps/emqx_gateway/rebar.config @@ -2,8 +2,7 @@ {erl_opts, [debug_info]}. {deps, [ - {emqx, {path, "../emqx"}}, - {grpc, {git, "https://github.com/emqx/grpc-erl", {tag, "0.6.4"}}} + {emqx, {path, "../emqx"}} ]}. {plugins, [ diff --git a/rebar.config b/rebar.config index 7d2570636..37dce676d 100644 --- a/rebar.config +++ b/rebar.config @@ -56,6 +56,7 @@ , {esockd, {git, "https://github.com/emqx/esockd", {tag, "5.9.3"}}} , {ekka, {git, "https://github.com/emqx/ekka", {tag, "0.13.2"}}} , {gen_rpc, {git, "https://github.com/emqx/gen_rpc", {tag, "2.8.1"}}} + , {grpc, {git, "https://github.com/emqx/grpc-erl", {tag, "0.6.6"}}} , {minirest, {git, "https://github.com/emqx/minirest", {tag, "1.3.5"}}} , {ecpool, {git, "https://github.com/emqx/ecpool", {tag, "0.5.2"}}} , {replayq, "0.3.4"}