Publish Events to MQTT
AIStor supports publishing bucket notification events to MQTT server/broker endpoint.
Prerequisites
-
MQTT 3.1 or 3.1.1 Server/Broker
This procedure assumes an existing MQTT 3.1 or 3.1.1 server/broker to which the AIStor Server has connectivity. See the mqtt.org software listing for a list of MQTT-compatible server/brokers.
If the MQTT service requires authentication, you must provide an appropriate username and password during the configuration process to grant AIStor access to the service.
-
The AIStor
mc
command line toolThis procedure uses the
mc
command line tool for certain actions. See themc
Quickstart for installation instructions.
Add an MQTT endpoint to an AIStor Server
The following procedure adds a new MQTT service endpoint for supporting bucket notifications in an AIStor Server.
-
Add the MQTT endpoint to AIStor.
You can configure a new MQTT service endpoint using either environment variables or by setting runtime configuration settings.
If you define both environment variables and configuration settings for the deployment, the settings defined by environment variables are used. -
Restart the AIStor Server.
You must restart the AIStor Server to apply the configuration changes. Use the
mc admin service restart
command to restart the deployment.mc admin service restart ALIAS
Replace
ALIAS
with the alias of the deployment to restart.The
minio server
process prints a line on startup for each configured MQTT target similar to the following:SQS ARNs: arn:minio:sqs::primary:mqtt
You must specify the ARN resource when configuring bucket notifications with the associated MQTT deployment as a target.
-
Configure bucket notifications using the MQTT endpoint as a target.
Use the
mc event add
command to add a new bucket notification event with the configured MQTT service as a target:mc event add ALIAS/BUCKET arn:minio:sqs::primary:mqtt \ --event EVENTS
- Replace
ALIAS
with the alias of an AIStor Server. - Replace
BUCKET
with the name of the bucket in which to configure the event. - Replace
EVENTS
with a comma-separated list of events for which AIStor triggers notifications.
Use
mc event ls
to view all configured bucket events for a given notification target:mc event ls ALIAS/BUCKET arn:minio:sqs::primary:MQTT
- Replace
-
Validate the configured events.
Perform an action on the bucket for which you configured the new event and check the MQTT service for the notification data. The action required depends on which
events
were specified when configuring the bucket notification.For example, if the bucket notification configuration includes the
s3:ObjectCreated:Put
event, you can use themc cp
command to create a new object in the bucket and trigger a notification.mc cp ~/data/new-object.txt ALIAS/BUCKET
Update an MQTT endpoint in an AIStor Server
The following procedure updates an existing MQTT service endpoint for supporting bucket notifications in an AIStor Server.
-
List configured MQTT endpoints in the deployment.
Use the
mc admin config get
command to list the currently configured MQTT service endpoints in the deployment:mc admin config get ALIAS/ notify_mqtt
Replace
ALIAS
with the alias of the AIStor Server.The command output resembles the following:
notify_mqtt:primary broker="tcp://mqtt-primary.example.net:port" password="" queue_dir="" queue_limit="0" reconnect_interval="0s" keep_alive_interval="0s" qos="0" topic="" username="" notify_mqtt:secondary broker="tcp://mqtt-primary.example.net:port" password="" queue_dir="" queue_limit="0" reconnect_interval="0s" keep_alive_interval="0s" qos="0" topic="" username=""
The
notify_mqtt
key is the top-level configuration key for an MQTT Notification Settings. Thebroker
key specifies the MQTT server/broker endpoint for the givennotify_mqtt
key. Thenotify_mqtt:<IDENTIFIER>
suffix describes the unique identifier for that MQTT service endpoint.Note the identifier for the MQTT service endpoint you want to update for the next step.
-
Update the MQTT endpoint.
Use the
mc admin config set
command to set the new configuration for the MQTT service endpoint:mc admin config set ALIAS/ notify_mqtt:<IDENTIFIER> \ url="MQTT://user:password@hostname:port" \ exchange="<string>" \ exchange_type="<string>" \ routing_key="<string>" \ mandatory="<string>" \ durable="<string>" \ no_wait="<string>" \ internal="<string>" \ auto_deleted="<string>" \ delivery_mode="<string>" \ queue_dir="<string>" \ queue_limit="<string>" \ comment="<string>"
The following configuration settings are the minimum required for an MQTT server/broker endpoint:
-
Required if the MQTT server/broker enforces authentication/authorization
-
Required if the MQTT server/broker enforces authentication/authorization
All other configuration settings are optional. See MQTT Notification Settings for a complete list of MQTT configuration settings.
-
Restart the AIStor Server.
You must restart the AIStor Server to apply the configuration changes. Use the
mc admin service restart
command to restart the deployment.mc admin service restart ALIAS
Replace
ALIAS
with the alias of the deployment to restart.The
minio server
process prints a line on startup for each configured MQTT target similar to the following:SQS ARNs: arn:minio:sqs::primary:mqtt
-
Validate the changes.
Perform an action on a bucket which has an event configuration using the updated MQTT service endpoint and check the MQTT service for the notification data. The action required depends on which
events
were specified when configuring the bucket notification.For example, if the bucket notification configuration includes the
s3:ObjectCreated:Put
event, you can use themc cp
command to create a new object in the bucket and trigger a notification.mc cp ~/data/new-object.txt ALIAS/BUCKET