Events sidecar Plugin

How to implement VerneMQ plugins using a TCP sidecar

The VerneMQ Events sidecar plugin provides an easy and flexible way to relay events on VerneMQ using tcp hooks.

The idea of VerneMQ Events sidecar id very simple: you can register an TCP endpoint with a VerneMQ plugin hook and whenever the hook (such as auth_on_register) is called, the VerneMQ Events sidecar dispatches a TCP request to the registered endpoint. Note that unlike the webhook plugin, this is an async plugin which only relays the events and no control flow is done based on responses returned.

Configuring webhooks

To enable webhooks make sure to set:

plugins.vmq_events_sidecar = on

And then each webhook can be configured like this:

vmq_events_sidecar.hostname = 127.0.0.1
vmq_events_sidecar.port = 8890
vmq_events_sidecar.pool_size = 100
vmq_events_sidecar.hooks = on_register,on_subscribe

It is also possible to dynamically register webhooks at run-time:

$ vmq-admin events enable register hook=on_register

See which endpoints are registered:

$ vmq-admin events show

And finally deregistering an endpoint:

$ vmq-admin events disable hook=on_register

We recommend placing the endpoint implementation locally on each VerneMQ node such that each request can go over localhost without being subject to network issues.

Connection pool configuration

The plugin uses by default a connection pool containing maximally 100 connections. This can be changed by setting vmq_events_sidecar.pool_size to a different value.

Sidecar specs

For detailed information about the hooks and when they are called, see the sections Session Lifecycle, Subscribe Flow and Publish Flow.

The tcp requests use the following codec:

Supporting proto definitions for the events.

disconnect_reason

matched_acl

Following are the proto definitions for all supported events.

on_client_gone

Sidecar payload format:

on_client_offline

Payload format:

on_client_wakeup

Payload format:

on_deliver

Payload format:

on_delivery_complete

Payload format:

on_offline_message

on_subscribe

Payload format:

on_unsubscribe

Payload format:

on_publish

Payload format:

on_register

Payload format:

on_session_expired

Payload format:

on_message_drop

Example TCP events sidecar in Golang

Below is a very simple example of a tcp sidecar implemented in Go. It receives and logs OnSubscribe events. Follow this guide to generate Go code for on_subscribe event: https://developers.google.com/protocol-buffers/docs/reference/go-generated

Note that this example code uses compiled proto code for on_subscribe event in protos package.

It runs a tcp server at port 8890 (default port for events sidecar plugin) that receives events and writes them on to a log file at /tmp/sidecar.log.

Last updated