fix(bridge): update bridge with new conf failed

This commit is contained in:
Shawn 2021-09-15 11:39:32 +08:00
parent 7058b83760
commit b1999b2205
3 changed files with 48 additions and 48 deletions

View File

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

View File

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

View File

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