Hi everybody,
I’m using EMQX 5.0.14.
I’m trying to use hook to add a new UserProperty to a message. I’m not very practice with erlang, but the message published doesn’t change.
Here is a little portion of the code:
on_message_publish(Message, _Env) ->
Username = maps:get(username, Message#message.headers, <<"">>),
Props = maps:get(properties, Message#message.headers, #{}),
UserProps = maps:get('User-Property', Props, []),
NewUserProps = lists:append(UserProps, [#{<<"publisher_username">> => Username}]),
NewProps = maps:put('User-Property', NewUserProps, Props),
Headers = maps:update(properties, NewProps, Message#message.headers),
NewMessage = emqx_message:set_headers(Headers, Message),
io:format("New Properties ~p~n ", [NewProps]),
io:format("New Headers ~p~n ", [Headers]),
io:format("New Publish ~p~n ~nEnv:~p~n", [emqx_message:to_map(NewMessage), _Env]),
{ok, NewMessage}.
What’s wrong with my code?
Thanks in advance
Andrea