# WebHook
WebHook in NanoMQ allows the broker to send HTTP requests to specified endpoints when certain events occur. These events include client connections, message publications, session terminations, and more. This feature lets you integrate NanoMQ with other services and build complex event-driven architectures.
# Example Configuration
webhook = {
url = "http://127.0.0.1:80" # URL where the webhook will send HTTP requests
headers.content-type = "application/json" # HTTP header specifying request content type
body.encoding = "plain" # Encoding format of the payload field in HTTP body
pool_size = 32 # Connection process pool size
events = [
{
event = "on_message_publish" # Webhook will trigger when a message is published
topic = "a/b/c" # The specific topic that this event applies to
}
{
event = "on_client_connack" # Webhook will trigger when a client ACK is received
}
]
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# Configuration Items
url
: Specifies the URL to which the webhook will send HTTP requests when the events occur. This should be the endpoint of a service that can handle these requests appropriately.headers.content-type
: Defines the HTTP header for the content type of the request. For example, "application/json" means that the HTTP request's body will be formatted as a JSON object.body.encoding
: Specifies the 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
: Specifies the connection process pool size. This determines the number of concurrent connections that the webhook can maintain with the endpoint specified in theurl
. Default: 32events
: This is an array of event objects. Each object specifies an event that will trigger the webhook:event
: Specifies the name of the event that will trigger the webhook. The supported events include:on_client_connack
on_client_disconnected
on_message_publish
topic
(Optional): For theon_message_publish
event, you can specify a particular topic. The webhook will only trigger 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"
}
1
2
3
4
5
2
3
4
5
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