Просмотр исходного кода

fix(bridge): update bridge with new conf failed

Shawn 4 лет назад
Родитель
Сommit
b1999b2205

+ 45 - 45
apps/emqx_bridge/etc/emqx_bridge.conf

@@ -2,48 +2,48 @@
 ## EMQ X Bridge
 ##--------------------------------------------------------------------
 
-bridges.mqtt.my_mqtt_bridge_to_aws {
-    server = "127.0.0.1:1883"
-    proto_ver = "v4"
-    username = "username1"
-    password = ""
-    clean_start = true
-    keepalive = 300
-    retry_interval = "30s"
-    max_inflight = 32
-    reconnect_interval = "30s"
-    bridge_mode = true
-    replayq {
-        dir = "{{ platform_data_dir }}/replayq/bridge_mqtt/"
-        seg_bytes = "100MB"
-        offload = false
-        max_total_bytes = "1GB"
-    }
-    ssl {
-        enable = false
-        keyfile = "{{ platform_etc_dir }}/certs/client-key.pem"
-        certfile = "{{ platform_etc_dir }}/certs/client-cert.pem"
-        cacertfile = "{{ platform_etc_dir }}/certs/cacert.pem"
-    }
-    ## we will create one MQTT connection for each element of the `ingress_channels`
-    ingress_channels: [{
-        ## the `id` will be used as part of the clientid
-        id = "pull_msgs_from_aws"
-        subscribe_remote_topic = "aws/#"
-        subscribe_qos = 1
-        local_topic = "from_aws/${topic}"
-        payload = "${payload}"
-        qos = "${qos}"
-        retain = "${retain}"
-    }]
-    ## we will create one MQTT connection for each element of the `egress_channels`
-    egress_channels: [{
-        ## the `id` will be used as part of the clientid
-        id = "push_msgs_to_aws"
-        subscribe_local_topic = "emqx/#"
-        remote_topic = "from_emqx/${topic}"
-        payload = "${payload}"
-        qos = 1
-        retain = false
-    }]
-}
+#bridges.mqtt.my_mqtt_bridge_to_aws {
+#    server = "127.0.0.1:1883"
+#    proto_ver = "v4"
+#    username = "username1"
+#    password = ""
+#    clean_start = true
+#    keepalive = 300
+#    retry_interval = "30s"
+#    max_inflight = 32
+#    reconnect_interval = "30s"
+#    bridge_mode = true
+#    replayq {
+#        dir = "{{ platform_data_dir }}/replayq/bridge_mqtt/"
+#        seg_bytes = "100MB"
+#        offload = false
+#        max_total_bytes = "1GB"
+#    }
+#    ssl {
+#        enable = false
+#        keyfile = "{{ platform_etc_dir }}/certs/client-key.pem"
+#        certfile = "{{ platform_etc_dir }}/certs/client-cert.pem"
+#        cacertfile = "{{ platform_etc_dir }}/certs/cacert.pem"
+#    }
+#    ## we will create one MQTT connection for each element of the `ingress_channels`
+#    ingress_channels: [{
+#        ## the `id` will be used as part of the clientid
+#        id = "pull_msgs_from_aws"
+#        subscribe_remote_topic = "aws/#"
+#        subscribe_qos = 1
+#        local_topic = "from_aws/${topic}"
+#        payload = "${payload}"
+#        qos = "${qos}"
+#        retain = "${retain}"
+#    }]
+#    ## we will create one MQTT connection for each element of the `egress_channels`
+#    egress_channels: [{
+#        ## the `id` will be used as part of the clientid
+#        id = "push_msgs_to_aws"
+#        subscribe_local_topic = "emqx/#"
+#        remote_topic = "from_emqx/${topic}"
+#        payload = "${payload}"
+#        qos = 1
+#        retain = false
+#    }]
+#}

+ 2 - 2
apps/emqx_bridge/src/emqx_bridge.erl

@@ -149,7 +149,7 @@ create_bridge(Type, Name, Conf) ->
             {error, Reason}
     end.
 
-update_bridge(Type, Name, Conf) ->
+update_bridge(Type, Name, {_OldConf, Conf}) ->
     %% TODO: sometimes its not necessary to restart the bridge connection.
     %%
     %% - if the connection related configs like `username` is updated, we should restart/start
@@ -160,7 +160,7 @@ update_bridge(Type, Name, Conf) ->
     %%
     logger:info("update ~p bridge ~p use config: ~p", [Type, Name, Conf]),
     emqx_resource:recreate(resource_id(Type, Name),
-        emqx_bridge:resource_type(Type), Conf).
+        emqx_bridge:resource_type(Type), Conf, []).
 
 remove_bridge(Type, Name, _Conf) ->
     logger:info("remove ~p bridge ~p", [Type, Name]),

+ 1 - 1
apps/emqx_connector/src/emqx_connector_mqtt.erl

@@ -168,7 +168,7 @@ create_sub_bridge(#{name := Name} = Conf) ->
         {ok, _Pid} ->
             start_sub_bridge(Name);
         {error, {already_started, _Pid}} ->
-            ok;
+            {ok, Name};
         {error, Reason} ->
             {error, Reason}
     end.