소스 검색

fix(bridge): update emqx_bridge.conf

Shawn 4 년 전
부모
커밋
05e24b457a
3개의 변경된 파일15개의 추가작업 그리고 17개의 파일을 삭제
  1. 5 4
      apps/emqx_bridge/etc/emqx_bridge.conf
  2. 5 12
      apps/emqx_bridge/src/emqx_bridge.erl
  3. 5 1
      apps/emqx_bridge/src/emqx_bridge_http_schema.erl

+ 5 - 4
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

+ 5 - 12
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).
 

+ 5 - 1
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)).