|
|
@@ -83,7 +83,8 @@ pre_process_action_args(
|
|
|
retain := Retain,
|
|
|
payload := Payload,
|
|
|
mqtt_properties := MQTTProperties,
|
|
|
- user_properties := UserProperties
|
|
|
+ user_properties := UserProperties,
|
|
|
+ direct_dispatch := DirectDispatch
|
|
|
} = Args
|
|
|
) ->
|
|
|
Args#{
|
|
|
@@ -93,7 +94,8 @@ pre_process_action_args(
|
|
|
retain => parse_simple_var(Retain),
|
|
|
payload => parse_payload(Payload),
|
|
|
mqtt_properties => parse_mqtt_properties(MQTTProperties),
|
|
|
- user_properties => parse_user_properties(UserProperties)
|
|
|
+ user_properties => parse_user_properties(UserProperties),
|
|
|
+ direct_dispatch => parse_simple_var(DirectDispatch)
|
|
|
}
|
|
|
};
|
|
|
pre_process_action_args(_, Args) ->
|
|
|
@@ -153,7 +155,8 @@ republish(
|
|
|
topic := TopicTemplate,
|
|
|
payload := PayloadTemplate,
|
|
|
mqtt_properties := MQTTPropertiesTemplate,
|
|
|
- user_properties := UserPropertiesTemplate
|
|
|
+ user_properties := UserPropertiesTemplate,
|
|
|
+ direct_dispatch := DirectDispatchTemplate
|
|
|
}
|
|
|
}
|
|
|
) ->
|
|
|
@@ -164,6 +167,7 @@ republish(
|
|
|
Payload = iolist_to_binary(PayloadString),
|
|
|
QoS = render_simple_var(QoSTemplate, Selected, 0),
|
|
|
Retain = render_simple_var(RetainTemplate, Selected, false),
|
|
|
+ DirectDispatch = render_simple_var(DirectDispatchTemplate, Selected, false),
|
|
|
%% 'flags' is set for message re-publishes or message related
|
|
|
%% events such as message.acked and message.dropped
|
|
|
Flags0 = maps:get(flags, Env, #{}),
|
|
|
@@ -175,7 +179,8 @@ republish(
|
|
|
flags => Flags,
|
|
|
topic => Topic,
|
|
|
payload => Payload,
|
|
|
- pub_props => PubProps
|
|
|
+ pub_props => PubProps,
|
|
|
+ direct_dispatch => DirectDispatch
|
|
|
},
|
|
|
case logger:get_process_metadata() of
|
|
|
#{action_id := ActionID} ->
|
|
|
@@ -190,7 +195,7 @@ republish(
|
|
|
"republish_message",
|
|
|
TraceInfo
|
|
|
),
|
|
|
- safe_publish(RuleId, Topic, QoS, Flags, Payload, PubProps).
|
|
|
+ safe_publish(RuleId, Topic, QoS, Flags, Payload, PubProps, DirectDispatch).
|
|
|
|
|
|
%%--------------------------------------------------------------------
|
|
|
%% internal functions
|
|
|
@@ -232,7 +237,7 @@ pre_process_args(Mod, Func, Args) ->
|
|
|
false -> Args
|
|
|
end.
|
|
|
|
|
|
-safe_publish(RuleId, Topic, QoS, Flags, Payload, PubProps) ->
|
|
|
+safe_publish(RuleId, Topic, QoS, Flags, Payload, PubProps, DirectDispatch) ->
|
|
|
Msg = #message{
|
|
|
id = emqx_guid:gen(),
|
|
|
qos = QoS,
|
|
|
@@ -246,7 +251,11 @@ safe_publish(RuleId, Topic, QoS, Flags, Payload, PubProps) ->
|
|
|
payload = Payload,
|
|
|
timestamp = erlang:system_time(millisecond)
|
|
|
},
|
|
|
- case emqx_broker:safe_publish(Msg, #{hook_prohibition_as_error => true}) of
|
|
|
+ case
|
|
|
+ emqx_broker:safe_publish(Msg, #{
|
|
|
+ bypass_hook => DirectDispatch, hook_prohibition_as_error => true
|
|
|
+ })
|
|
|
+ of
|
|
|
Routes when is_list(Routes) ->
|
|
|
emqx_metrics:inc_msg(Msg),
|
|
|
ok;
|