New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
1121 rule bridge properties #9398
Conversation
7ac33a6
to
ae87253
Compare
@@ -110,8 +110,9 @@ republish( | |||
Payload = format_msg(PayloadTks, Selected), | |||
QoS = replace_simple_var(QoSTks, Selected, 0), | |||
Retain = replace_simple_var(RetainTks, Selected, false), | |||
PubProps = maps:get(pub_props, OriginalMsg, #{}), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was originally (#9240) taken from Selected
's pub_props
atom filed,
which seemed to be wrong because selected element keys are of binary format. (i.e. <<"pub_props">>
).
I tried to change to take from the original message, it seemed to work, however it also affects
other events like message.dropped
, message.acked
, in those events, a user may not necessary
want to keep the properties.
For example, if someone just want to republish a message.dropped
event, but only interested in the topic name.
Fixed to pick <<"pub_props">>
value from Selected
, but try to convert properties to atom keys,
this requires user to explicitly SELECT pub_props
(see test case examples).
The "proper" approach is perhaps to treat message properties like qos
, retain
flag, and payload
,
meaning to add another argument here:
emqx/apps/emqx_rule_engine/src/emqx_rule_engine_schema.erl
Lines 139 to 177 in 966e6dd
fields("republish_args") -> | |
[ | |
{topic, | |
?HOCON( | |
binary(), | |
#{ | |
desc => ?DESC("republish_args_topic"), | |
required => true, | |
example => <<"a/1">> | |
} | |
)}, | |
{qos, | |
?HOCON( | |
qos(), | |
#{ | |
desc => ?DESC("republish_args_qos"), | |
default => <<"${qos}">>, | |
example => <<"${qos}">> | |
} | |
)}, | |
{retain, | |
?HOCON( | |
hoconsc:union([boolean(), binary()]), | |
#{ | |
desc => ?DESC("republish_args_retain"), | |
default => <<"${retain}">>, | |
example => <<"${retain}">> | |
} | |
)}, | |
{payload, | |
?HOCON( | |
binary(), | |
#{ | |
desc => ?DESC("republish_args_payload"), | |
default => <<"${payload}">>, | |
example => <<"${payload}">> | |
} | |
)} | |
]. |
@terry-xiaoyu @kjellwinblad @thalesmg wdyt ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we need a 'properties' config in this case.
- If the 'properties' is not configured and it's a PUBLISH message, we republish the message using the original properties.
- If the 'properties' is not configured and it's an event like
$events/client_connected
, we republish the message without any property. - If the 'properties' is configured, then we republish using the configured properties.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The "proper" approach is perhaps to treat message properties like qos, retain flag, and payload,
meaning to add another argument here:
Based on my limited understanding I also think this would be the the proper approach
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From my very limited knowledge about this, it seems like the props should indeed be a new config; otherwise, it's not obvious that a property should be dropped or not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your suggestions.
I have added a user_properties
republish action argument with default template ${user_properties}
.
Decided NOT to fill user_properties
with original message's pub_props.'User-Property'
,
because the code is shared for both message republish and for message events such as message.acked
and message.dropped
.
In order to republish message with User-Property
, a user will have to explicitly select a variable,
or configure with the special value ${pub_props.'User-Property'}
.
4945bd4
to
9e45ad1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me (just a few minor comments about sleeps in test cases).
5f9b7f0
to
f70f18d
Compare
Topic = emqx_plugin_libs_rule:proc_tmpl(TopicTks, Selected), | ||
Payload = format_msg(PayloadTks, Selected), | ||
QoS = replace_simple_var(QoSTks, Selected, 0), | ||
Retain = replace_simple_var(RetainTks, Selected, false), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these three lines duplicates line 113-116, so i merged the two function clauses.
the only special part is the flags
field.
37d187e
to
7a309c8
Compare
7a309c8
to
f3df2c8
Compare
Pull Request Test Coverage Report for Build 3526362825
💛 - Coveralls |
this is a follow up for #9240