WebHook Configuration
The WebHook feature in EMQX Edge enables the broker to automatically send HTTP POST requests to external services in response to specific MQTT events. This mechanism makes it easy to integrate EMQX Edge with external systems. For more information on the WebHook feature, see WebHook Integration Tutorial.
This page provides you with a sample configuration of the WebHook settings in the nanomq.conf
configuration file.
Example Configuration
EMQX Edge supports defining multiple trigger rules through the configuration file. This section will demonstrate by defining two WebHook trigger rules as an example:
- Rule 1: When a message is sent to the "a/b/c" topic, trigger the WebHook.
- Rule 2: When a client initiates a connection request, trigger the WebHook.
The sample configuration is as follows:
webhook = {
url = "http://127.0.0.1:80" # URL where webhooks will send HTTP requests to
headers.content-type = "application/json" # HTTP header specifying request content type
body.encoding = "plain" # Encoding format of the payload field in
cancel_timeout = 5000 # HTTP max timeout duration (ms)
pool_size = 32 # Connection process pool size
events = [
{
event = "on_message_publish" # Event type
topic = "a/b/c" # The specific topic that this event applies to
}
{
event = "on_client_connack"
}
]
}
Configuration Items
url
: The URL where webhooks will send HTTP requests to when events occur. This should be the endpoint of a service that can handle these requests appropriately.headers.content-type
: Content type of the HTTP request included in the headers. For example, "application/json" means HTTP request's body will be formatted as a JSON object.body.encoding
: Encoding format of the payload field in the HTTP body. This field only appears in theon_message_publish
andon_message_delivered
events. The value can beplain
,base64
, orbase62
.pool_size
: The connection process pool size. This determines the number of concurrent connections that webhooks can maintain with the endpoint specified in theurl
. Default: 32cancel_timeout
: The HTTP connection waitscancel_timeout
for reomte reply. 5 seconds by default. Exceeding this setting will result in Request canceled.events
: An array of event objects. Each object specifies an event that can trigger a webhook:event
: Specify the type of the event that will trigger a webhook. The following events are supported:on_client_connack
on_client_disconnected
on_message_publish
topic
(Optional): Foron_message_publish
event, you can specify a particular topic. Webhooks are triggered only for messages published to this topic.
Upcoming Features
TLS
TLS-related configuration items will be supported in upcoming releases. Please stay tuned.
tls {
keyfile="/etc/certs/key.pem"
certfile="/etc/certs/cert.pem"
cacertfile="/etc/certs/cacert.pem"
}
Event
More events will be supported in upcoming releases. Please stay tuned.
on_client_connect
on_client_connected
on_client_subscribe
on_client_unsubscribe
on_session_subscribed
on_session_unsubscribed
on_session_terminated
on_message_delivered
on_message_acked