GithubHelp home page GithubHelp logo

emqx / emqx-web-hook Goto Github PK

View Code? Open in Web Editor NEW
77.0 23.0 36.0 426 KB

EMQX Webhook Plugin

Home Page: https://www.emqx.com

License: Apache License 2.0

Erlang 99.01% Makefile 0.99%
emqttd mqtt webhook plugin broker mqtt-broker erlang emq

emqx-web-hook's Introduction

emqx-web-hook

EMQX WebHook plugin.

Please see: EMQX - WebHook

emqx_web_hook.conf

## The web services URL for Hook request
##
## Value: String
web.hook.api.url = http://127.0.0.1:8080

## Encode message payload field
##
## Value: base64 | base62
## web.hook.encode_payload = base64

##--------------------------------------------------------------------
## Hook Rules

## These configuration items represent a list of events should be forwarded
##
## Format:
##   web.hook.rule.<HookName>.<No> = <Spec>
web.hook.rule.client.connect.1       = {"action": "on_client_connect"}
web.hook.rule.client.connack.1       = {"action": "on_client_connack"}
web.hook.rule.client.connected.1     = {"action": "on_client_connected"}
web.hook.rule.client.disconnected.1  = {"action": "on_client_disconnected"}
web.hook.rule.client.subscribe.1     = {"action": "on_client_subscribe"}
web.hook.rule.client.unsubscribe.1   = {"action": "on_client_unsubscribe"}
web.hook.rule.session.subscribed.1   = {"action": "on_session_subscribed"}
web.hook.rule.session.unsubscribed.1 = {"action": "on_session_unsubscribed"}
web.hook.rule.session.terminated.1   = {"action": "on_session_terminated"}
web.hook.rule.message.publish.1      = {"action": "on_message_publish"}
web.hook.rule.message.delivered.1    = {"action": "on_message_delivered"}
web.hook.rule.message.acked.1        = {"action": "on_message_acked"}

API

The HTTP request parameter format:

  • client.connected
{
    "action":"client_connected",
    "clientid":"C_1492410235117",
    "username":"C_1492410235117",
    "keepalive": 60,
    "ipaddress": "127.0.0.1",
    "proto_ver": 4,
    "connected_at": 1556176748,
    "conn_ack":0
}
  • client.disconnected
{
    "action":"client_disconnected",
    "clientid":"C_1492410235117",
    "username":"C_1492410235117",
    "reason":"normal"
}
  • client.subscribe
{
    "action":"client_subscribe",
    "clientid":"C_1492410235117",
    "username":"C_1492410235117",
    "topic":"world",
    "opts":{
        "qos":0
    }
}
  • client.unsubscribe
{
    "action":"client_unsubscribe",
    "clientid":"C_1492410235117",
    "username":"C_1492410235117",
    "topic":"world"
}
  • session.created
{
    "action":"session_created",
    "clientid":"C_1492410235117",
    "username":"C_1492410235117"
}
  • session.subscribed
{
    "action":"session_subscribed",
    "clientid":"C_1492410235117",
    "username":"C_1492410235117",
    "topic":"world",
    "opts":{
        "qos":0
    }
}
  • session.unsubscribed
{
    "action":"session_unsubscribed",
    "clientid":"C_1492410235117",
    "username":"C_1492410235117",
    "topic":"world"
}
  • session.terminated
{
    "action":"session_terminated",
    "clientid":"C_1492410235117",
    "username":"C_1492410235117",
    "reason":"normal"
}
  • message.publish
{
    "action":"message_publish",
    "from_client_id":"C_1492410235117",
    "from_username":"C_1492410235117",
    "topic":"world",
    "qos":0,
    "retain":true,
    "payload":"Hello world!",
    "ts":1492412774
}
  • message.delivered
{
    "action":"message_delivered",
    "clientid":"C_1492410235117",
    "username":"C_1492410235117",
    "from_client_id":"C_1492410235117",
    "from_username":"C_1492410235117",
    "topic":"world",
    "qos":0,
    "retain":true,
    "payload":"Hello world!",
    "ts":1492412826
}
  • message.acked
{
    "action":"message_acked",
    "clientid":"C_1492410235117",
    "username":"C_1492410235117",
    "from_client_id":"C_1492410235117",
    "from_username":"C_1492410235117",
    "topic":"world",
    "qos":1,
    "retain":true,
    "payload":"Hello world!",
    "ts":1492412914
}

