From 05e24b457ab7b5ce8b3600ce97c55c4f33a4dc35 Mon Sep 17 00:00:00 2001 From: Shawn <506895667@qq.com> Date: Sat, 18 Dec 2021 20:53:14 +0800 Subject: [PATCH] fix(bridge): update emqx_bridge.conf --- apps/emqx_bridge/etc/emqx_bridge.conf | 9 +++++---- apps/emqx_bridge/src/emqx_bridge.erl | 17 +++++------------ .../emqx_bridge/src/emqx_bridge_http_schema.erl | 6 +++++- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/apps/emqx_bridge/etc/emqx_bridge.conf b/apps/emqx_bridge/etc/emqx_bridge.conf index fdd4005bf..04f4709b8 100644 --- a/apps/emqx_bridge/etc/emqx_bridge.conf +++ b/apps/emqx_bridge/etc/emqx_bridge.conf @@ -9,10 +9,10 @@ # direction = ingress # ## topic mappings for this bridge # remote_topic = "aws/#" -# subscribe_qos = 1 +# remote_qos = 1 # local_topic = "from_aws/${topic}" +# local_qos = "${qos}" # payload = "${payload}" -# qos = "${qos}" # retain = "${retain}" #} # @@ -23,14 +23,15 @@ # ## topic mappings for this bridge # local_topic = "emqx/#" # remote_topic = "from_emqx/${topic}" +# remote_qos = "${qos}" # payload = "${payload}" -# qos = 1 # retain = false #} # ## HTTP bridges to an HTTP server #bridges.http.my_http_bridge { # enable = true +# direction = egress # ## NOTE: we cannot use placehodler variables in the `scheme://host:port` part of the url # url = "http://localhost:9901/messages/${topic}" # request_timeout = "30s" @@ -47,7 +48,7 @@ # cacertfile = "{{ platform_etc_dir }}/certs/cacert.pem" # } # -# from_local_topic = "emqx_http/#" +# local_topic = "emqx_http/#" # ## the following config entries can use placehodler variables: # ## url, method, body, headers # method = post diff --git a/apps/emqx_bridge/src/emqx_bridge.erl b/apps/emqx_bridge/src/emqx_bridge.erl index ad3fee858..1e11046db 100644 --- a/apps/emqx_bridge/src/emqx_bridge.erl +++ b/apps/emqx_bridge/src/emqx_bridge.erl @@ -68,14 +68,9 @@ load_hook(Bridges) -> end, maps:to_list(Bridges)). do_load_hook(#{local_topic := _} = Conf) -> - case maps:find(direction, Conf) of - error -> - %% this bridge has no direction field, it means that it has only egress bridges - emqx_hooks:put('message.publish', {?MODULE, on_message_publish, []}); - {ok, egress} -> - emqx_hooks:put('message.publish', {?MODULE, on_message_publish, []}); - {ok, ingress} -> - ok + case maps:get(direction, Conf, egress) of + egress -> emqx_hooks:put('message.publish', {?MODULE, on_message_publish, []}); + ingress -> ok end; do_load_hook(_Conf) -> ok. @@ -276,10 +271,8 @@ get_matched_bridges(Topic) -> (_BName, #{direction := ingress}, Acc1) -> Acc1; (BName, #{direction := egress} = Egress, Acc1) -> - get_matched_bridge_id(Egress, Topic, BType, BName, Acc1); - %% HTTP, MySQL bridges only have egress direction - (BName, BridgeConf, Acc1) -> - get_matched_bridge_id(BridgeConf, Topic, BType, BName, Acc1) + %% HTTP, MySQL bridges only have egress direction + get_matched_bridge_id(Egress, Topic, BType, BName, Acc1) end, Acc0, Conf) end, [], Bridges). diff --git a/apps/emqx_bridge/src/emqx_bridge_http_schema.erl b/apps/emqx_bridge/src/emqx_bridge_http_schema.erl index 88cc90db7..43cace332 100644 --- a/apps/emqx_bridge/src/emqx_bridge_http_schema.erl +++ b/apps/emqx_bridge/src/emqx_bridge_http_schema.erl @@ -81,9 +81,13 @@ fields("get") -> basic_config() -> [ {enable, mk(boolean(), - #{ desc =>"Enable or disable this bridge" + #{ desc => "Enable or disable this bridge" , default => true })} + , {direction, + mk(egress, + #{ desc => "The direction of this bridge, MUST be egress" + })} ] ++ proplists:delete(base_url, emqx_connector_http:fields(config)).