Merge pull request #7014 from gsychev/bridge_config_topic_node_template_43
Bridge config topic node template
This commit is contained in:
commit
3af36378dd
|
@ -24,6 +24,8 @@ File format:
|
|||
* Refactor the ExProto so that anonymous clients can also be displayed on the dashboard [#6983]
|
||||
* Force shutdown of processe that cannot answer takeover event [#7026]
|
||||
|
||||
* `topic` parameter in bridge configuration can have `${node}` substitution (just like in `clientid` parameter)
|
||||
|
||||
### Bug fixes
|
||||
|
||||
* Fix the `{error,eexist}` error when do release upgrade again if last run failed. [#7121]
|
||||
|
|
|
@ -31,4 +31,4 @@
|
|||
]},
|
||||
{<<".*">>, []}
|
||||
]
|
||||
}.
|
||||
}.
|
|
@ -37,6 +37,11 @@
|
|||
, handle_disconnected/2
|
||||
]).
|
||||
|
||||
%% for testing
|
||||
-ifdef(TEST).
|
||||
-export([ replvar/1 ]).
|
||||
-endif.
|
||||
|
||||
-include_lib("emqx/include/logger.hrl").
|
||||
-include_lib("emqx/include/emqx_mqtt.hrl").
|
||||
|
||||
|
@ -176,13 +181,13 @@ subscribe_remote_topics(ClientPid, Subscriptions) ->
|
|||
end
|
||||
end, Subscriptions).
|
||||
|
||||
replvar(Options) ->
|
||||
replvar([topic, clientid, max_inflight], Options).
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
%% Internal funcs
|
||||
%%--------------------------------------------------------------------
|
||||
|
||||
replvar(Options) ->
|
||||
replvar([clientid, max_inflight], Options).
|
||||
|
||||
replvar([], Options) ->
|
||||
Options;
|
||||
replvar([Key|More], Options) ->
|
||||
|
@ -194,8 +199,8 @@ replvar([Key|More], Options) ->
|
|||
end.
|
||||
|
||||
%% ${node} => node()
|
||||
feedvar(clientid, ClientId, _) ->
|
||||
iolist_to_binary(re:replace(ClientId, "\\${node}", atom_to_list(node())));
|
||||
feedvar(Key, Value, _) when Key =:= topic; Key =:= clientid ->
|
||||
iolist_to_binary(re:replace(Value, "\\${node}", atom_to_list(node())));
|
||||
|
||||
feedvar(max_inflight, 0, _) ->
|
||||
infinity;
|
||||
|
|
|
@ -44,4 +44,15 @@ send_and_ack_test() ->
|
|||
ok = emqx_bridge_mqtt:stop(Conn)
|
||||
after
|
||||
meck:unload(emqtt)
|
||||
end.
|
||||
end.
|
||||
|
||||
replvar_test() ->
|
||||
Node = atom_to_list(node()),
|
||||
Config = #{clientid => <<"Hey ${node}">>, topic => <<"topic ${node}">>, other => <<"other">>},
|
||||
|
||||
ReplacedConfig = emqx_bridge_mqtt:replvar(Config),
|
||||
|
||||
ExpectedConfig = #{clientid => iolist_to_binary("Hey " ++ Node),
|
||||
topic => iolist_to_binary("topic " ++ Node),
|
||||
other => <<"other">>},
|
||||
?assertEqual(ExpectedConfig, ReplacedConfig).
|
||||
|
|
Loading…
Reference in New Issue