|
@@ -82,8 +82,12 @@ make_trace_fn_action() ->
|
|
|
#{function => Fn, args => #{}}.
|
|
#{function => Fn, args => #{}}.
|
|
|
|
|
|
|
|
create_rule_http(RuleParams) ->
|
|
create_rule_http(RuleParams) ->
|
|
|
|
|
+ create_rule_http(RuleParams, _Overrides = #{}).
|
|
|
|
|
+
|
|
|
|
|
+create_rule_http(RuleParams, Overrides) ->
|
|
|
RepublishTopic = <<"republish/schema_registry">>,
|
|
RepublishTopic = <<"republish/schema_registry">>,
|
|
|
emqx:subscribe(RepublishTopic),
|
|
emqx:subscribe(RepublishTopic),
|
|
|
|
|
+ PayloadTemplate = maps:get(payload_template, Overrides, <<>>),
|
|
|
DefaultParams = #{
|
|
DefaultParams = #{
|
|
|
enable => true,
|
|
enable => true,
|
|
|
actions => [
|
|
actions => [
|
|
@@ -93,7 +97,7 @@ create_rule_http(RuleParams) ->
|
|
|
<<"args">> =>
|
|
<<"args">> =>
|
|
|
#{
|
|
#{
|
|
|
<<"topic">> => RepublishTopic,
|
|
<<"topic">> => RepublishTopic,
|
|
|
- <<"payload">> => <<>>,
|
|
|
|
|
|
|
+ <<"payload">> => PayloadTemplate,
|
|
|
<<"qos">> => 0,
|
|
<<"qos">> => 0,
|
|
|
<<"retain">> => false,
|
|
<<"retain">> => false,
|
|
|
<<"user_properties">> => <<>>
|
|
<<"user_properties">> => <<>>
|
|
@@ -177,10 +181,12 @@ test_params_for(avro, encode1) ->
|
|
|
"from t\n"
|
|
"from t\n"
|
|
|
>>,
|
|
>>,
|
|
|
Payload = #{<<"i">> => 10, <<"s">> => <<"text">>},
|
|
Payload = #{<<"i">> => 10, <<"s">> => <<"text">>},
|
|
|
|
|
+ PayloadTemplate = <<"${.encoded}">>,
|
|
|
ExtraArgs = [],
|
|
ExtraArgs = [],
|
|
|
#{
|
|
#{
|
|
|
sql => SQL,
|
|
sql => SQL,
|
|
|
payload => Payload,
|
|
payload => Payload,
|
|
|
|
|
+ payload_template => PayloadTemplate,
|
|
|
extra_args => ExtraArgs
|
|
extra_args => ExtraArgs
|
|
|
};
|
|
};
|
|
|
test_params_for(avro, decode1) ->
|
|
test_params_for(avro, decode1) ->
|
|
@@ -251,10 +257,12 @@ test_params_for(protobuf, encode1) ->
|
|
|
"from t\n"
|
|
"from t\n"
|
|
|
>>,
|
|
>>,
|
|
|
Payload = #{<<"name">> => <<"some name">>, <<"id">> => 10, <<"email">> => <<"emqx@emqx.io">>},
|
|
Payload = #{<<"name">> => <<"some name">>, <<"id">> => 10, <<"email">> => <<"emqx@emqx.io">>},
|
|
|
|
|
+ PayloadTemplate = <<"${.encoded}">>,
|
|
|
ExtraArgs = [<<"Person">>],
|
|
ExtraArgs = [<<"Person">>],
|
|
|
#{
|
|
#{
|
|
|
sql => SQL,
|
|
sql => SQL,
|
|
|
payload => Payload,
|
|
payload => Payload,
|
|
|
|
|
+ payload_template => PayloadTemplate,
|
|
|
extra_args => ExtraArgs
|
|
extra_args => ExtraArgs
|
|
|
};
|
|
};
|
|
|
test_params_for(protobuf, union1) ->
|
|
test_params_for(protobuf, union1) ->
|
|
@@ -487,17 +495,18 @@ t_encode(Config) ->
|
|
|
#{
|
|
#{
|
|
|
sql := SQL,
|
|
sql := SQL,
|
|
|
payload := Payload,
|
|
payload := Payload,
|
|
|
|
|
+ payload_template := PayloadTemplate,
|
|
|
extra_args := ExtraArgs
|
|
extra_args := ExtraArgs
|
|
|
} = test_params_for(SerdeType, encode1),
|
|
} = test_params_for(SerdeType, encode1),
|
|
|
- {ok, _} = create_rule_http(#{sql => SQL}),
|
|
|
|
|
|
|
+ {ok, _} = create_rule_http(#{sql => SQL}, #{payload_template => PayloadTemplate}),
|
|
|
PayloadBin = emqx_utils_json:encode(Payload),
|
|
PayloadBin = emqx_utils_json:encode(Payload),
|
|
|
emqx:publish(emqx_message:make(<<"t">>, PayloadBin)),
|
|
emqx:publish(emqx_message:make(<<"t">>, PayloadBin)),
|
|
|
Published = receive_published(?LINE),
|
|
Published = receive_published(?LINE),
|
|
|
?assertMatch(
|
|
?assertMatch(
|
|
|
- #{payload := #{<<"encoded">> := _}},
|
|
|
|
|
|
|
+ #{payload := P} when is_binary(P),
|
|
|
Published
|
|
Published
|
|
|
),
|
|
),
|
|
|
- #{payload := #{<<"encoded">> := Encoded}} = Published,
|
|
|
|
|
|
|
+ #{payload := Encoded} = Published,
|
|
|
{ok, #{deserializer := Deserializer}} = emqx_ee_schema_registry:get_serde(SerdeName),
|
|
{ok, #{deserializer := Deserializer}} = emqx_ee_schema_registry:get_serde(SerdeName),
|
|
|
?assertEqual(Payload, apply(Deserializer, [Encoded | ExtraArgs])),
|
|
?assertEqual(Payload, apply(Deserializer, [Encoded | ExtraArgs])),
|
|
|
ok.
|
|
ok.
|