fix: function_clause when sending messages to bridges

This commit is contained in:
Shawn 2023-01-05 18:06:01 +08:00
parent 22707495ac
commit 13b2f45405
2 changed files with 56 additions and 4 deletions

View File

@ -363,10 +363,13 @@ get_matched_egress_bridges(Topic) ->
get_matched_bridge_id(_BType, #{enable := false}, _Topic, _BName, Acc) -> get_matched_bridge_id(_BType, #{enable := false}, _Topic, _BName, Acc) ->
Acc; Acc;
get_matched_bridge_id(BType, #{local_topic := Filter}, Topic, BName, Acc) when get_matched_bridge_id(BType, Conf, Topic, BName, Acc) when ?EGRESS_DIR_BRIDGES(BType) ->
?EGRESS_DIR_BRIDGES(BType) case maps:get(local_topic, Conf, undefined) of
-> undefined ->
do_get_matched_bridge_id(Topic, Filter, BType, BName, Acc); Acc;
Filter ->
do_get_matched_bridge_id(Topic, Filter, BType, BName, Acc)
end;
get_matched_bridge_id(mqtt, #{egress := #{local := #{topic := Filter}}}, Topic, BName, Acc) -> get_matched_bridge_id(mqtt, #{egress := #{local := #{topic := Filter}}}, Topic, BName, Acc) ->
do_get_matched_bridge_id(Topic, Filter, mqtt, BName, Acc); do_get_matched_bridge_id(Topic, Filter, mqtt, BName, Acc);
get_matched_bridge_id(kafka, #{producer := #{mqtt := #{topic := Filter}}}, Topic, BName, Acc) -> get_matched_bridge_id(kafka, #{producer := #{mqtt := #{topic := Filter}}}, Topic, BName, Acc) ->

View File

@ -305,6 +305,55 @@ t_http_crud_apis(Config) ->
), ),
ok. ok.
t_http_bridges_local_topic(Config) ->
Port = ?config(port, Config),
%% assert we there's no bridges at first
{ok, 200, <<"[]">>} = request(get, uri(["bridges"]), []),
%% then we add a webhook bridge, using POST
%% POST /bridges/ will create a bridge
URL1 = ?URL(Port, "path1"),
Name1 = <<"t_http_bridges_with_local_topic1">>,
Name2 = <<"t_http_bridges_without_local_topic1">>,
%% create one http bridge with local_topic
{ok, 201, _} = request(
post,
uri(["bridges"]),
?HTTP_BRIDGE(URL1, ?BRIDGE_TYPE, Name1)
),
%% and we create another one without local_topic
{ok, 201, _} = request(
post,
uri(["bridges"]),
maps:remove(<<"local_topic">>, ?HTTP_BRIDGE(URL1, ?BRIDGE_TYPE, Name2))
),
BridgeID1 = emqx_bridge_resource:bridge_id(?BRIDGE_TYPE, Name1),
BridgeID2 = emqx_bridge_resource:bridge_id(?BRIDGE_TYPE, Name2),
%% Send an message to emqx and the message should be forwarded to the HTTP server.
%% This is to verify we can have 2 bridges with and without local_topic fields
%% at the same time.
Body = <<"my msg">>,
emqx:publish(emqx_message:make(<<"emqx_webhook/1">>, Body)),
?assert(
receive
{http_server, received, #{
method := <<"POST">>,
path := <<"/path1">>,
body := Body
}} ->
true;
Msg ->
ct:pal("error: http got unexpected request: ~p", [Msg]),
false
after 100 ->
false
end
),
%% delete the bridge
{ok, 204, <<>>} = request(delete, uri(["bridges", BridgeID1]), []),
{ok, 204, <<>>} = request(delete, uri(["bridges", BridgeID2]), []),
ok.
t_check_dependent_actions_on_delete(Config) -> t_check_dependent_actions_on_delete(Config) ->
Port = ?config(port, Config), Port = ?config(port, Config),
%% assert we there's no bridges at first %% assert we there's no bridges at first