License

Apache License Version 2.0

Author

Contributors

emqx-web-hook's People

Contributors

6293 avatar cmaster11 avatar emqplus avatar gilbertwong96 avatar hjianbo avatar huangdan avatar linjunjj avatar rory-z avatar s4kibs4mi avatar terry-xiaoyu avatar tigercl avatar turtledeng avatar wwhai avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

emqx-web-hook's Issues

Can the disconnection time include the disconnection time?

In concurrency, I appear offline message will be received before the online message. Of course, it was my device that reconnected immediately after disconnection, but I wanted the disconnection time information in the disconnection message.

Connection to emqx using websockets is delayed

When I try to connect to the emqx broker using websockets, there is 30sec delay. With tcp the connection is immediate. Is there a way to remove the delay?

05:45:24: Trying to connect to localhost:8083
05:45:24: client.connect call made with mqtt.Client.connect params --> after client.connect
_host=localhost _port=8083
_websocket_path:/mqtt _transport:websockets
_client_id: abc
05:45:54: CONNECTED WITH RESULT CODE: 0 --> in on_connect
05:45:54: SUBSCRIBED FOR $ABC/#

Error when subscribing to "$local" topic

Using emq_web_hook with emqttd 2.3.3.
When client subscribes to topic "$local/$share/group/#" it gets disconnected with error in emqttd log:

