Skip to content
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

Is there an easy way to modify web_hook to allow changing message data? #118

Open
damouse opened this issue Apr 26, 2019 · 3 comments
Open
Assignees
Labels

Comments

@damouse
Copy link

damouse commented Apr 26, 2019

I need to modify publishes in-flight from Python. I was hoping web_hook would let me do that, but then I saw this ticket that said that only lua can do that.

I plan to deploy the authentication, authorization, and modification service alongside the broker, and its very important for my application that I can manipulate those messages. In the issue above someone says its possible to modify the web_hook extension to modify data.

I don't know erlang. I could learn it, but it would take some time. Is there a simple example for how to modify the web_hook extension to modify the payload on a publish based on the results of the http call? I understand if this isn't a trivial task, thanks for your time.

@HJianBo
Copy link
Member

HJianBo commented Apr 27, 2019

Yes, you can't update any content of a publish message by the official emqx_web_hook.

So, if want using web_hook to implement this, maybe you should receive the HTTP response to update the message content in the on_message_publish callback function emqx_web_hook.erl#L189.

i.e:

on_message_publish(Message = #message{topic = Topic, flags = #{retain := Retain}}, {Filter}) ->
    with_filter(
      fun() ->
        {FromClientId, FromUsername} = format_from(Message),
        Params = [{action, message_publish},
                  {from_client_id, FromClientId},
                  {from_username, FromUsername},
                  {topic, Message#message.topic},
                  {qos, Message#message.qos},
                  {retain, Retain},
                  {payload, Message#message.payload},
                  {ts, emqx_time:now_secs(Message#message.timestamp)}],
        %% Modify these lines:
        %% send_http_request(Params),
        %% {ok, Message}
        %% To:
        Response = send_http_request(Params),
        NewMessage = parse_http_resp_to_message(Response, Message),
        {ok, NewMessage}
      end, Message, Topic, Filter).

But, you should understand the Hooks Mechnism and Erlang first!

@HJianBo HJianBo self-assigned this May 5, 2019
@HJianBo HJianBo added the Support label May 5, 2019
@slaesh
Copy link

slaesh commented Nov 8, 2021

Still not possible? @HJianBo

This request was old, maybe in the meantime things changed :)

I saw this here: https://www.emqx.com/en/blog/develop-emqx-plugin-using-python
using the hooks-api..

Use-Case: appending a timestamp to JSON-payloads.

thanks! :)

@slaesh
Copy link

slaesh commented Nov 8, 2021

nvm, found this here: https://github.com/emqx/emqx-extension-examples/tree/master/exhook-svr-go

works fine! thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants