|
@@ -39,7 +39,8 @@
|
|
|
-define(METRIC_NAME, message_transformation).
|
|
-define(METRIC_NAME, message_transformation).
|
|
|
|
|
|
|
|
-type user_property() :: #{binary() => binary()}.
|
|
-type user_property() :: #{binary() => binary()}.
|
|
|
--reflect_type([user_property/0]).
|
|
|
|
|
|
|
+-type publish_properties() :: #{binary() => binary() | integer()}.
|
|
|
|
|
+-reflect_type([user_property/0, publish_properties/0]).
|
|
|
|
|
|
|
|
%%-------------------------------------------------------------------------------------------------
|
|
%%-------------------------------------------------------------------------------------------------
|
|
|
%% `minirest' and `minirest_trails' API
|
|
%% `minirest' and `minirest_trails' API
|
|
@@ -305,7 +306,14 @@ fields(dryrun_input_message) ->
|
|
|
%% See `emqx_message_transformation:eval_context()'.
|
|
%% See `emqx_message_transformation:eval_context()'.
|
|
|
[
|
|
[
|
|
|
{client_attrs, mk(map(), #{default => #{}})},
|
|
{client_attrs, mk(map(), #{default => #{}})},
|
|
|
|
|
+ {clientid, mk(binary(), #{default => <<"test-clientid">>})},
|
|
|
{payload, mk(binary(), #{required => true})},
|
|
{payload, mk(binary(), #{required => true})},
|
|
|
|
|
+ {peername, mk(emqx_schema:ip_port(), #{default => <<"127.0.0.1:19872">>})},
|
|
|
|
|
+ {pub_props,
|
|
|
|
|
+ mk(
|
|
|
|
|
+ typerefl:alias("map()", publish_properties()),
|
|
|
|
|
+ #{default => #{}}
|
|
|
|
|
+ )},
|
|
|
{qos, mk(range(0, 2), #{default => 0})},
|
|
{qos, mk(range(0, 2), #{default => 0})},
|
|
|
{retain, mk(boolean(), #{default => false})},
|
|
{retain, mk(boolean(), #{default => false})},
|
|
|
{topic, mk(binary(), #{required => true})},
|
|
{topic, mk(binary(), #{required => true})},
|
|
@@ -313,7 +321,8 @@ fields(dryrun_input_message) ->
|
|
|
mk(
|
|
mk(
|
|
|
typerefl:alias("map(binary(), binary())", user_property()),
|
|
typerefl:alias("map(binary(), binary())", user_property()),
|
|
|
#{default => #{}}
|
|
#{default => #{}}
|
|
|
- )}
|
|
|
|
|
|
|
+ )},
|
|
|
|
|
+ {username, mk(binary(), #{required => false})}
|
|
|
];
|
|
];
|
|
|
fields(get_metrics) ->
|
|
fields(get_metrics) ->
|
|
|
[
|
|
[
|
|
@@ -728,26 +737,34 @@ dryrun_input_message_in(Params) ->
|
|
|
),
|
|
),
|
|
|
#{
|
|
#{
|
|
|
client_attrs := ClientAttrs,
|
|
client_attrs := ClientAttrs,
|
|
|
|
|
+ clientid := ClientId,
|
|
|
payload := Payload,
|
|
payload := Payload,
|
|
|
|
|
+ peername := Peername,
|
|
|
|
|
+ pub_props := PublishProperties,
|
|
|
qos := QoS,
|
|
qos := QoS,
|
|
|
retain := Retain,
|
|
retain := Retain,
|
|
|
topic := Topic,
|
|
topic := Topic,
|
|
|
user_property := UserProperty0
|
|
user_property := UserProperty0
|
|
|
} = Message0,
|
|
} = Message0,
|
|
|
|
|
+ Username = maps:get(username, Message0, undefined),
|
|
|
UserProperty = maps:to_list(UserProperty0),
|
|
UserProperty = maps:to_list(UserProperty0),
|
|
|
Message1 = #{
|
|
Message1 = #{
|
|
|
id => emqx_guid:gen(),
|
|
id => emqx_guid:gen(),
|
|
|
timestamp => emqx_message:timestamp_now(),
|
|
timestamp => emqx_message:timestamp_now(),
|
|
|
extra => #{},
|
|
extra => #{},
|
|
|
- from => <<"test-clientid">>,
|
|
|
|
|
-
|
|
|
|
|
- flags => #{retain => Retain},
|
|
|
|
|
|
|
+ from => ClientId,
|
|
|
|
|
+ flags => #{dup => false, retain => Retain},
|
|
|
qos => QoS,
|
|
qos => QoS,
|
|
|
topic => Topic,
|
|
topic => Topic,
|
|
|
payload => Payload,
|
|
payload => Payload,
|
|
|
headers => #{
|
|
headers => #{
|
|
|
client_attrs => ClientAttrs,
|
|
client_attrs => ClientAttrs,
|
|
|
- properties => #{'User-Property' => UserProperty}
|
|
|
|
|
|
|
+ peername => Peername,
|
|
|
|
|
+ properties => maps:merge(
|
|
|
|
|
+ PublishProperties,
|
|
|
|
|
+ #{'User-Property' => UserProperty}
|
|
|
|
|
+ ),
|
|
|
|
|
+ username => Username
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
Message = emqx_message:from_map(Message1),
|
|
Message = emqx_message:from_map(Message1),
|