2018-01-17 15:04:23.697 [error] <0.4767.0> gen_server <0.4767.0> terminated with reason: no function clause matchin
767.0> terminated with reason: no function clause matchin
g mochijson2:'-json_encode_proplist/2-fun-0-'(local, [44,[34,<<"all">>,34],58,[34,<<"share">>,34],44,"0",58,[34,<<"
qos">>,34],123]) line 206
2018-01-17 15:04:23.697 [error] <0.4767.0> CRASH REPORT Process <0.4767.0> with 0 neighbours exited with reason: no
 function clause matching mochijson2:'-json_encode_proplist/2-fun-0-'(local, [44,[34,<<"all">>,34],58,[34,<<"share"
>>,34],44,"0",58,[34,<<"qos">>,34],123]) line 206 in gen_server2:terminate/3 line 1157
2018-01-17 15:04:23.697 [error] <0.4564.0> Supervisor 'esockd_connection_sup - <0.4564.0>' had child connection sta
rted with emqttd_client:start_link([{max_publish_rate,0},{client_idle_timeout,30000},{client_enable_stats,false},{max_clientid_len,...},...]) at <0.4767.0> exit with reason no function clause matching mochijson2:'-json_encode_proplist/2-fun-0-'(local, [44,[34,<<"all">>,34],58,[34,<<"share">>,34],44,"0",58,[34,<<"qos">>,34],123]) line 206 in context connection_crashed

If the topic is "$share/group/#" client subscribes normally.
$local prefix is needed for load-balancing in a cluster mode.
@emqplus

unsubcribe action name is wrong

unsubscribe action name:
{
"action":"client_unsubscribe",
"client_id":"C_1492410235117",
"username":"C_1492410235117",
"topic":"world"
}
not is:
{
"action":"client_subscribe",
"client_id":"C_1492410235117",
"username":"C_1492410235117",
"topic":"world"
}

Does emq-web-hook support https?

Hello there, I used an https URL for web.hook.api.url. It doesn't seem work. I'm wondering whether emq-web-hook supports https?

HTTP 422

http status code 422, is not treated as error in send_http_request

webhook generates empty post

emqx 4.0.6

I am trying to get webhooks working, but am having an issue. Perhaps I do not understand what exactly I have to do. The documentation is not sufficient for me.

I have been able to make emqx republish data on another mqtt topic using rules, but not post it to a webhook. I will explain the steps I have taken.

Using the EMQ dashboard, I make a rule with the SQL "SELECT payload FROM "t/#". I then add an action handler, and select "Data to Web Server" using a previously configured resource (POST to http://localhost/webhook.php, empty request header list). I leave the Payload Template field empty.

I have the following webhook.php:

<?php
file_put_contents("log/post.log", print_r($_POST, true)); 
print "ok";
?>

I then post to topic t/test a string value of test. I can then see in the apache log that emqx has posted to webhook.php. The file log/post.log has been made. Unfortunately, the contents of the file is the PHP representation of an empty array, i.e. the POST was empty.

I was hoping for things like clientid, topic and payload to have been posted.

Can you suggest what I am doing wrong?

Thanks!

Does not support HTTP Basic Authentication

setting

web.hook.api.url=http://emqx-webhook-user:emqxpassword@localhost/mqtt/webhook/

does not authenticate the user properly.

HTTP Basic Authentication should be supported

How to subscribe to a web hook?

Based on my knowledge about web hooks I need to subscribe to a web hook first by giving him a URL he should send the payload to. I don't see how to do this in your README.

Add node name in payload

Add node name in payload. So in a cluster mode end user can identify which client is connected to which node or which event is coming from which node.

Client ID is blank

hello, Sometimes the client Id obtained through webhook is null. why?

Confusion regarding emqx-rule-engine

emqx-web-hook and emqx-rule-engine have overlapping use cases. For example processing all messages published by web server can be done by both the plugin.

Can some from @emqx clarify the following:

  • Which one the plugin is recommended for it?
  • Performance wise which is better?
  • Does any one of it implement "fire and forget" mechanism for sending messages to web server instead on syncronously waiting for response?
  • Since it looks redundant which one of the plugin will be in active development, is there any plan to deprecate emqx-web-hook in favour of emqx-rule-engine?

Dropped fields on events

Hi,

I see some of the fields are dropped from the following events:

on_client_connected

https://github.com/vishr/emq-web-hook/blob/master/src/emq_web_hook.erl#L52

  • username
  • ip_address

on_client_disconnected

https://github.com/vishr/emq-web-hook/blob/master/src/emq_web_hook.erl#L65

  • username

These properties are essential for us to identify the clients in a multi tenant environment. Any reason for dropping them?

PS: Another change I saw is renaming event to action. Action sounds more like what you need to do for an event e.g. on_client_disconnect, IMHO changing it back to event is more appropriate. If this change is for consistency, please ignore this.

@emqplus @turtleDeng @s4kibs4mi

Client ID & Username not in message body

Hey so when I set up the web-hook plugin to post to a webserver running locally this is the body that I get.
{"action":"message_publish","from_client_id":"","from_username":"","topic":"data/rand","qos":2,"retain":true,"payload":"145,2018-11-05 18:08:06,34","ts":1541459286}

I expect this as it shows in the documentation but am not receiving the same information.

{
    "action":"message_publish",
    "from_client_id":"C_1492410235117",
    "from_username":"C_1492410235117",
    "topic":"world",
    "qos":0,
    "retain":true,
    "payload":"Hello world!",
    "ts":1492412774
}

Events data required using web hook urls

I want to use web hook url's for retrieving the data of different events like connect, subscribe, publish etc and for this i am trying to use web hook plugin provided by EMQ X broker and for this I have created an express app where the payload from the web hook url will be transferred.
But there's no guidance provided that how to use it and modify it in web hook config file.
I tried to modify it using dashboard but its giving me an error code of 500 when i provide a url.
Can someone please guide me that how to modify config file of web hook and how to use it to get the events data in the provided express app?

bug when load emqx-web-hook

EMQ v3.0.1 when I enable emqx-web-hook , and set web.hook.api.url=http://127.0.0.1:30041/emqHook ,there is some bugs shown.

For example :

  1. when I publish a message to a topic , It cannot be received;
  2. mqtt.fx connected to emq , when I close my mqtt.fx client the Dashboard also show there is a connected client;
    and also some other errors , anybody happens?

the emqHook is simple

@RequestMapping("emqHook")
public Object emqHook(@RequestBody Map<String,Object> params){
    logger.info(params.toString());
    return new HashMap<>();
}

Publish via dashboard REST-API fails

With the latest version (commit de344f1) of this plugin the from_client_id is now correctly set when receiving a publish message via the web hook (see #75). But after upgrading the web hook plugin to the latest version I wasn't able to publish via the dashboards HTTP API anymore. Publishes via web socket/regular clients work for me, but publishing over the dashboard HTTP API produces the following error:

Publish to 127.0.0.1:18083/api/v3/mqtt/publish with valid basic authentication (admin:public) sending JSON: "{"topic": "testtopic", "payload": "hello", "qos": 1, "retain": true, "client_id":"mqttjs_ab9069449e"} returns an Internal Error

The log of the broker shows:

2018-11-30 13:05:59.556 [error] POST /api/v3/mqtt/publish error: function_clause, stacktrace:
[{emqx_web_hook,format_from,
                [{message,<<0,5,123,224,159,84,118,22,244,66,0,0,8,121,0,0>>,
                          1,<<"mqttjs_ab9069449e">>,
                          #{retain => true},
                          #{},<<"testtopic">>,<<"hello">>,
                          {1543,579559,556628}}],
                [{file,"src/emqx_web_hook.erl"},{line,278}]},
 {emqx_web_hook,'-on_message_publish/2-fun-0-',2,
                [{file,"src/emqx_web_hook.erl"},{line,175}]},
 {emqx_hooks,run_,3,[{file,"src/emqx_hooks.erl"},{line,105}]},
 {emqx_broker,publish,1,[{file,"src/emqx_broker.erl"},{line,155}]},
 {lists,foreach,2,[{file,"lists.erl"},{line,1338}]},
 {emqx_mgmt_api_pubsub,publish,2,
                       [{file,"src/emqx_mgmt_api_pubsub.erl"},{line,68}]},
 {minirest_handler,dispatch,3,[{file,"src/minirest_handler.erl"},{line,55}]},
 {minirest,handle_request,2,[{file,"src/minirest.erl"},{line,66}]}]

Any idea why this doesn't work anymore?

Issue with WS connections

Hi, the plugin throws this error whenever this flow completes:

  1. A connection is esabilished using a WS connection (browser page).
  2. The tab in the browser is closed, so not with a graceful disconnection.

This issue prevents receiving disconnect hooks.

2020-04-04 05:45:24.901 [error] <<"myclientid:asdasd:12345">>@10.36.1.228:43906 [Hooks] Failed to execute {emqx_web_hook,on_client_disconnected,[{undefined}]}: {function_clause,                                                                                 [{emqx_web_hook,
printable,
[1001],
[{file,
"/emqx_rel/_build/emqx/lib/emqx_web_hook/src/emqx_web_hook.erl"},
{line,
154}]},
{emqx_web_hook,
on_client_disconnected,
4,
[{file,
"/emqx_rel/_build/emqx/lib/emqx_web_hook/src/emqx_web_hook.erl"},
{line,
149}]},
{emqx_hooks,
safe_execute,
2,
[{file,
"/emqx_rel/_build/emqx/lib/emqx/src/emqx_hooks.erl"},
{line,
164}]},
{emqx_hooks,
do_run,
2,
[{file,
"/emqx_rel/_build/emqx/lib/emqx/src/emqx_hooks.erl"},
{line,
130}]},
{emqx_channel,
ensure_disconnected,
2,
[{file,
"/emqx_rel/_build/emqx/lib/emqx/src/emqx_channel.erl"},
{line,
1336}]},                   
{emqx_channel,
handle_info,
2,
[{file,
"/emqx_rel/_build/emqx/lib/emqx/src/emqx_channel.erl"},
{line,
782}]},
{emqx_ws_connection,
with_channel,
3,
[{file,
"/emqx_rel/_build/emqx/lib/emqx/src/emqx_ws_connection.erl"},
{line,
489}]},
{cowboy_websocket,
websocket_close,
3,
[{file,
"/emqx_rel/_build/emqx/lib/cowboy/src/cowboy_websocket.erl"},
{line,
625}]}]}                                                           

How can I find the emqx_web_hook's log

I have some problem when using emqx_web_hook, and I am trying to fix it. So I want to search the plugin's log to solve the problem.

How can I find this plugin's log ?

Example of changing a parameter using emq-web-hook

Does emq-web-hook support the ability change change a parameter, as does https://github.com/emqtt/emq-lua-hook? For example, changing the topic when a client subscribes?

I understand how emq-web-hook works from a logging/notification standpoint, where data is sent to the URL, but it's not clear what the response options are, if any. A simple example would be much appreciated.

Thank you in advance.

How can i get the node name when client connect?

RT.

Is it node.name ?

on_client_connected(0, Client = #mqtt_client{client_id = ClientId, username = Username}, _Env) ->
--
  | Params = [{action, client_connected},
  | {client_id, ClientId},
  | {username, Username},
  | {nodename, node.name},
  | {conn_ack, 0}],
  | send_http_request(Params),
  | {ok, Client};

publish payload with protocolbuf got errors

FYI.

2018-01-22 10:17:09.765 [error] <0.11133.0> gen_server <0.11133.0> terminated with reason: no function clause matching mochijson2:json_encode_string_unicode({error,"\b",<<199,1,21,189,55,134,54,29,172,197,167,54>>}, {encoder,null,false}, """) line 300
2018-01-22 10:17:09.765 [error] <0.11133.0> CRASH REPORT Process <0.11133.0> with 0 neighbours exited with reason: no function clause matching mochijson2:json_encode_string_unicode({error,"\b",<<199,1,21,189,55,134,54,29,172,197,167,54>>}, {encoder,null,false}, """) line 300 in gen_server2:terminate/3 line 1157
2018-01-22 10:17:09.765 [error] <0.1427.0> Supervisor 'esockd_connection_sup - <0.1427.0>' had child connection started with emqttd_client:start_link([{max_publish_rate,0},{client_idle_timeout,30000},{client_enable_stats,false},{max_clientid_len,...},...]) at <0.11133.0> exit with reason no function clause matching mochijson2:json_encode_string_unicode({error,"\b",<<199,1,21,189,55,134,54,29,172,197,167,54>>}, {encoder,null,false}, """) line 300 in context connection_crashed

Thanks.

emulator Error in process <0.6292.0> on node '[email protected]' with exit value:

2018-10-24 16:35:00.396 [error] <0.6290.0>@emqttd_client:received:340 Client(182.50.122.136:51438): Parser failed for {{badmatch,0},[{emqttd_parser,parse_frame,3,[{file,"src/emqttd_parser.erl"},{line,170}]},{emqttd_client,received,2,[{file,"src/emqttd_client.erl"},{line,319}]},{gen_server2,handle_msg,2,[{file,"src/gen_server2.erl"},{line,1046}]},{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,247}]}]}
2018-10-24 16:35:00.396 [error] <0.6290.0>@emqttd_client:received:341 Client(182.50.122.136:51438): Error data: <<239,52,68,83,245,66,240,24,126,43,160,171,234,3,254,9,131,193,92,24,162,238,52,193,32,215,159,146,54,116,9,180,85,124,187,244,172,109,136,142,244,96,220,120,190,187,37,96,160,5,79,0,52,47,141,96,101,18,153,5,107,174,246,8,121,21,127,42,41,7,238,166,213,169,94,130,185,175,231,196,124,179,100,99,216,185,205,14,41,68,210,56,217,105,141,171,174,179,148,246,204,246,248,150,157,119,160,66,220,240,138,227,200,101,86,138,61,117,151,254,244,95,5,243,5,19,237,135,12,172,245,65,147,218,222,195,15,160,201,113,111,186,31,227,107,48,244,132,156,48,122,192,56,37,224,127,43,115,23,229,97,188,161,30,58,249,229,1>>
2018-10-24 16:35:14.357 [error] emulator Error in process <0.6292.0> on node '[email protected]' with exit value:

what reason means?

Does anyone know what reason means represent? What are the values? What does each value mean? I hope that there are good people to answer. Thank you.

Disable some webhook event

@s4kibs4mi ,
Is it possible to disable some webhook rule? For example, I want to receive webhook for below 2 actions only. Other actions I want to disable. I use webhook to persist the client messages in a database and I only need this 2 type of messages.

web.hook.rule.message.publish.1 = {"action": "on_message_publish"}
web.hook.rule.message.delivered.1 = {"action": "on_message_delivered"}

publish binary payload got error

When I send a binary message, the byte value bigger than 0xf7 will change to 0xef 0xbf 0xbd in web hook, for example, I send <<0x53 0x80 0x53>> but payload will get <<0x53 0xef 0xbf 0xbd 0x53>>. but at same time a client subscribe the topic will get correct payload.

I read the code of web hook, It is simple and do not process the parameter, so I think maybe the problem is at emqx.

test at 3.0.0 and 3.1-beta2

reproduce the error

set up an emqx server and config web hook, use mosquito send a binary file 0x53 0x80 0x53, use wireshark catch http package and payload change to 0x53 0xef 0xbf 0xbd 0x53. below is the screen capture.

https://www.alloyfang.com/assets/emqx_web_hook.jpg

Callbacks not begin invoked by emqx_web_hook plugin

What I want to achieve? Receive the messages from emqx using emqx_web_hook plugin for further processing

What I did so far?

What is the issue? The restapi server does not receive any of the published messages.

Any hints to debug this issue.
Please note that I am relatively new to the restapi space, so there could be basic misses in what I have done.

Configure Plugin to only send Publish messages.

As it says in the title I want to configure the plugin to only send requests when publish messages are sent. My config file looks as follows but I still receive the connected and disconnected requests

`web.hook.api.url = http://127.0.0.1:8080

web.hook.rule.client.connected.1 =
web.hook.rule.client.disconnected.1 =
web.hook.rule.client.subscribe.1 =
web.hook.rule.client.unsubscribe.1 =
web.hook.rule.session.created.1 =
web.hook.rule.session.subscribed.1 =
web.hook.rule.session.unsubscribed.1 =
web.hook.rule.session.terminated.1 =
web.hook.rule.message.publish.1 = {"action": "on_message_publish"}
web.hook.rule.message.deliver.1 =
web.hook.rule.message.acked.1 =
`

EMQ is not connecting to mqtt client after enabling emq_web_hook plugin

I am running my emqtt broker by docker image.

I am trying to catch all messages published on my broker and all acknowledged messages. For this purpose I am trying to use emq_web_hook plugin but when I enabled this plugin from dashboard, client disconnects and then unable to connect again to broker. I tried this with default configurations like

`web.hook.api.url = http://127.0.0.1

web.hook.rule.client.connected.1 = {"action": "on_client_connected"}
web.hook.rule.client.disconnected.1 = {"action": "on_client_disconnected"}
web.hook.rule.client.subscribe.1 = {"action": "on_client_subscribe"}
web.hook.rule.client.unsubscribe.1 = {"action": "on_client_unsubscribe"}
web.hook.rule.session.created.1 = {"action": "on_session_created"}
web.hook.rule.session.subscribed.1 = {"action": "on_session_subscribed"}
web.hook.rule.session.unsubscribed.1 = {"action": "on_session_unsubscribed"}
web.hook.rule.session.terminated.1 = {"action": "on_session_terminated"}
web.hook.rule.message.publish.1 = {"action": "on_message_publish"}
web.hook.rule.message.delivered.1 = {"action": "on_message_delivered"}
web.hook.rule.message.acked.1 = {"action": "on_message_acked"}`

I also changed the url and provide a url of my node server but it also dis not work.My endpoint was never called.

My dashboard is working but I am unable to publish.

What am I doing wrong or are there any steps I missed?

And How can I catch all those events?

Is this an issue or I misunderstood the documentation?

Thanks

Need explicit disable some webhook event when use docker environment configure

I have look this issues #60 , the answer is work when use config file. But when use docker to run, the best way to configure is use docker environment parameters, just like:

-e EMQX_WEB__HOOK__API__URL=http://127.0.0.1:8080/api/open/mqtt/webhook
-e EMQX_WEB__HOOK__RULE__CLIENT__CONNECTED__1={"action":"on_client_connected"}
-e EMQX_WEB__HOOK__RULE__CLIENT__DISCONNECTED__1={"action":"on_client_disconnected"}
................

If some hook events not specific by environment parameters, EMQX will take the items in the config file instead. So how can I disable some hook events but not need to change the default plugin config file?

Responding to webhook causes emqx to drop connections

I have an emqx broker set up and have the webhook plugin pointed at another server running node .js with express. I have about 630 devices connected to the emqx broker with a throughput of ~60 messages a second ( each device sending a message every 10 seconds). When I have have my node server send back a status with res.sendStatus(200) but if i send the I see that my connections drop from 630 to around 550. Would this be a timeout issue where my server is taking too long to respond? I'm unsure why the webhook plugin is making my emqx broker unstable

Cann't publish message with emqx-web-hook enabled

I enable emqx-web-hook plugin with the configuration below:

web.hook.api.url = http://10.150.123.214:8080/emqx/hook

web.hook.rule.client.connected.1     = {"action": "on_client_connected"}
web.hook.rule.client.disconnected.1  = {"action": "on_client_disconnected"}
web.hook.rule.client.subscribe.1     = {"action": "on_client_subscribe"}
web.hook.rule.client.unsubscribe.1   = {"action": "on_client_unsubscribe"}
web.hook.rule.session.created.1      = {"action": "on_session_created"}
web.hook.rule.session.subscribed.1   = {"action": "on_session_subscribed"}
web.hook.rule.session.unsubscribed.1 = {"action": "on_session_unsubscribed"}
web.hook.rule.session.terminated.1   = {"action": "on_session_terminated"}
web.hook.rule.message.publish.1      = {"action": "on_message_publish"}
web.hook.rule.message.delivered.1    = {"action": "on_message_delivered"}
web.hook.rule.message.acked.1        = {"action": "on_message_acked"}

And I can receive the message in my server:

{"action":"client_disconnected","client_id":"emqx_test_consumer1","username":"radioServer","reason":"closed"}
{"action":"session_terminated","client_id":"emqx_test","reason":"discarded"}
{"action":"session_created","client_id":"emqx_test","username":"radioServer"}
{"action":"client_connected","client_id":"emqx_test","username":"radioServer","conn_ack":0}
{"action":"client_subscribe","client_id":"emqx_test","username":"radioServer","topic":"testtopic/1","opts":{"nl":0,"qos":1,"rap":0,"rc":0,"rh":0}}
{"action":"session_subscribed","client_id":"emqx_test","topic":"testtopic/1","opts":{"first":true,"nl":0,"qos":1,"rap":0,"rc":0,"rh":0}}

But, the publishing message function cannot work with the code below:

client.publish(pubTopic, message); // eclipse paho client 

it triggers an Exception:

org.eclipse.paho.client.mqttv3.MqttException: timeout from server
	at org.eclipse.paho.client.mqttv3.internal.ExceptionHelper.createMqttException(ExceptionHelper.java:31)
	at org.eclipse.paho.client.mqttv3.internal.ClientState.checkForActivity(ClientState.java:694)
	at org.eclipse.paho.client.mqttv3.internal.ClientComms.checkForActivity(ClientComms.java:784)
	at org.eclipse.paho.client.mqttv3.internal.ClientComms.checkForActivity(ClientComms.java:770)
	at org.eclipse.paho.client.mqttv3.TimerPingSender$PingTask.run(TimerPingSender.java:77)
	at java.util.TimerThread.mainLoop(Timer.java:555)
	at java.util.TimerThread.run(Timer.java:505)

How can I solve this problem with emqx-web-hook enabled ?

Can I specify a particular event,because I'm just focusing on the client event

in your conf

web.hook.api.url = http://127.0.0.1

web.hook.rule.client.connected.1     = {"action": "on_client_connected"}
web.hook.rule.client.disconnected.1  = {"action": "on_client_disconnected"}
web.hook.rule.client.subscribe.1     = {"action": "on_client_subscribe"}
web.hook.rule.client.unsubscribe.1   = {"action": "on_client_unsubscribe"}
web.hook.rule.session.created.1      = {"action": "on_session_created"}
web.hook.rule.session.subscribed.1   = {"action": "on_session_subscribed"}
web.hook.rule.session.unsubscribed.1 = {"action": "on_session_unsubscribed"}
web.hook.rule.session.terminated.1   = {"action": "on_session_terminated"}
web.hook.rule.message.publish.1      = {"action": "on_message_publish"}
web.hook.rule.message.delivered.1    = {"action": "on_message_delivered"}
web.hook.rule.message.acked.1        = {"action": "on_message_acked"}

I want to ignore sesssion and message events, beacuase those message are too many, and i don't care.

web.hook.api.url = http://127.0.0.1

web.hook.rule.client.connected.1     = {"action": "on_client_connected"}
web.hook.rule.client.disconnected.1  = {"action": "on_client_disconnected"}
web.hook.rule.client.subscribe.1     = {"action": "on_client_subscribe"}
web.hook.rule.client.unsubscribe.1   = {"action": "on_client_unsubscribe"}
web.hook.rule.session.created.1      = {"action": "on_session_created"}
web.hook.rule.session.subscribed.1   = {"action": "on_session_subscribed"}
web.hook.rule.session.unsubscribed.1 = {"action": "on_session_unsubscribed"}
web.hook.rule.session.terminated.1   = {"action": "on_session_terminated"}
web.hook.rule.message.publish.1      = {"action": "on_message_publish"}
web.hook.rule.message.delivered.1    = {"action": "on_message_delivered"}
web.hook.rule.message.acked.1        = {"action": "on_message_acked"}

on = ["on_client_connected", "on_client_disconnected", "on_client_subscribe", "on_client_unsubscribe"]
off = ["other"]

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

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.