WebHook

    The internal implementation of WebHook is based on hooks, but it is closer to the top level. It obtains various events in EMQX Broker through the callback function mounted on the hook, and forwards them to the web server configured in emqx_web_hook.

    Taking the client.connected event as an example, the event delivery process is as follows:

    TIP

    WebHook processes events in one-way pattern. It only supports pushing events in EMQX Broker to Web services, and does not care about the return of Web services. With the help of Webhooks, many services such as device going online, online and offline recording, subscription and message storage, and message delivery confirmation can be completed.

    The webhook configuration file is located in: , the detailed description of configuration items can be found in Configuration Item.

    Trigger rules can be configured in etc/plugins/emqx_web_hook.conf. The configuration format is as follows:

    The following events are currently supported:

    Multiple trigger rules can be configured for the same event, and events with the same configuration should be incremented in sequence.

    • action: string, taking a fixed value
    • topic: a string, indicating a topic filter, the operation topic can only trigger the forwarding of the event if it matches the topic

    For example, we only forward messages matching the topics of a/b/c and foo/# to the web server, and the configuration should be:

    In this way, Webhook will only forward messages matching the topics of a/b/c and foo/#, such as foo/bar, etc., instead of forwarding a/b/d or .

    When the event is triggered, Webhook will group each event into an HTTP request and sent it to the web server configured by url according to the configuration. The request format is:

    For different events, the content of the request body is different. The following table lists the parameters of the body in each event:

    client.connect

    KeyTypeDescription
    actionstringevent name
    fixed at:”client_connect”
    clientidstringclient ClientId
    usernamestringclient Username, When not existed, the value is “undefined”
    ipaddressstringclient source IP address
    keepaliveintegerHeartbeat keepalive time applied by client
    proto_verintegerProtocol version number

    client.connack

    KeyTypeDescription
    actionstringevent name
    fixed at: “client_connack”
    clientidstringclient ClientId
    usernamestringclient Username, When not existed, the value is “undefined”
    ipaddressstringclient source IP address
    keepaliveintegerHeartbeat keepalive time applied by client
    proto_verintegerProtocol version number
    conn_ackstring“success” means success, other means failure

    client.connected

    client.disconnected

    KeyTypeDescription
    actionstringevent name
    fixed at: “client_disconnected”
    clientidstringclient ClientId
    usernamestringclient Username, When not existed, the value is “undefined”
    reasonstringerror reason
    KeyTypeDescription
    actionstringevent name
    fixed at: “client_subscribe”
    clientidstringClient ClientId
    usernamestringClient Username, When not existed, the value is “undefined”
    topicstringTopics to be subscribed
    optsjsonSubscription parameters

    opts includes

    client.unsubscribe

    KeyTypeDescription
    actionstringevent name
    fixed at:”client_unsubscribe”
    clientidstringclient ClientId
    usernamestringclient Username, When not existed, the value is “undefined”
    topicstringunsubscribed topic

    session.subscribed: same as client.subscribe,action is session_subscribed

    session.unsubscribed: same as client.unsubscribe,action is session_unsubscribe

    session.terminated: same as client.disconnected,action is

    message.publish

    KeyTypeDescription
    actionstringevent name
    fixed at: “message_publish”
    from_client_idstringPublisher’s ClientId
    from_usernamestringPublisher’s Username, When not existed, the value is “undefined”
    topicstringUnsubscribed topic
    qosenumQoS level, and the optional value is 0 1 2
    retainboolWhether it is a Retain message
    payloadstringMessage Payload
    tsintegerTimestamp (second)

    message.delivered

    message.acked

    KeyTypeDescription
    actionstringevent name
    fixed at: “message_acked”
    clientidstringReceiver’s ClientId
    from_client_idstringPublisher’s ClientId
    from_usernamestringPublisher’s Username, When not existed, the value is “undefined”
    topicstringUnsubscribed topic
    qosenumQoS level, and the optional value is 0 1
    retainboolWhether it is a Retain message
    payloadstringMessage Payload
    tsintegerTimestamp (second)