github.com/minio/minio@v0.0.0-20240328213742-3f72439b8a27/docs/bucket/notifications/README.md (about)

     1  # MinIO Bucket Notification Guide [![Slack](https://slack.min.io/slack?type=svg)](https://slack.min.io)
     2  
     3  Events occurring on objects in a bucket can be monitored using bucket event notifications.
     4  
     5  Various event types supported by MinIO server are
     6  
     7  | Supported Object Event Types     |                                            |                                        |
     8  | :----------------------          | ------------------------------------------ | -------------------------------------  |
     9  | `s3:ObjectCreated:Put`           | `s3:ObjectCreated:CompleteMultipartUpload` | `s3:ObjectAccessed:Head`               |
    10  | `s3:ObjectCreated:Post`          | `s3:ObjectRemoved:Delete`                  | `s3:ObjectRemoved:DeleteMarkerCreated` |
    11  | `s3:ObjectCreated:Copy`          | `s3:ObjectAccessed:Get`                    |                                        |
    12  | `s3:ObjectCreated:PutRetention`  | `s3:ObjectCreated:PutLegalHold`            |                                        |
    13  | `s3:ObjectAccessed:GetRetention` | `s3:ObjectAccessed:GetLegalHold`           |                                        |
    14  
    15  | Supported Replication Event Types                  |
    16  | :------------                                      |
    17  | `s3:Replication:OperationFailedReplication`        |
    18  | `s3:Replication:OperationCompletedReplication`     |
    19  | `s3:Replication:OperationNotTracked`               |
    20  | `s3:Replication:OperationMissedThreshold`          |
    21  | `s3:Replication:OperationReplicatedAfterThreshold` |
    22  
    23  | Supported ILM Transition Event Types |
    24  | :-----                               |
    25  | `s3:ObjectRestore:Post`              |
    26  | `s3:ObjectRestore:Completed`         |
    27  
    28  | Supported Global Event Types (Only supported through ListenNotification API) |
    29  | :-----                                                                       |
    30  | `s3:BucketCreated`                                                           |
    31  | `s3:BucketRemoved`                                                           |
    32  
    33  Use client tools like `mc` to set and listen for event notifications using the [`event` sub-command](https://min.io/docs/minio/linux/reference/minio-mc/mc-event-add.html). MinIO SDK's [`BucketNotification` APIs](https://min.io/docs/minio/linux/developers/go/API.html#setbucketnotification-ctx-context-context-bucketname-string-config-notification-configuration-error) can also be used. The notification message MinIO sends to publish an event is a JSON message with the following [structure](https://docs.aws.amazon.com/AmazonS3/latest/dev/notification-content-structure.html).
    34  
    35  Bucket events can be published to the following targets:
    36  
    37  | Supported Notification Targets    |                             |                                 |
    38  | :-------------------------------- | --------------------------- | ------------------------------- |
    39  | [`AMQP`](#AMQP)                   | [`Redis`](#Redis)           | [`MySQL`](#MySQL)               |
    40  | [`MQTT`](#MQTT)                   | [`NATS`](#NATS)             | [`Apache Kafka`](#apache-kafka) |
    41  | [`Elasticsearch`](#Elasticsearch) | [`PostgreSQL`](#PostgreSQL) | [`Webhooks`](#webhooks)         |
    42  | [`NSQ`](#NSQ)                     |                             |                                 |
    43  
    44  ## Prerequisites
    45  
    46  - Install and configure MinIO Server from [here](https://min.io/docs/minio/linux/index.html#procedure).
    47  - Install and configure MinIO Client from [here](https://min.io/docs/minio/linux/reference/minio-mc.html#quickstart).
    48  
    49  ```
    50  $ mc admin config get myminio | grep notify
    51  notify_webhook        publish bucket notifications to webhook endpoints
    52  notify_amqp           publish bucket notifications to AMQP endpoints
    53  notify_kafka          publish bucket notifications to Kafka endpoints
    54  notify_mqtt           publish bucket notifications to MQTT endpoints
    55  notify_nats           publish bucket notifications to NATS endpoints
    56  notify_nsq            publish bucket notifications to NSQ endpoints
    57  notify_mysql          publish bucket notifications to MySQL databases
    58  notify_postgres       publish bucket notifications to Postgres databases
    59  notify_elasticsearch  publish bucket notifications to Elasticsearch endpoints
    60  notify_redis          publish bucket notifications to Redis datastores
    61  ```
    62  
    63  > NOTE:
    64  >
    65  > - '\*' at the end of arg means its mandatory.
    66  > - '\*' at the end of the values, means its the default value for the arg.
    67  > - When configured using environment variables, the `:name` can be specified using this format `MINIO_NOTIFY_WEBHOOK_ENABLE_<name>`.
    68  
    69  ## Publish MinIO events via AMQP
    70  
    71  Install RabbitMQ from [here](https://www.rabbitmq.com/).
    72  
    73  ### Step 1: Add AMQP endpoint to MinIO
    74  
    75  The AMQP configuration is located under the sub-system `notify_amqp` top-level key. Create a configuration key-value pair here for your AMQP instance. The key is a name for your AMQP endpoint, and the value is a collection of key-value parameters described in the table below.
    76  
    77  ```
    78  KEY:
    79  notify_amqp[:name]  publish bucket notifications to AMQP endpoints
    80  
    81  ARGS:
    82  url*           (url)       AMQP server endpoint e.g. `amqp://myuser:mypassword@localhost:5672`
    83  exchange       (string)    name of the AMQP exchange
    84  exchange_type  (string)    AMQP exchange type
    85  routing_key    (string)    routing key for publishing
    86  mandatory      (on|off)    quietly ignore undelivered messages when set to 'off', default is 'on'
    87  durable        (on|off)    persist queue across broker restarts when set to 'on', default is 'off'
    88  no_wait        (on|off)    non-blocking message delivery when set to 'on', default is 'off'
    89  internal       (on|off)    set to 'on' for exchange to be not used directly by publishers, but only when bound to other exchanges
    90  auto_deleted   (on|off)    auto delete queue when set to 'on', when there are no consumers
    91  delivery_mode  (number)    set to '1' for non-persistent or '2' for persistent queue
    92  queue_dir      (path)      staging dir for undelivered messages e.g. '/home/events'
    93  queue_limit    (number)    maximum limit for undelivered messages, defaults to '100000'
    94  comment        (sentence)  optionally add a comment to this setting
    95  ```
    96  
    97  Or environment variables
    98  
    99  ```
   100  KEY:
   101  notify_amqp[:name]  publish bucket notifications to AMQP endpoints
   102  
   103  ARGS:
   104  MINIO_NOTIFY_AMQP_ENABLE*        (on|off)    enable notify_amqp target, default is 'off'
   105  MINIO_NOTIFY_AMQP_URL*           (url)       AMQP server endpoint e.g. `amqp://myuser:mypassword@localhost:5672`
   106  MINIO_NOTIFY_AMQP_EXCHANGE       (string)    name of the AMQP exchange
   107  MINIO_NOTIFY_AMQP_EXCHANGE_TYPE  (string)    AMQP exchange type
   108  MINIO_NOTIFY_AMQP_ROUTING_KEY    (string)    routing key for publishing
   109  MINIO_NOTIFY_AMQP_MANDATORY      (on|off)    quietly ignore undelivered messages when set to 'off', default is 'on'
   110  MINIO_NOTIFY_AMQP_DURABLE        (on|off)    persist queue across broker restarts when set to 'on', default is 'off'
   111  MINIO_NOTIFY_AMQP_NO_WAIT        (on|off)    non-blocking message delivery when set to 'on', default is 'off'
   112  MINIO_NOTIFY_AMQP_INTERNAL       (on|off)    set to 'on' for exchange to be not used directly by publishers, but only when bound to other exchanges
   113  MINIO_NOTIFY_AMQP_AUTO_DELETED   (on|off)    auto delete queue when set to 'on', when there are no consumers
   114  MINIO_NOTIFY_AMQP_DELIVERY_MODE  (number)    set to '1' for non-persistent or '2' for persistent queue
   115  MINIO_NOTIFY_AMQP_QUEUE_DIR      (path)      staging dir for undelivered messages e.g. '/home/events'
   116  MINIO_NOTIFY_AMQP_QUEUE_LIMIT    (number)    maximum limit for undelivered messages, defaults to '100000'
   117  MINIO_NOTIFY_AMQP_COMMENT        (sentence)  optionally add a comment to this setting
   118  ```
   119  
   120  MinIO supports persistent event store. The persistent store will backup events when the AMQP broker goes offline and replays it when the broker comes back online. The event store can be configured by setting the directory path in `queue_dir` field and the maximum limit of events in the queue_dir in `queue_limit` field. For eg, the `queue_dir` can be `/home/events` and `queue_limit` can be `1000`. By default, the `queue_limit` is set to 100000.
   121  
   122  To update the configuration, use `mc admin config get notify_amqp` command to get the current configuration for `notify_amqp`.
   123  
   124  ```sh
   125  $ mc admin config get myminio/ notify_amqp
   126  notify_amqp:1 delivery_mode="0" exchange_type="" no_wait="off" queue_dir="" queue_limit="0"  url="" auto_deleted="off" durable="off" exchange="" internal="off" mandatory="off" routing_key=""
   127  ```
   128  
   129  Use `mc admin config set` command to update the configuration for the deployment.Restart the MinIO server to put the changes into effect. The server will print a line like `SQS ARNs: arn:minio:sqs::1:amqp` at start-up if there were no errors.
   130  
   131  An example configuration for RabbitMQ is shown below:
   132  
   133  ```sh
   134  mc admin config set myminio/ notify_amqp:1 exchange="bucketevents" exchange_type="fanout" mandatory="off" no_wait="off"  url="amqp://myuser:mypassword@localhost:5672" auto_deleted="off" delivery_mode="0" durable="off" internal="off" routing_key="bucketlogs"
   135  ```
   136  
   137  MinIO supports all the exchanges available in [RabbitMQ](https://www.rabbitmq.com/). For this setup, we are using `fanout` exchange.
   138  
   139  MinIO also sends with the notifications two headers: `minio-bucket` and `minio-event`. An exchange using the type "headers" can use this information to route the notifications to proper queues.
   140  
   141  Note that, you can add as many AMQP server endpoint configurations as needed by providing an identifier (like "1" in the example above) for the AMQP instance and an object of per-server configuration parameters.
   142  
   143  ### Step 2: Enable RabbitMQ bucket notification using MinIO client
   144  
   145  We will enable bucket event notification to trigger whenever a JPEG image is uploaded or deleted `images` bucket on `myminio` server. Here ARN value is `arn:minio:sqs::1:amqp`. To understand more about ARN please follow [AWS ARN](http://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html) documentation.
   146  
   147  ```
   148  mc mb myminio/images
   149  mc event add myminio/images arn:minio:sqs::1:amqp --suffix .jpg
   150  mc event list myminio/images
   151  arn:minio:sqs::1:amqp s3:ObjectCreated:*,s3:ObjectRemoved:* Filter: suffix=”.jpg”
   152  ```
   153  
   154  ### Step 3: Test on RabbitMQ
   155  
   156  The python program below waits on the queue exchange `bucketevents` and prints event notifications on the console. We use [Pika Python Client](https://www.rabbitmq.com/tutorials/tutorial-three-python.html) library to do this.
   157  
   158  ```py
   159  #!/usr/bin/env python
   160  import pika
   161  
   162  connection = pika.BlockingConnection(pika.ConnectionParameters(
   163          host='localhost'))
   164  channel = connection.channel()
   165  
   166  channel.exchange_declare(exchange='bucketevents',
   167                           exchange_type='fanout')
   168  
   169  result = channel.queue_declare(exclusive=False)
   170  queue_name = result.method.queue
   171  
   172  channel.queue_bind(exchange='bucketevents',
   173                     queue=queue_name)
   174  
   175  print(' [*] Waiting for logs. To exit press CTRL+C')
   176  
   177  def callback(ch, method, properties, body):
   178      print(" [x] %r" % body)
   179  
   180  channel.basic_consume(callback,
   181                        queue=queue_name,
   182                        no_ack=False)
   183  
   184  channel.start_consuming()
   185  ```
   186  
   187  Execute this example python program to watch for RabbitMQ events on the console.
   188  
   189  ```py
   190  python rabbit.py
   191  ```
   192  
   193  Open another terminal and upload a JPEG image into `images` bucket.
   194  
   195  ```
   196  mc cp myphoto.jpg myminio/images
   197  ```
   198  
   199  You should receive the following event notification via RabbitMQ once the upload completes.
   200  
   201  ```py
   202  python rabbit.py
   203  '{"Records":[{"eventVersion":"2.0","eventSource":"aws:s3","awsRegion":"","eventTime":"2016–09–08T22:34:38.226Z","eventName":"s3:ObjectCreated:Put","userIdentity":{"principalId":"minio"},"requestParameters":{"sourceIPAddress":"10.1.10.150:44576"},"responseElements":{},"s3":{"s3SchemaVersion":"1.0","configurationId":"Config","bucket":{"name":"images","ownerIdentity":{"principalId":"minio"},"arn":"arn:aws:s3:::images"},"object":{"key":"myphoto.jpg","size":200436,"sequencer":"147279EAF9F40933"}}}],"level":"info","msg":"","time":"2016–09–08T15:34:38–07:00"}'
   204  ```
   205  
   206  ## Publish MinIO events MQTT
   207  
   208  Install an MQTT Broker from [here](https://mosquitto.org/).
   209  
   210  ### Step 1: Add MQTT endpoint to MinIO
   211  
   212  The MQTT configuration is located as `notify_mqtt` key. Create a configuration key-value pair here for your MQTT instance. The key is a name for your MQTT endpoint, and the value is a collection of key-value parameters described in the table below.
   213  
   214  ```
   215  KEY:
   216  notify_mqtt[:name]  publish bucket notifications to MQTT endpoints
   217  
   218  ARGS:
   219  broker*              (uri)       MQTT server endpoint e.g. `tcp://localhost:1883`
   220  topic*               (string)    name of the MQTT topic to publish
   221  username             (string)    MQTT username
   222  password             (string)    MQTT password
   223  qos                  (number)    set the quality of service priority, defaults to '0'
   224  keep_alive_interval  (duration)  keep-alive interval for MQTT connections in s,m,h,d
   225  reconnect_interval   (duration)  reconnect interval for MQTT connections in s,m,h,d
   226  queue_dir            (path)      staging dir for undelivered messages e.g. '/home/events'
   227  queue_limit          (number)    maximum limit for undelivered messages, defaults to '100000'
   228  comment              (sentence)  optionally add a comment to this setting
   229  ```
   230  
   231  or environment variables
   232  
   233  ```
   234  KEY:
   235  notify_mqtt[:name]  publish bucket notifications to MQTT endpoints
   236  
   237  ARGS:
   238  MINIO_NOTIFY_MQTT_ENABLE*              (on|off)    enable notify_mqtt target, default is 'off'
   239  MINIO_NOTIFY_MQTT_BROKER*              (uri)       MQTT server endpoint e.g. `tcp://localhost:1883`
   240  MINIO_NOTIFY_MQTT_TOPIC*               (string)    name of the MQTT topic to publish
   241  MINIO_NOTIFY_MQTT_USERNAME             (string)    MQTT username
   242  MINIO_NOTIFY_MQTT_PASSWORD             (string)    MQTT password
   243  MINIO_NOTIFY_MQTT_QOS                  (number)    set the quality of service priority, defaults to '0'
   244  MINIO_NOTIFY_MQTT_KEEP_ALIVE_INTERVAL  (duration)  keep-alive interval for MQTT connections in s,m,h,d
   245  MINIO_NOTIFY_MQTT_RECONNECT_INTERVAL   (duration)  reconnect interval for MQTT connections in s,m,h,d
   246  MINIO_NOTIFY_MQTT_QUEUE_DIR            (path)      staging dir for undelivered messages e.g. '/home/events'
   247  MINIO_NOTIFY_MQTT_QUEUE_LIMIT          (number)    maximum limit for undelivered messages, defaults to '100000'
   248  MINIO_NOTIFY_MQTT_COMMENT              (sentence)  optionally add a comment to this setting
   249  ```
   250  
   251  MinIO supports persistent event store. The persistent store will backup events when the MQTT broker goes offline and replays it when the broker comes back online. The event store can be configured by setting the directory path in `queue_dir` field and the maximum limit of events in the queue_dir in `queue_limit` field. For eg, the `queue_dir` can be `/home/events` and `queue_limit` can be `1000`. By default, the `queue_limit` is set to 100000.
   252  
   253  To update the configuration, use `mc admin config get` command to get the current configuration.
   254  
   255  ```sh
   256  $ mc admin config get myminio/ notify_mqtt
   257  notify_mqtt:1 broker="" password="" queue_dir="" queue_limit="0" reconnect_interval="0s"  keep_alive_interval="0s" qos="0" topic="" username=""
   258  ```
   259  
   260  Use `mc admin config set` command to update the configuration for the deployment. Restart the MinIO server to put the changes into effect. The server will print a line like `SQS ARNs: arn:minio:sqs::1:mqtt` at start-up if there were no errors.
   261  
   262  ```sh
   263  mc admin config set myminio notify_mqtt:1 broker="tcp://localhost:1883" password="" queue_dir="" queue_limit="0" reconnect_interval="0s"  keep_alive_interval="0s" qos="1" topic="minio" username=""
   264  ```
   265  
   266  MinIO supports any MQTT server that supports MQTT 3.1 or 3.1.1 and can connect to them over TCP, TLS, or a Websocket connection using `tcp://`, `tls://`, or `ws://` respectively as the scheme for the broker url. See the [Go Client](http://www.eclipse.org/paho/clients/golang/) documentation for more information.
   267  
   268  Note that, you can add as many MQTT server endpoint configurations as needed by providing an identifier (like "1" in the example above) for the MQTT instance and an object of per-server configuration parameters.
   269  
   270  ### Step 2: Enable MQTT bucket notification using MinIO client
   271  
   272  We will enable bucket event notification to trigger whenever a JPEG image is uploaded or deleted `images` bucket on `myminio` server. Here ARN value is `arn:minio:sqs::1:mqtt`.
   273  
   274  ```
   275  mc mb myminio/images
   276  mc event add  myminio/images arn:minio:sqs::1:mqtt --suffix .jpg
   277  mc event list myminio/images
   278  arn:minio:sqs::1:amqp s3:ObjectCreated:*,s3:ObjectRemoved:* Filter: suffix=”.jpg”
   279  ```
   280  
   281  ### Step 3: Test on MQTT
   282  
   283  The python program below waits on mqtt topic `/minio` and prints event notifications on the console. We use [paho-mqtt](https://pypi.python.org/pypi/paho-mqtt/) library to do this.
   284  
   285  ```py
   286  #!/usr/bin/env python3
   287  from __future__ import print_function
   288  import paho.mqtt.client as mqtt
   289  
   290  # This is the Subscriber
   291  
   292  def on_connect(client, userdata, flags, rc):
   293    print("Connected with result code "+str(rc))
   294    # qos level is set to 1
   295    client.subscribe("minio", 1)
   296  
   297  def on_message(client, userdata, msg):
   298      print(msg.payload)
   299  
   300  # client_id is a randomly generated unique ID for the mqtt broker to identify the connection.
   301  client = mqtt.Client(client_id="myclientid",clean_session=False)
   302  
   303  client.on_connect = on_connect
   304  client.on_message = on_message
   305  
   306  client.connect("localhost",1883,60)
   307  client.loop_forever()
   308  ```
   309  
   310  Execute this example python program to watch for MQTT events on the console.
   311  
   312  ```py
   313  python mqtt.py
   314  ```
   315  
   316  Open another terminal and upload a JPEG image into `images` bucket.
   317  
   318  ```
   319  mc cp myphoto.jpg myminio/images
   320  ```
   321  
   322  You should receive the following event notification via MQTT once the upload completes.
   323  
   324  ```py
   325  python mqtt.py
   326  {“Records”:[{“eventVersion”:”2.0",”eventSource”:”aws:s3",”awsRegion”:”",”eventTime”:”2016–09–08T22:34:38.226Z”,”eventName”:”s3:ObjectCreated:Put”,”userIdentity”:{“principalId”:”minio”},”requestParameters”:{“sourceIPAddress”:”10.1.10.150:44576"},”responseElements”:{},”s3":{“s3SchemaVersion”:”1.0",”configurationId”:”Config”,”bucket”:{“name”:”images”,”ownerIdentity”:{“principalId”:”minio”},”arn”:”arn:aws:s3:::images”},”object”:{“key”:”myphoto.jpg”,”size”:200436,”sequencer”:”147279EAF9F40933"}}}],”level”:”info”,”msg”:””,”time”:”2016–09–08T15:34:38–07:00"}
   327  ```
   328  
   329  ## Publish MinIO events via Elasticsearch
   330  
   331  Install [Elasticsearch](https://www.elastic.co/downloads/elasticsearch) server.
   332  
   333  This notification target supports two formats: _namespace_ and _access_.
   334  
   335  When the _namespace_ format is used, MinIO synchronizes objects in the bucket with documents in the index. For each event in the MinIO, the server creates a document with the bucket and object name from the event as the document ID. Other details of the event are stored in the body of the document. Thus if an existing object is over-written in MinIO, the corresponding document in the Elasticsearch index is updated. If an object is deleted, the corresponding document is deleted from the index.
   336  
   337  When the _access_ format is used, MinIO appends events as documents in an Elasticsearch index. For each event, a document with the event details, with the timestamp of document set to the event's timestamp is appended to an index. The ID of the documented is randomly generated by Elasticsearch. No documents are deleted or modified in this format.
   338  
   339  The steps below show how to use this notification target in `namespace` format. The other format is very similar and is omitted for brevity.
   340  
   341  ### Step 1: Ensure Elasticsearch minimum requirements are met
   342  
   343  MinIO requires a 5.x series version of Elasticsearch. This is the latest major release series. Elasticsearch provides version upgrade migration guidelines [here](https://www.elastic.co/guide/en/elasticsearch/reference/current/setup-upgrade.html).
   344  
   345  ### Step 2: Add Elasticsearch endpoint to MinIO
   346  
   347  The Elasticsearch configuration is located in the `notify_elasticsearch` key. Create a configuration key-value pair here for your Elasticsearch instance. The key is a name for your Elasticsearch endpoint, and the value is a collection of key-value parameters described in the table below.
   348  
   349  ```
   350  KEY:
   351  notify_elasticsearch[:name]  publish bucket notifications to Elasticsearch endpoints
   352  
   353  ARGS:
   354  url*         (url)                Elasticsearch server's address, with optional authentication info
   355  index*       (string)             Elasticsearch index to store/update events, index is auto-created
   356  format*      (namespace*|access)  'namespace' reflects current bucket/object list and 'access' reflects a journal of object operations, defaults to 'namespace'
   357  queue_dir    (path)               staging dir for undelivered messages e.g. '/home/events'
   358  queue_limit  (number)             maximum limit for undelivered messages, defaults to '100000'
   359  username     (string)             username for Elasticsearch basic-auth
   360  password     (string)             password for Elasticsearch basic-auth
   361  comment      (sentence)           optionally add a comment to this setting
   362  ```
   363  
   364  or environment variables
   365  
   366  ```
   367  KEY:
   368  notify_elasticsearch[:name]  publish bucket notifications to Elasticsearch endpoints
   369  
   370  ARGS:
   371  MINIO_NOTIFY_ELASTICSEARCH_ENABLE*      (on|off)             enable notify_elasticsearch target, default is 'off'
   372  MINIO_NOTIFY_ELASTICSEARCH_URL*         (url)                Elasticsearch server's address, with optional authentication info
   373  MINIO_NOTIFY_ELASTICSEARCH_INDEX*       (string)             Elasticsearch index to store/update events, index is auto-created
   374  MINIO_NOTIFY_ELASTICSEARCH_FORMAT*      (namespace*|access)  'namespace' reflects current bucket/object list and 'access' reflects a journal of object operations, defaults to 'namespace'
   375  MINIO_NOTIFY_ELASTICSEARCH_QUEUE_DIR    (path)               staging dir for undelivered messages e.g. '/home/events'
   376  MINIO_NOTIFY_ELASTICSEARCH_QUEUE_LIMIT  (number)             maximum limit for undelivered messages, defaults to '100000'
   377  MINIO_NOTIFY_ELASTICSEARCH_USERNAME     (string)             username for Elasticsearch basic-auth
   378  MINIO_NOTIFY_ELASTICSEARCH_PASSWORD     (string)             password for Elasticsearch basic-auth
   379  MINIO_NOTIFY_ELASTICSEARCH_COMMENT      (sentence)           optionally add a comment to this setting
   380  ```
   381  
   382  For example: `http://localhost:9200` or with authentication info `http://elastic:MagicWord@127.0.0.1:9200`.
   383  
   384  MinIO supports persistent event store. The persistent store will backup events when the Elasticsearch broker goes offline and replays it when the broker comes back online. The event store can be configured by setting the directory path in `queue_dir` field and the maximum limit of events in the queue_dir in `queue_limit` field. For eg, the `queue_dir` can be `/home/events` and `queue_limit` can be `1000`. By default, the `queue_limit` is set to 100000.
   385  
   386  If Elasticsearch has authentication enabled, the credentials can be supplied to MinIO via the `url` parameter formatted as `PROTO://USERNAME:PASSWORD@ELASTICSEARCH_HOST:PORT`.
   387  
   388  To update the configuration, use `mc admin config get` command to get the current configuration.
   389  
   390  ```sh
   391  $ mc admin config get myminio/ notify_elasticsearch
   392  notify_elasticsearch:1 queue_limit="0"  url="" format="namespace" index="" queue_dir=""
   393  ```
   394  
   395  Use `mc admin config set` command to update the configuration for the deployment. Restart the MinIO server to put the changes into effect. The server will print a line like `SQS ARNs: arn:minio:sqs::1:elasticsearch` at start-up if there were no errors.
   396  
   397  ```sh
   398  mc admin config set myminio notify_elasticsearch:1 queue_limit="0"  url="http://127.0.0.1:9200" format="namespace" index="minio_events" queue_dir="" username="" password=""
   399  ```
   400  
   401  Note that, you can add as many Elasticsearch server endpoint configurations as needed by providing an identifier (like "1" in the example above) for the Elasticsearch instance and an object of per-server configuration parameters.
   402  
   403  ### Step 3: Enable Elastichsearch bucket notification using MinIO client
   404  
   405  We will now enable bucket event notifications on a bucket named `images`. Whenever a JPEG image is created/overwritten, a new document is added or an existing document is updated in the Elasticsearch index configured above. When an existing object is deleted, the corresponding document is deleted from the index. Thus, the rows in the Elasticsearch index, reflect the `.jpg` objects in the `images` bucket.
   406  
   407  To configure this bucket notification, we need the ARN printed by MinIO in the previous step. Additional information about ARN is available [here](http://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html).
   408  
   409  With the `mc` tool, the configuration is very simple to add. Let us say that the MinIO server is aliased as `myminio` in our mc configuration. Execute the following:
   410  
   411  ```
   412  mc mb myminio/images
   413  mc event add  myminio/images arn:minio:sqs::1:elasticsearch --suffix .jpg
   414  mc event list myminio/images
   415  arn:minio:sqs::1:elasticsearch s3:ObjectCreated:*,s3:ObjectRemoved:* Filter: suffix=”.jpg”
   416  ```
   417  
   418  ### Step 4: Test on Elasticsearch
   419  
   420  Upload a JPEG image into `images` bucket.
   421  
   422  ```
   423  mc cp myphoto.jpg myminio/images
   424  ```
   425  
   426  Use curl to view contents of `minio_events` index.
   427  
   428  ```
   429  $ curl  "http://localhost:9200/minio_events/_search?pretty=true"
   430  {
   431    "took" : 40,
   432    "timed_out" : false,
   433    "_shards" : {
   434      "total" : 5,
   435      "successful" : 5,
   436      "failed" : 0
   437    },
   438    "hits" : {
   439      "total" : 1,
   440      "max_score" : 1.0,
   441      "hits" : [
   442        {
   443          "_index" : "minio_events",
   444          "_type" : "event",
   445          "_id" : "images/myphoto.jpg",
   446          "_score" : 1.0,
   447          "_source" : {
   448            "Records" : [
   449              {
   450                "eventVersion" : "2.0",
   451                "eventSource" : "minio:s3",
   452                "awsRegion" : "",
   453                "eventTime" : "2017-03-30T08:00:41Z",
   454                "eventName" : "s3:ObjectCreated:Put",
   455                "userIdentity" : {
   456                  "principalId" : "minio"
   457                },
   458                "requestParameters" : {
   459                  "sourceIPAddress" : "127.0.0.1:38062"
   460                },
   461                "responseElements" : {
   462                  "x-amz-request-id" : "14B09A09703FC47B",
   463                  "x-minio-origin-endpoint" : "http://192.168.86.115:9000"
   464                },
   465                "s3" : {
   466                  "s3SchemaVersion" : "1.0",
   467                  "configurationId" : "Config",
   468                  "bucket" : {
   469                    "name" : "images",
   470                    "ownerIdentity" : {
   471                      "principalId" : "minio"
   472                    },
   473                    "arn" : "arn:aws:s3:::images"
   474                  },
   475                  "object" : {
   476                    "key" : "myphoto.jpg",
   477                    "size" : 6474,
   478                    "eTag" : "a3410f4f8788b510d6f19c5067e60a90",
   479                    "sequencer" : "14B09A09703FC47B"
   480                  }
   481                },
   482                "source" : {
   483                  "host" : "127.0.0.1",
   484                  "port" : "38062",
   485                  "userAgent" : "MinIO (linux; amd64) minio-go/2.0.3 mc/2017-02-15T17:57:25Z"
   486                }
   487              }
   488            ]
   489          }
   490        }
   491      ]
   492    }
   493  }
   494  ```
   495  
   496  This output shows that a document has been created for the event in Elasticsearch.
   497  
   498  Here we see that the document ID is the bucket and object name. In case `access` format was used, the document ID would be automatically generated by Elasticsearch.
   499  
   500  ## Publish MinIO events via Redis
   501  
   502  Install [Redis](http://redis.io/download) server. For illustrative purposes, we have set the database password as "yoursecret".
   503  
   504  This notification target supports two formats: _namespace_ and _access_.
   505  
   506  When the _namespace_ format is used, MinIO synchronizes objects in the bucket with entries in a hash. For each entry, the key is formatted as "bucketName/objectName" for an object that exists in the bucket, and the value is the JSON-encoded event data about the operation that created/replaced the object in MinIO. When objects are updated or deleted, the corresponding entry in the hash is also updated or deleted.
   507  
   508  When the _access_ format is used, MinIO appends events to a list using [RPUSH](https://redis.io/commands/rpush). Each item in the list is a JSON encoded list with two items, where the first item is a timestamp string, and the second item is a JSON object containing event data about the operation that happened in the bucket. No entries appended to the list are updated or deleted by MinIO in this format.
   509  
   510  The steps below show how to use this notification target in `namespace` and `access` format.
   511  
   512  ### Step 1: Add Redis endpoint to MinIO
   513  
   514  The MinIO server configuration file is stored on the backend in json format.The Redis configuration is located in the `redis` key under the `notify` top-level key. Create a configuration key-value pair here for your Redis instance. The key is a name for your Redis endpoint, and the value is a collection of key-value parameters described in the table below.
   515  
   516  ```
   517  KEY:
   518  notify_redis[:name]  publish bucket notifications to Redis datastores
   519  
   520  ARGS:
   521  address*     (address)            Redis server's address. For example: `localhost:6379`
   522  key*         (string)             Redis key to store/update events, key is auto-created
   523  format*      (namespace*|access)  'namespace' reflects current bucket/object list and 'access' reflects a journal of object operations, defaults to 'namespace'
   524  password     (string)             Redis server password
   525  queue_dir    (path)               staging dir for undelivered messages e.g. '/home/events'
   526  queue_limit  (number)             maximum limit for undelivered messages, defaults to '100000'
   527  comment      (sentence)           optionally add a comment to this setting
   528  ```
   529  
   530  or environment variables
   531  
   532  ```
   533  KEY:
   534  notify_redis[:name]  publish bucket notifications to Redis datastores
   535  
   536  ARGS:
   537  MINIO_NOTIFY_REDIS_ENABLE*      (on|off)             enable notify_redis target, default is 'off'
   538  MINIO_NOTIFY_REDIS_KEY*         (string)             Redis key to store/update events, key is auto-created
   539  MINIO_NOTIFY_REDIS_FORMAT*      (namespace*|access)  'namespace' reflects current bucket/object list and 'access' reflects a journal of object operations, defaults to 'namespace'
   540  MINIO_NOTIFY_REDIS_PASSWORD     (string)             Redis server password
   541  MINIO_NOTIFY_REDIS_QUEUE_DIR    (path)               staging dir for undelivered messages e.g. '/home/events'
   542  MINIO_NOTIFY_REDIS_QUEUE_LIMIT  (number)             maximum limit for undelivered messages, defaults to '100000'
   543  MINIO_NOTIFY_REDIS_COMMENT      (sentence)           optionally add a comment to this setting
   544  ```
   545  
   546  MinIO supports persistent event store. The persistent store will backup events when the Redis broker goes offline and replays it when the broker comes back online. The event store can be configured by setting the directory path in `queue_dir` field and the maximum limit of events in the queue_dir in `queue_limit` field. For eg, the `queue_dir` can be `/home/events` and `queue_limit` can be `1000`. By default, the `queue_limit` is set to 100000.
   547  
   548  To update the configuration, use `mc admin config get` command to get the current configuration.
   549  
   550  ```sh
   551  $ mc admin config get myminio/ notify_redis
   552  notify_redis:1 address="" format="namespace" key="" password="" queue_dir="" queue_limit="0"
   553  ```
   554  
   555  Use `mc admin config set` command to update the configuration for the deployment.Restart the MinIO server to put the changes into effect. The server will print a line like `SQS ARNs: arn:minio:sqs::1:redis` at start-up if there were no errors.
   556  
   557  ```sh
   558  mc admin config set myminio/ notify_redis:1 address="127.0.0.1:6379" format="namespace" key="bucketevents" password="yoursecret" queue_dir="" queue_limit="0"
   559  ```
   560  
   561  Note that, you can add as many Redis server endpoint configurations as needed by providing an identifier (like "1" in the example above) for the Redis instance and an object of per-server configuration parameters.
   562  
   563  ### Step 2: Enable Redis bucket notification using MinIO client
   564  
   565  We will now enable bucket event notifications on a bucket named `images`. Whenever a JPEG image is created/overwritten, a new key is added or an existing key is updated in the Redis hash configured above. When an existing object is deleted, the corresponding key is deleted from the Redis hash. Thus, the rows in the Redis hash, reflect the `.jpg` objects in the `images` bucket.
   566  
   567  To configure this bucket notification, we need the ARN printed by MinIO in the previous step. Additional information about ARN is available [here](http://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html).
   568  
   569  With the `mc` tool, the configuration is very simple to add. Let us say that the MinIO server is aliased as `myminio` in our mc configuration. Execute the following:
   570  
   571  ```
   572  mc mb myminio/images
   573  mc event add myminio/images arn:minio:sqs::1:redis --suffix .jpg
   574  mc event list myminio/images
   575  arn:minio:sqs::1:redis s3:ObjectCreated:*,s3:ObjectRemoved:* Filter: suffix=”.jpg”
   576  ```
   577  
   578  ### Step 3: Test on Redis
   579  
   580  Start the `redis-cli` Redis client program to inspect the contents in Redis. Run the `monitor` Redis command. This prints each operation performed on Redis as it occurs.
   581  
   582  ```
   583  redis-cli -a yoursecret
   584  127.0.0.1:6379> monitor
   585  OK
   586  ```
   587  
   588  Open another terminal and upload a JPEG image into `images` bucket.
   589  
   590  ```
   591  mc cp myphoto.jpg myminio/images
   592  ```
   593  
   594  In the previous terminal, you will now see the operation that MinIO performs on Redis:
   595  
   596  ```
   597  127.0.0.1:6379> monitor
   598  OK
   599  1490686879.650649 [0 172.17.0.1:44710] "PING"
   600  1490686879.651061 [0 172.17.0.1:44710] "HSET" "minio_events" "images/myphoto.jpg" "{\"Records\":[{\"eventVersion\":\"2.0\",\"eventSource\":\"minio:s3\",\"awsRegion\":\"\",\"eventTime\":\"2017-03-28T07:41:19Z\",\"eventName\":\"s3:ObjectCreated:Put\",\"userIdentity\":{\"principalId\":\"minio\"},\"requestParameters\":{\"sourceIPAddress\":\"127.0.0.1:52234\"},\"responseElements\":{\"x-amz-request-id\":\"14AFFBD1ACE5F632\",\"x-minio-origin-endpoint\":\"http://192.168.86.115:9000\"},\"s3\":{\"s3SchemaVersion\":\"1.0\",\"configurationId\":\"Config\",\"bucket\":{\"name\":\"images\",\"ownerIdentity\":{\"principalId\":\"minio\"},\"arn\":\"arn:aws:s3:::images\"},\"object\":{\"key\":\"myphoto.jpg\",\"size\":2586,\"eTag\":\"5d284463f9da279f060f0ea4d11af098\",\"sequencer\":\"14AFFBD1ACE5F632\"}},\"source\":{\"host\":\"127.0.0.1\",\"port\":\"52234\",\"userAgent\":\"MinIO (linux; amd64) minio-go/2.0.3 mc/2017-02-15T17:57:25Z\"}}]}"
   601  ```
   602  
   603  Here we see that MinIO performed `HSET` on `minio_events` key.
   604  
   605  In case, `access` format was used, then `minio_events` would be a list, and the MinIO server would have performed an `RPUSH` to append to the list. A consumer of this list would ideally use `BLPOP` to remove list items from the left-end of the list.
   606  
   607  ## Publish MinIO events via NATS
   608  
   609  Install NATS from [here](http://nats.io/).
   610  
   611  ### Step 1: Add NATS endpoint to MinIO
   612  
   613  MinIO supports persistent event store. The persistent store will backup events when the NATS broker goes offline and replays it when the broker comes back online. The event store can be configured by setting the directory path in `queue_dir` field and the maximum limit of events in the queue_dir in `queue_limit` field. For eg, the `queue_dir` can be `/home/events` and `queue_limit` can be `1000`. By default, the `queue_limit` is set to 100000.
   614  
   615  ```
   616  KEY:
   617  notify_nats[:name]  publish bucket notifications to NATS endpoints
   618  
   619  ARGS:
   620  address*                          (address)   NATS server address e.g. '0.0.0.0:4222'
   621  subject*                          (string)    NATS subscription subject
   622  username                          (string)    NATS username
   623  password                          (string)    NATS password
   624  token                             (string)    NATS token
   625  tls                               (on|off)    set to 'on' to enable TLS
   626  tls_skip_verify                   (on|off)    trust server TLS without verification, defaults to "on" (verify)
   627  ping_interval                     (duration)  client ping commands interval in s,m,h,d. Disabled by default
   628  streaming                         (on|off)    set to 'on', to use streaming NATS server
   629  streaming_async                   (on|off)    set to 'on', to enable asynchronous publish
   630  streaming_max_pub_acks_in_flight  (number)    number of messages to publish without waiting for ACKs
   631  streaming_cluster_id              (string)    unique ID for NATS streaming cluster
   632  cert_authority                    (string)    path to certificate chain of the target NATS server
   633  client_cert                       (string)    client cert for NATS mTLS auth
   634  client_key                        (string)    client cert key for NATS mTLS auth
   635  queue_dir                         (path)      staging dir for undelivered messages e.g. '/home/events'
   636  queue_limit                       (number)    maximum limit for undelivered messages, defaults to '100000'
   637  comment                           (sentence)  optionally add a comment to this setting
   638  ```
   639  
   640  or environment variables
   641  
   642  ```
   643  KEY:
   644  notify_nats[:name]  publish bucket notifications to NATS endpoints
   645  
   646  ARGS:
   647  MINIO_NOTIFY_NATS_ENABLE*                           (on|off)    enable notify_nats target, default is 'off'
   648  MINIO_NOTIFY_NATS_ADDRESS*                          (address)   NATS server address e.g. '0.0.0.0:4222'
   649  MINIO_NOTIFY_NATS_SUBJECT*                          (string)    NATS subscription subject
   650  MINIO_NOTIFY_NATS_USERNAME                          (string)    NATS username
   651  MINIO_NOTIFY_NATS_PASSWORD                          (string)    NATS password
   652  MINIO_NOTIFY_NATS_TOKEN                             (string)    NATS token
   653  MINIO_NOTIFY_NATS_TLS                               (on|off)    set to 'on' to enable TLS
   654  MINIO_NOTIFY_NATS_TLS_SKIP_VERIFY                   (on|off)    trust server TLS without verification, defaults to "on" (verify)
   655  MINIO_NOTIFY_NATS_PING_INTERVAL                     (duration)  client ping commands interval in s,m,h,d. Disabled by default
   656  MINIO_NOTIFY_NATS_STREAMING                         (on|off)    set to 'on', to use streaming NATS server
   657  MINIO_NOTIFY_NATS_STREAMING_ASYNC                   (on|off)    set to 'on', to enable asynchronous publish
   658  MINIO_NOTIFY_NATS_STREAMING_MAX_PUB_ACKS_IN_FLIGHT  (number)    number of messages to publish without waiting for ACKs
   659  MINIO_NOTIFY_NATS_STREAMING_CLUSTER_ID              (string)    unique ID for NATS streaming cluster
   660  MINIO_NOTIFY_NATS_CERT_AUTHORITY                    (string)    path to certificate chain of the target NATS server
   661  MINIO_NOTIFY_NATS_CLIENT_CERT                       (string)    client cert for NATS mTLS auth
   662  MINIO_NOTIFY_NATS_CLIENT_KEY                        (string)    client cert key for NATS mTLS auth
   663  MINIO_NOTIFY_NATS_QUEUE_DIR                         (path)      staging dir for undelivered messages e.g. '/home/events'
   664  MINIO_NOTIFY_NATS_QUEUE_LIMIT                       (number)    maximum limit for undelivered messages, defaults to '100000'
   665  MINIO_NOTIFY_NATS_COMMENT                           (sentence)  optionally add a comment to this setting
   666  ```
   667  
   668  To update the configuration, use `mc admin config get` command to get the current configuration file for the minio deployment.
   669  
   670  ```sh
   671  $ mc admin config get myminio/ notify_nats
   672  notify_nats:1 password="yoursecret" streaming_max_pub_acks_in_flight="10" subject="" address="0.0.0.0:4222"  token="" username="yourusername" ping_interval="0" queue_limit="0" tls="off" tls_skip_verify="off" streaming_async="on" queue_dir="" streaming_cluster_id="test-cluster" streaming_enable="on"
   673  ```
   674  
   675  Use `mc admin config set` command to update the configuration for the deployment.Restart MinIO server to reflect config changes. `bucketevents` is the subject used by NATS in this example.
   676  
   677  ```sh
   678  mc admin config set myminio notify_nats:1 password="yoursecret" streaming_max_pub_acks_in_flight="10" subject="" address="0.0.0.0:4222"  token="" username="yourusername" ping_interval="0" queue_limit="0" tls="off" streaming_async="on" queue_dir="" streaming_cluster_id="test-cluster" streaming_enable="on"
   679  ```
   680  
   681  MinIO server also supports [NATS Streaming mode](http://nats.io/documentation/streaming/nats-streaming-intro/) that offers additional functionality like `At-least-once-delivery`, and `Publisher rate limiting`. To configure MinIO server to send notifications to NATS Streaming server, update the MinIO server configuration file as follows:
   682  
   683  Read more about sections `cluster_id`, `client_id` on [NATS documentation](https://github.com/nats-io/nats-streaming-server/blob/master/README.md). Section `maxPubAcksInflight` is explained [here](https://github.com/nats-io/stan.go#publisher-rate-limiting).
   684  
   685  ### Step 2: Enable NATS bucket notification using MinIO client
   686  
   687  We will enable bucket event notification to trigger whenever a JPEG image is uploaded or deleted from `images` bucket on `myminio` server. Here ARN value is `arn:minio:sqs::1:nats`. To understand more about ARN please follow [AWS ARN](http://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html) documentation.
   688  
   689  ```
   690  mc mb myminio/images
   691  mc event add myminio/images arn:minio:sqs::1:nats --suffix .jpg
   692  mc event list myminio/images
   693  arn:minio:sqs::1:nats s3:ObjectCreated:*,s3:ObjectRemoved:* Filter: suffix=”.jpg”
   694  ```
   695  
   696  ### Step 3: Test on NATS
   697  
   698  If you use NATS server, check out this sample program below to log the bucket notification added to NATS.
   699  
   700  ```go
   701  package main
   702  
   703  // Import Go and NATS packages
   704  import (
   705   "log"
   706   "runtime"
   707  
   708   "github.com/nats-io/nats.go"
   709  )
   710  
   711  func main() {
   712  
   713   // Create server connection
   714   natsConnection, _ := nats.Connect("nats://yourusername:yoursecret@localhost:4222")
   715   log.Println("Connected")
   716  
   717   // Subscribe to subject
   718   log.Printf("Subscribing to subject 'bucketevents'\n")
   719   natsConnection.Subscribe("bucketevents", func(msg *nats.Msg) {
   720  
   721    // Handle the message
   722    log.Printf("Received message '%s\n", string(msg.Data)+"'")
   723   })
   724  
   725   // Keep the connection alive
   726   runtime.Goexit()
   727  }
   728  ```
   729  
   730  ```
   731  go run nats.go
   732  2016/10/12 06:39:18 Connected
   733  2016/10/12 06:39:18 Subscribing to subject 'bucketevents'
   734  ```
   735  
   736  Open another terminal and upload a JPEG image into `images` bucket.
   737  
   738  ```
   739  mc cp myphoto.jpg myminio/images
   740  ```
   741  
   742  The example `nats.go` program prints event notification to console.
   743  
   744  ```
   745  go run nats.go
   746  2016/10/12 06:51:26 Connected
   747  2016/10/12 06:51:26 Subscribing to subject 'bucketevents'
   748  2016/10/12 06:51:33 Received message '{"EventType":"s3:ObjectCreated:Put","Key":"images/myphoto.jpg","Records":[{"eventVersion":"2.0","eventSource":"aws:s3","awsRegion":"","eventTime":"2016-10-12T13:51:33Z","eventName":"s3:ObjectCreated:Put","userIdentity":{"principalId":"minio"},"requestParameters":{"sourceIPAddress":"[::1]:57106"},"responseElements":{},"s3":{"s3SchemaVersion":"1.0","configurationId":"Config","bucket":{"name":"images","ownerIdentity":{"principalId":"minio"},"arn":"arn:aws:s3:::images"},"object":{"key":"myphoto.jpg","size":56060,"eTag":"1d97bf45ecb37f7a7b699418070df08f","sequencer":"147CCD1AE054BFD0"}}}],"level":"info","msg":"","time":"2016-10-12T06:51:33-07:00"}
   749  ```
   750  
   751  If you use NATS Streaming server, check out this sample program below to log the bucket notification added to NATS.
   752  
   753  ```go
   754  package main
   755  
   756  // Import Go and NATS packages
   757  import (
   758   "fmt"
   759   "runtime"
   760  
   761   "github.com/nats-io/stan.go"
   762  )
   763  
   764  func main() {
   765  
   766   var stanConnection stan.Conn
   767  
   768   subscribe := func() {
   769    fmt.Printf("Subscribing to subject 'bucketevents'\n")
   770    stanConnection.Subscribe("bucketevents", func(m *stan.Msg) {
   771  
   772     // Handle the message
   773     fmt.Printf("Received a message: %s\n", string(m.Data))
   774    })
   775   }
   776  
   777  
   778   stanConnection, _ = stan.Connect("test-cluster", "test-client", stan.NatsURL("nats://yourusername:yoursecret@0.0.0.0:4222"), stan.SetConnectionLostHandler(func(c stan.Conn, _ error) {
   779    go func() {
   780     for {
   781      // Reconnect if the connection is lost.
   782      if stanConnection == nil || stanConnection.NatsConn() == nil ||  !stanConnection.NatsConn().IsConnected() {
   783       stanConnection, _ = stan.Connect("test-cluster", "test-client", stan.NatsURL("nats://yourusername:yoursecret@0.0.0.0:4222"), stan.SetConnectionLostHandler(func(c stan.Conn, _ error) {
   784        if c.NatsConn() != nil {
   785         c.NatsConn().Close()
   786        }
   787        _ = c.Close()
   788       }))
   789       if stanConnection != nil {
   790        subscribe()
   791       }
   792  
   793      }
   794     }
   795  
   796    }()
   797   }))
   798  
   799   // Subscribe to subject
   800   subscribe()
   801  
   802   // Keep the connection alive
   803   runtime.Goexit()
   804  }
   805  
   806  ```
   807  
   808  ```
   809  go run nats.go
   810  2017/07/07 11:47:40 Connected
   811  2017/07/07 11:47:40 Subscribing to subject 'bucketevents'
   812  ```
   813  
   814  Open another terminal and upload a JPEG image into `images` bucket.
   815  
   816  ```
   817  mc cp myphoto.jpg myminio/images
   818  ```
   819  
   820  The example `nats.go` program prints event notification to console.
   821  
   822  ```
   823  Received a message: {"EventType":"s3:ObjectCreated:Put","Key":"images/myphoto.jpg","Records":[{"eventVersion":"2.0","eventSource":"minio:s3","awsRegion":"","eventTime":"2017-07-07T18:46:37Z","eventName":"s3:ObjectCreated:Put","userIdentity":{"principalId":"minio"},"requestParameters":{"sourceIPAddress":"192.168.1.80:55328"},"responseElements":{"x-amz-request-id":"14CF20BD1EFD5B93","x-minio-origin-endpoint":"http://127.0.0.1:9000"},"s3":{"s3SchemaVersion":"1.0","configurationId":"Config","bucket":{"name":"images","ownerIdentity":{"principalId":"minio"},"arn":"arn:aws:s3:::images"},"object":{"key":"myphoto.jpg","size":248682,"eTag":"f1671feacb8bbf7b0397c6e9364e8c92","contentType":"image/jpeg","userDefined":{"content-type":"image/jpeg"},"versionId":"1","sequencer":"14CF20BD1EFD5B93"}},"source":{"host":"192.168.1.80","port":"55328","userAgent":"MinIO (linux; amd64) minio-go/2.0.4 mc/DEVELOPMENT.GOGET"}}],"level":"info","msg":"","time":"2017-07-07T11:46:37-07:00"}
   824  ```
   825  
   826  ## Publish MinIO events via PostgreSQL
   827  
   828  > NOTE: Until release RELEASE.2020-04-10T03-34-42Z PostgreSQL notification used to support following options:
   829  >
   830  > ```
   831  > host                (hostname)           Postgres server hostname (used only if `connection_string` is empty)
   832  > port                (port)               Postgres server port, defaults to `5432` (used only if `connection_string` is empty)
   833  > username            (string)             database username (used only if `connection_string` is empty)
   834  > password            (string)             database password (used only if `connection_string` is empty)
   835  > database            (string)             database name (used only if `connection_string` is empty)
   836  > ```
   837  >
   838  > These are now deprecated, if you plan to upgrade to any releases after _RELEASE.2020-04-10T03-34-42Z_ make sure
   839  > to migrate to only using _connection_string_ option. To migrate, once you have upgraded all the servers use the
   840  > following command to update the existing notification targets.
   841  >
   842  > ```
   843  > mc admin config set myminio/ notify_postgres[:name] connection_string="host=hostname port=2832 username=psqluser password=psqlpass database=bucketevents"
   844  > ```
   845  >
   846  > Please make sure this step is carried out, without this step PostgreSQL notification targets will not work,
   847  > an error message will be shown on the console upon server upgrade/restart, make sure to follow the above
   848  > instructions appropriately. For further questions please join our <https://slack.min.io>
   849  
   850  Install [PostgreSQL](https://www.postgresql.org/) database server. For illustrative purposes, we have set the "postgres" user password as `password` and created a database called `minio_events` to store the events.
   851  
   852  This notification target supports two formats: _namespace_ and _access_.
   853  
   854  When the _namespace_ format is used, MinIO synchronizes objects in the bucket with rows in the table. It creates rows with two columns: key and value. The key is the bucket and object name of an object that exists in MinIO. The value is JSON encoded event data about the operation that created/replaced the object in MinIO. When objects are updated or deleted, the corresponding row from this table is updated or deleted respectively.
   855  
   856  When the _access_ format is used, MinIO appends events to a table. It creates rows with two columns: event_time and event_data. The event_time is the time at which the event occurred in the MinIO server. The event_data is the JSON encoded event data about the operation on an object. No rows are deleted or modified in this format.
   857  
   858  The steps below show how to use this notification target in `namespace` format. The other format is very similar and is omitted for brevity.
   859  
   860  ### Step 1: Ensure postgresql minimum requirements are met
   861  
   862  MinIO requires PostgreSQL version 9.5 or above. MinIO uses the [`INSERT ON CONFLICT`](https://www.postgresql.org/docs/9.5/static/sql-insert.html#SQL-ON-CONFLICT) (aka UPSERT) feature, introduced in version 9.5 and the [JSONB](https://www.postgresql.org/docs/9.4/static/datatype-json.html) data-type introduced in version 9.4.
   863  
   864  ### Step 2: Add PostgreSQL endpoint to MinIO
   865  
   866  The PostgreSQL configuration is located in the `notify_postgresql` key. Create a configuration key-value pair here for your PostgreSQL instance. The key is a name for your PostgreSQL endpoint, and the value is a collection of key-value parameters described in the table below.
   867  
   868  ```
   869  KEY:
   870  notify_postgres[:name]  publish bucket notifications to Postgres databases
   871  
   872  ARGS:
   873  connection_string*   (string)             Postgres server connection-string e.g. "host=localhost port=5432 dbname=minio_events user=postgres password=password sslmode=disable"
   874  table*               (string)             DB table name to store/update events, table is auto-created
   875  format*              (namespace*|access)  'namespace' reflects current bucket/object list and 'access' reflects a journal of object operations, defaults to 'namespace'
   876  queue_dir            (path)               staging dir for undelivered messages e.g. '/home/events'
   877  queue_limit          (number)             maximum limit for undelivered messages, defaults to '100000'
   878  max_open_connections (number)             maximum number of open connections to the database, defaults to '2'
   879  comment              (sentence)           optionally add a comment to this setting
   880  ```
   881  
   882  or environment variables
   883  
   884  ```
   885  KEY:
   886  notify_postgres[:name]  publish bucket notifications to Postgres databases
   887  
   888  ARGS:
   889  MINIO_NOTIFY_POSTGRES_ENABLE*              (on|off)             enable notify_postgres target, default is 'off'
   890  MINIO_NOTIFY_POSTGRES_CONNECTION_STRING*   (string)             Postgres server connection-string e.g. "host=localhost port=5432 dbname=minio_events user=postgres password=password sslmode=disable"
   891  MINIO_NOTIFY_POSTGRES_TABLE*               (string)             DB table name to store/update events, table is auto-created
   892  MINIO_NOTIFY_POSTGRES_FORMAT*              (namespace*|access)  'namespace' reflects current bucket/object list and 'access' reflects a journal of object operations, defaults to 'namespace'
   893  MINIO_NOTIFY_POSTGRES_QUEUE_DIR            (path)               staging dir for undelivered messages e.g. '/home/events'
   894  MINIO_NOTIFY_POSTGRES_QUEUE_LIMIT          (number)             maximum limit for undelivered messages, defaults to '100000'
   895  MINIO_NOTIFY_POSTGRES_COMMENT              (sentence)           optionally add a comment to this setting
   896  MINIO_NOTIFY_POSTGRES_MAX_OPEN_CONNECTIONS (number)             maximum number of open connections to the database, defaults to '2'
   897  ```
   898  
   899  > NOTE: If the `max_open_connections` key or the environment variable `MINIO_NOTIFY_POSTGRES_MAX_OPEN_CONNECTIONS` is set to `0`, There will be no limit set on the number of
   900  > open connections to the database. This setting is generally NOT recommended as the behavior may be inconsistent during recursive deletes in `namespace` format.
   901  
   902  MinIO supports persistent event store. The persistent store will backup events when the PostgreSQL connection goes offline and replays it when the broker comes back online. The event store can be configured by setting the directory path in `queue_dir` field and the maximum limit of events in the queue_dir in `queue_limit` field. For eg, the `queue_dir` can be `/home/events` and `queue_limit` can be `1000`. By default, the `queue_limit` is set to 100000.
   903  
   904  Note that for illustration here, we have disabled SSL. In the interest of security, for production this is not recommended.
   905  To update the configuration, use `mc admin config get` command to get the current configuration.
   906  
   907  ```sh
   908  $ mc admin config get myminio notify_postgres
   909  notify_postgres:1 queue_dir="" connection_string="" queue_limit="0"  table="" format="namespace"
   910  ```
   911  
   912  Use `mc admin config set` command to update the configuration for the deployment. Restart the MinIO server to put the changes into effect. The server will print a line like `SQS ARNs: arn:minio:sqs::1:postgresql` at start-up if there were no errors.
   913  
   914  ```sh
   915  mc admin config set myminio notify_postgres:1 connection_string="host=localhost port=5432 dbname=minio_events user=postgres password=password sslmode=disable" table="bucketevents" format="namespace"
   916  ```
   917  
   918  Note that, you can add as many PostgreSQL server endpoint configurations as needed by providing an identifier (like "1" in the example above) for the PostgreSQL instance and an object of per-server configuration parameters.
   919  
   920  ### Step 3: Enable PostgreSQL bucket notification using MinIO client
   921  
   922  We will now enable bucket event notifications on a bucket named `images`. Whenever a JPEG image is created/overwritten, a new row is added or an existing row is updated in the PostgreSQL configured above. When an existing object is deleted, the corresponding row is deleted from the PostgreSQL table. Thus, the rows in the PostgreSQL table, reflect the `.jpg` objects in the `images` bucket.
   923  
   924  To configure this bucket notification, we need the ARN printed by MinIO in the previous step. Additional information about ARN is available [here](http://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html).
   925  
   926  With the `mc` tool, the configuration is very simple to add. Let us say that the MinIO server is aliased as `myminio` in our mc configuration. Execute the following:
   927  
   928  ```
   929  # Create bucket named `images` in myminio
   930  mc mb myminio/images
   931  # Add notification configuration on the `images` bucket using the MySQL ARN. The --suffix argument filters events.
   932  mc event add myminio/images arn:minio:sqs::1:postgresql --suffix .jpg
   933  # Print out the notification configuration on the `images` bucket.
   934  mc event list myminio/images
   935  mc event list myminio/images
   936  arn:minio:sqs::1:postgresql s3:ObjectCreated:*,s3:ObjectRemoved:* Filter: suffix=”.jpg”
   937  ```
   938  
   939  ### Step 4: Test on PostgreSQL
   940  
   941  Open another terminal and upload a JPEG image into `images` bucket.
   942  
   943  ```
   944  mc cp myphoto.jpg myminio/images
   945  ```
   946  
   947  Open PostgreSQL terminal to list the rows in the `bucketevents` table.
   948  
   949  ```
   950  $ psql -h 127.0.0.1 -U postgres -d minio_events
   951  minio_events=# select * from bucketevents;
   952  
   953  key                 |                      value
   954  --------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
   955   images/myphoto.jpg | {"Records": [{"s3": {"bucket": {"arn": "arn:aws:s3:::images", "name": "images", "ownerIdentity": {"principalId": "minio"}}, "object": {"key": "myphoto.jpg", "eTag": "1d97bf45ecb37f7a7b699418070df08f", "size": 56060, "sequencer": "147CE57C70B31931"}, "configurationId": "Config", "s3SchemaVersion": "1.0"}, "awsRegion": "", "eventName": "s3:ObjectCreated:Put", "eventTime": "2016-10-12T21:18:20Z", "eventSource": "aws:s3", "eventVersion": "2.0", "userIdentity": {"principalId": "minio"}, "responseElements": {}, "requestParameters": {"sourceIPAddress": "[::1]:39706"}}]}
   956  (1 row)
   957  ```
   958  
   959  ## Publish MinIO events via MySQL
   960  
   961  > NOTE: Until release RELEASE.2020-04-10T03-34-42Z MySQL notification used to support following options:
   962  >
   963  > ```
   964  > host         (hostname)           MySQL server hostname (used only if `dsn_string` is empty)
   965  > port         (port)               MySQL server port (used only if `dsn_string` is empty)
   966  > username     (string)             database username (used only if `dsn_string` is empty)
   967  > password     (string)             database password (used only if `dsn_string` is empty)
   968  > database     (string)             database name (used only if `dsn_string` is empty)
   969  > ```
   970  >
   971  > These are now deprecated, if you plan to upgrade to any releases after _RELEASE.2020-04-10T03-34-42Z_ make sure
   972  > to migrate to only using _dsn_string_ option. To migrate, once you have upgraded all the servers use the
   973  > following command to update the existing notification targets.
   974  >
   975  > ```
   976  > mc admin config set myminio/ notify_mysql[:name] dsn_string="mysqluser:mysqlpass@tcp(localhost:2832)/bucketevents"
   977  > ```
   978  >
   979  > Please make sure this step is carried out, without this step MySQL notification targets will not work,
   980  > an error message will be shown on the console upon server upgrade/restart, make sure to follow the above
   981  > instructions appropriately. For further questions please join our <https://slack.min.io>
   982  
   983  Install MySQL from [here](https://dev.mysql.com/downloads/mysql/). For illustrative purposes, we have set the root password as `password` and created a database called `miniodb` to store the events.
   984  
   985  This notification target supports two formats: _namespace_ and _access_.
   986  
   987  When the _namespace_ format is used, MinIO synchronizes objects in the bucket with rows in the table. It creates rows with two columns: key_name and value. The key_name is the bucket and object name of an object that exists in MinIO. The value is JSON encoded event data about the operation that created/replaced the object in MinIO. When objects are updated or deleted, the corresponding row from this table is updated or deleted respectively.
   988  
   989  When the _access_ format is used, MinIO appends events to a table. It creates rows with two columns: event_time and event_data. The event_time is the time at which the event occurred in the MinIO server. The event_data is the JSON encoded event data about the operation on an object. No rows are deleted or modified in this format.
   990  
   991  The steps below show how to use this notification target in `namespace` format. The other format is very similar and is omitted for brevity.
   992  
   993  ### Step 1: Ensure MySQL minimum requirements are met
   994  
   995  MinIO requires MySQL version 5.7.8 or above. MinIO uses the [JSON](https://dev.mysql.com/doc/refman/5.7/en/json.html) data-type introduced in version 5.7.8. We tested this setup on MySQL 5.7.17.
   996  
   997  ### Step 2: Add MySQL server endpoint configuration to MinIO
   998  
   999  The MySQL configuration is located in the `notify_mysql` key. Create a configuration key-value pair here for your MySQL instance. The key is a name for your MySQL endpoint, and the value is a collection of key-value parameters described in the table below.
  1000  
  1001  ```
  1002  KEY:
  1003  notify_mysql[:name]  publish bucket notifications to MySQL databases. When multiple MySQL server endpoints are needed, a user specified "name" can be added for each configuration, (e.g."notify_mysql:myinstance").
  1004  
  1005  ARGS:
  1006  dsn_string*          (string)             MySQL data-source-name connection string e.g. "<user>:<password>@tcp(<host>:<port>)/<database>"
  1007  table*               (string)             DB table name to store/update events, table is auto-created
  1008  format*              (namespace*|access)  'namespace' reflects current bucket/object list and 'access' reflects a journal of object operations, defaults to 'namespace'
  1009  queue_dir            (path)               staging dir for undelivered messages e.g. '/home/events'
  1010  queue_limit          (number)             maximum limit for undelivered messages, defaults to '100000'
  1011  max_open_connections (number)             maximum number of open connections to the database, defaults to '2'
  1012  comment              (sentence)           optionally add a comment to this setting
  1013  ```
  1014  
  1015  or environment variables
  1016  
  1017  ```
  1018  KEY:
  1019  notify_mysql[:name]  publish bucket notifications to MySQL databases
  1020  
  1021  ARGS:
  1022  MINIO_NOTIFY_MYSQL_ENABLE*              (on|off)             enable notify_mysql target, default is 'off'
  1023  MINIO_NOTIFY_MYSQL_DSN_STRING*          (string)             MySQL data-source-name connection string e.g. "<user>:<password>@tcp(<host>:<port>)/<database>"
  1024  MINIO_NOTIFY_MYSQL_TABLE*               (string)             DB table name to store/update events, table is auto-created
  1025  MINIO_NOTIFY_MYSQL_FORMAT*              (namespace*|access)  'namespace' reflects current bucket/object list and 'access' reflects a journal of object operations, defaults to 'namespace'
  1026  MINIO_NOTIFY_MYSQL_QUEUE_DIR            (path)               staging dir for undelivered messages e.g. '/home/events'
  1027  MINIO_NOTIFY_MYSQL_QUEUE_LIMIT          (number)             maximum limit for undelivered messages, defaults to '100000'
  1028  MINIO_NOTIFY_MYSQL_MAX_OPEN_CONNECTIONS (number)             maximum number of open connections to the database, defaults to '2'
  1029  MINIO_NOTIFY_MYSQL_COMMENT              (sentence)           optionally add a comment to this setting
  1030  ```
  1031  
  1032  > NOTE: If the `max_open_connections` key or the environment variable `MINIO_NOTIFY_MYSQL_MAX_OPEN_CONNECTIONS` is set to `0`, There will be no limit set on the number of
  1033  > open connections to the database. This setting is generally NOT recommended as the behavior may be inconsistent during recursive deletes in `namespace` format.
  1034  
  1035  `dsn_string` is required and is of form `"<user>:<password>@tcp(<host>:<port>)/<database>"`
  1036  
  1037  MinIO supports persistent event store. The persistent store will backup events if MySQL connection goes offline and then replays the stored events when the broken connection comes back up. The event store can be configured by setting a directory path in `queue_dir` field, and the maximum number of events, which can be stored in a `queue_dir`, in `queue_limit` field. For example, `queue_dir` can be set to `/home/events` and `queue_limit` can be set to `1000`. By default, the `queue_limit` is set to `100000`.
  1038  
  1039  Before updating the configuration, let's start with `mc admin config get` command to get the current configuration.
  1040  
  1041  ```sh
  1042  $ mc admin config get myminio/ notify_mysql
  1043  notify_mysql:myinstance enable=off format=namespace host= port= username= password= database= dsn_string= table= queue_dir= queue_limit=0
  1044  ```
  1045  
  1046  Use `mc admin config set` command to update MySQL notification configuration for the deployment with `dsn_string` parameter:
  1047  
  1048  ```sh
  1049  mc admin config set myminio notify_mysql:myinstance table="minio_images" dsn_string="root:xxxx@tcp(172.17.0.1:3306)/miniodb"
  1050  ```
  1051  
  1052  Note that, you can add as many MySQL server endpoint configurations as needed by providing an identifier (like "myinstance" in the example above) for each MySQL instance desired.
  1053  
  1054  Restart the MinIO server to put the changes into effect. The server will print a line like `SQS ARNs: arn:minio:sqs::myinstance:mysql` at start-up, if there are no errors.
  1055  
  1056  ### Step 3: Enable MySQL bucket notification using MinIO client
  1057  
  1058  We will now setup bucket notifications on a bucket named `images`. Whenever a JPEG image object is created/overwritten, a new row is added or an existing row is updated in the MySQL table configured above. When an existing object is deleted, the corresponding row is deleted from the MySQL table. Thus, the rows in the MySQL table, reflect the `.jpg` objects in the `images` bucket.
  1059  
  1060  To configure this bucket notification, we need the ARN printed by MinIO in the previous step. Additional information about ARN is available [here](http://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html).
  1061  
  1062  With the `mc` tool, the configuration is very simple to add. Let us say that the MinIO server is aliased as `myminio` in our mc configuration. Execute the following:
  1063  
  1064  ```
  1065  # Create bucket named `images` in myminio
  1066  mc mb myminio/images
  1067  # Add notification configuration on the `images` bucket using the MySQL ARN. The --suffix argument filters events.
  1068  mc event add myminio/images arn:minio:sqs::myinstance:mysql --suffix .jpg
  1069  # Print out the notification configuration on the `images` bucket.
  1070  mc event list myminio/images
  1071  arn:minio:sqs::myinstance:mysql s3:ObjectCreated:*,s3:ObjectRemoved:*,s3:ObjectAccessed:* Filter: suffix=”.jpg”
  1072  ```
  1073  
  1074  ### Step 4: Test on MySQL
  1075  
  1076  Open another terminal and upload a JPEG image into `images` bucket:
  1077  
  1078  ```
  1079  mc cp myphoto.jpg myminio/images
  1080  ```
  1081  
  1082  Open MySQL terminal and list the rows in the `minio_images` table.
  1083  
  1084  ```
  1085  $ mysql -h 172.17.0.1 -P 3306 -u root -p miniodb
  1086  mysql> select * from minio_images;
  1087  +--------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  1088  | key_name           | value                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
  1089  +--------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  1090  | images/myphoto.jpg | {"Records": [{"s3": {"bucket": {"arn": "arn:aws:s3:::images", "name": "images", "ownerIdentity": {"principalId": "minio"}}, "object": {"key": "myphoto.jpg", "eTag": "467886be95c8ecfd71a2900e3f461b4f", "size": 26, "sequencer": "14AC59476F809FD3"}, "configurationId": "Config", "s3SchemaVersion": "1.0"}, "awsRegion": "", "eventName": "s3:ObjectCreated:Put", "eventTime": "2017-03-16T11:29:00Z", "eventSource": "aws:s3", "eventVersion": "2.0", "userIdentity": {"principalId": "minio"}, "responseElements": {"x-amz-request-id": "14AC59476F809FD3", "x-minio-origin-endpoint": "http://192.168.86.110:9000"}, "requestParameters": {"sourceIPAddress": "127.0.0.1:38260"}}]} |
  1091  +--------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  1092  1 row in set (0.01 sec)
  1093  
  1094  ```
  1095  
  1096  ## Publish MinIO events via Kafka
  1097  
  1098  Install Apache Kafka from [here](http://kafka.apache.org/).
  1099  
  1100  ### Step 1: Ensure minimum requirements are met
  1101  
  1102  MinIO requires Kafka version 0.10 or 0.9. Internally MinIO uses the [Shopify/sarama](https://github.com/Shopify/sarama/) library and so has the same version compatibility as provided by this library.
  1103  
  1104  ### Step 2: Add Kafka endpoint to MinIO
  1105  
  1106  MinIO supports persistent event store. The persistent store will backup events when the kafka broker goes offline and replays it when the broker comes back online. The event store can be configured by setting the directory path in `queue_dir` field and the maximum limit of events in the queue_dir in `queue_limit` field. For eg, the `queue_dir` can be `/home/events` and `queue_limit` can be `1000`. By default, the `queue_limit` is set to 100000.
  1107  
  1108  ```
  1109  KEY:
  1110  notify_kafka[:name]  publish bucket notifications to Kafka endpoints
  1111  
  1112  ARGS:
  1113  brokers*         (csv)       comma separated list of Kafka broker addresses
  1114  topic            (string)    Kafka topic used for bucket notifications
  1115  sasl_username    (string)    username for SASL/PLAIN or SASL/SCRAM authentication
  1116  sasl_password    (string)    password for SASL/PLAIN or SASL/SCRAM authentication
  1117  sasl_mechanism   (string)    sasl authentication mechanism, default 'PLAIN'
  1118  tls_client_auth  (string)    clientAuth determines the Kafka server's policy for TLS client auth
  1119  sasl             (on|off)    set to 'on' to enable SASL authentication
  1120  tls              (on|off)    set to 'on' to enable TLS
  1121  tls_skip_verify  (on|off)    trust server TLS without verification, defaults to "on" (verify)
  1122  client_tls_cert  (path)      path to client certificate for mTLS auth
  1123  client_tls_key   (path)      path to client key for mTLS auth
  1124  queue_dir        (path)      staging dir for undelivered messages e.g. '/home/events'
  1125  queue_limit      (number)    maximum limit for undelivered messages, defaults to '100000'
  1126  version          (string)    specify the version of the Kafka cluster e.g '2.2.0'
  1127  comment          (sentence)  optionally add a comment to this setting
  1128  ```
  1129  
  1130  or environment variables
  1131  
  1132  ```
  1133  KEY:
  1134  notify_kafka[:name]  publish bucket notifications to Kafka endpoints
  1135  
  1136  ARGS:
  1137  MINIO_NOTIFY_KAFKA_ENABLE*                     (on|off)                    enable notify_kafka target, default is 'off'
  1138  MINIO_NOTIFY_KAFKA_BROKERS*                    (csv)                       comma separated list of Kafka broker addresses
  1139  MINIO_NOTIFY_KAFKA_TOPIC                       (string)                    Kafka topic used for bucket notifications
  1140  MINIO_NOTIFY_KAFKA_SASL_USERNAME               (string)                    username for SASL/PLAIN or SASL/SCRAM authentication
  1141  MINIO_NOTIFY_KAFKA_SASL_PASSWORD               (string)                    password for SASL/PLAIN or SASL/SCRAM authentication
  1142  MINIO_NOTIFY_KAFKA_SASL_MECHANISM              (plain*|sha256|sha512)      sasl authentication mechanism, default 'plain'
  1143  MINIO_NOTIFY_KAFKA_TLS_CLIENT_AUTH             (string)                    clientAuth determines the Kafka server's policy for TLS client auth
  1144  MINIO_NOTIFY_KAFKA_SASL                        (on|off)                    set to 'on' to enable SASL authentication
  1145  MINIO_NOTIFY_KAFKA_TLS                         (on|off)                    set to 'on' to enable TLS
  1146  MINIO_NOTIFY_KAFKA_TLS_SKIP_VERIFY             (on|off)                    trust server TLS without verification, defaults to "on" (verify)
  1147  MINIO_NOTIFY_KAFKA_CLIENT_TLS_CERT             (path)                      path to client certificate for mTLS auth
  1148  MINIO_NOTIFY_KAFKA_CLIENT_TLS_KEY              (path)                      path to client key for mTLS auth
  1149  MINIO_NOTIFY_KAFKA_QUEUE_DIR                   (path)                      staging dir for undelivered messages e.g. '/home/events'
  1150  MINIO_NOTIFY_KAFKA_QUEUE_LIMIT                 (number)                    maximum limit for undelivered messages, defaults to '100000'
  1151  MINIO_NOTIFY_KAFKA_COMMENT                     (sentence)                  optionally add a comment to this setting
  1152  MINIO_NOTIFY_KAFKA_VERSION                     (string)                    specify the version of the Kafka cluster e.g. '2.2.0'
  1153  MINIO_NOTIFY_KAFKA_PRODUCER_COMPRESSION_CODEC  (none|snappy|gzip|lz4|zstd) compression codec for producer messages
  1154  MINIO_NOTIFY_KAFKA_PRODUCER_COMPRESSION_LEVEL  (number)                    compression level for producer messages, defaults to '0'
  1155  ```
  1156  
  1157  To update the configuration, use `mc admin config get` command to get the current configuration.
  1158  
  1159  ```sh
  1160  $ mc admin config get myminio/ notify_kafka
  1161  notify_kafka:1 tls_skip_verify="off"  queue_dir="" queue_limit="0" sasl="off" sasl_password="" sasl_username="" tls_client_auth="0" tls="off" brokers="" topic="" client_tls_cert="" client_tls_key="" version=""
  1162  ```
  1163  
  1164  Use `mc admin config set` command to update the configuration for the deployment. Restart the MinIO server to put the changes into effect. The server will print a line like `SQS ARNs: arn:minio:sqs::1:kafka` at start-up if there were no errors.`bucketevents` is the topic used by kafka in this example.
  1165  
  1166  ```sh
  1167  mc admin config set myminio notify_kafka:1 tls_skip_verify="off"  queue_dir="" queue_limit="0" sasl="off" sasl_password="" sasl_username="" tls_client_auth="0" tls="off" client_tls_cert="" client_tls_key="" brokers="localhost:9092,localhost:9093" topic="bucketevents" version=""
  1168  ```
  1169  
  1170  ### Step 3: Enable Kafka bucket notification using MinIO client
  1171  
  1172  We will enable bucket event notification to trigger whenever a JPEG image is uploaded or deleted from `images` bucket on `myminio` server. Here ARN value is `arn:minio:sqs::1:kafka`. To understand more about ARN please follow [AWS ARN](http://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html) documentation.
  1173  
  1174  ```
  1175  mc mb myminio/images
  1176  mc event add  myminio/images arn:minio:sqs::1:kafka --suffix .jpg
  1177  mc event list myminio/images
  1178  arn:minio:sqs::1:kafka s3:ObjectCreated:*,s3:ObjectRemoved:* Filter: suffix=”.jpg”
  1179  ```
  1180  
  1181  ### Step 4: Test on Kafka
  1182  
  1183  We used [kafkacat](https://github.com/edenhill/kafkacat) to print all notifications on the console.
  1184  
  1185  ```
  1186  kafkacat -C -b localhost:9092 -t bucketevents
  1187  ```
  1188  
  1189  Open another terminal and upload a JPEG image into `images` bucket.
  1190  
  1191  ```
  1192  mc cp myphoto.jpg myminio/images
  1193  ```
  1194  
  1195  `kafkacat` prints the event notification to the console.
  1196  
  1197  ```
  1198  kafkacat -b localhost:9092 -t bucketevents
  1199  {
  1200      "EventName": "s3:ObjectCreated:Put",
  1201      "Key": "images/myphoto.jpg",
  1202      "Records": [
  1203          {
  1204              "eventVersion": "2.0",
  1205              "eventSource": "minio:s3",
  1206              "awsRegion": "",
  1207              "eventTime": "2019-09-10T17:41:54Z",
  1208              "eventName": "s3:ObjectCreated:Put",
  1209              "userIdentity": {
  1210                  "principalId": "AKIAIOSFODNN7EXAMPLE"
  1211              },
  1212              "requestParameters": {
  1213                  "accessKey": "AKIAIOSFODNN7EXAMPLE",
  1214                  "region": "",
  1215                  "sourceIPAddress": "192.168.56.192"
  1216              },
  1217              "responseElements": {
  1218                  "x-amz-request-id": "15C3249451E12784",
  1219                  "x-minio-deployment-id": "751a8ba6-acb2-42f6-a297-4cdf1cf1fa4f",
  1220                  "x-minio-origin-endpoint": "http://192.168.97.83:9000"
  1221              },
  1222              "s3": {
  1223                  "s3SchemaVersion": "1.0",
  1224                  "configurationId": "Config",
  1225                  "bucket": {
  1226                      "name": "images",
  1227                      "ownerIdentity": {
  1228                          "principalId": "AKIAIOSFODNN7EXAMPLE"
  1229                      },
  1230                      "arn": "arn:aws:s3:::images"
  1231                  },
  1232                  "object": {
  1233                      "key": "myphoto.jpg",
  1234                      "size": 6474,
  1235                      "eTag": "430f89010c77aa34fc8760696da62d08-1",
  1236                      "contentType": "image/jpeg",
  1237                      "userMetadata": {
  1238                          "content-type": "image/jpeg"
  1239                      },
  1240                      "versionId": "1",
  1241                      "sequencer": "15C32494527B46C5"
  1242                  }
  1243              },
  1244              "source": {
  1245                  "host": "192.168.56.192",
  1246                  "port": "",
  1247                  "userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:69.0) Gecko/20100101 Firefox/69.0"
  1248              }
  1249          }
  1250      ]
  1251  }
  1252  ```
  1253  
  1254  ## Publish MinIO events via Webhooks
  1255  
  1256  [Webhooks](https://en.wikipedia.org/wiki/Webhook) are a way to receive information when it happens, rather than continually polling for that data.
  1257  
  1258  ### Step 1: Add Webhook endpoint to MinIO
  1259  
  1260  MinIO supports persistent event store. The persistent store will backup events when the webhook goes offline and replays it when the broker comes back online. The event store can be configured by setting the directory path in `queue_dir` field and the maximum limit of events in the queue_dir in `queue_limit` field. For eg, the `queue_dir` can be `/home/events` and `queue_limit` can be `1000`. By default, the `queue_limit` is set to 100000.
  1261  
  1262  ```
  1263  KEY:
  1264  notify_webhook[:name]  publish bucket notifications to webhook endpoints
  1265  
  1266  ARGS:
  1267  endpoint*    (url)       webhook server endpoint e.g. http://localhost:8080/minio/events
  1268  auth_token   (string)    opaque string or JWT authorization token
  1269  queue_dir    (path)      staging dir for undelivered messages e.g. '/home/events'
  1270  queue_limit  (number)    maximum limit for undelivered messages, defaults to '100000'
  1271  client_cert  (string)    client cert for Webhook mTLS auth
  1272  client_key   (string)    client cert key for Webhook mTLS auth
  1273  comment      (sentence)  optionally add a comment to this setting
  1274  ```
  1275  
  1276  or environment variables
  1277  
  1278  ```
  1279  KEY:
  1280  notify_webhook[:name]  publish bucket notifications to webhook endpoints
  1281  
  1282  ARGS:
  1283  MINIO_NOTIFY_WEBHOOK_ENABLE*      (on|off)    enable notify_webhook target, default is 'off'
  1284  MINIO_NOTIFY_WEBHOOK_ENDPOINT*    (url)       webhook server endpoint e.g. http://localhost:8080/minio/events
  1285  MINIO_NOTIFY_WEBHOOK_AUTH_TOKEN   (string)    opaque string or JWT authorization token
  1286  MINIO_NOTIFY_WEBHOOK_QUEUE_DIR    (path)      staging dir for undelivered messages e.g. '/home/events'
  1287  MINIO_NOTIFY_WEBHOOK_QUEUE_LIMIT  (number)    maximum limit for undelivered messages, defaults to '100000'
  1288  MINIO_NOTIFY_WEBHOOK_COMMENT      (sentence)  optionally add a comment to this setting
  1289  MINIO_NOTIFY_WEBHOOK_CLIENT_CERT  (string)    client cert for Webhook mTLS auth
  1290  MINIO_NOTIFY_WEBHOOK_CLIENT_KEY   (string)    client cert key for Webhook mTLS auth
  1291  ```
  1292  
  1293  ```sh
  1294  $ mc admin config get myminio/ notify_webhook
  1295  notify_webhook:1 endpoint="" auth_token="" queue_limit="0" queue_dir="" client_cert="" client_key=""
  1296  ```
  1297  
  1298  Use `mc admin config set` command to update the configuration for the deployment. Here the endpoint is the server listening for webhook notifications. Save the settings and restart the MinIO server for changes to take effect. Note that the endpoint needs to be live and reachable when you restart your MinIO server.
  1299  
  1300  ```sh
  1301  mc admin config set myminio notify_webhook:1 queue_limit="0"  endpoint="http://localhost:3000" queue_dir=""
  1302  ```
  1303  
  1304  ### Step 2: Enable Webhook bucket notification using MinIO client
  1305  
  1306  We will enable bucket event notification to trigger whenever a JPEG image is uploaded to `images` bucket on `myminio` server. Here ARN value is `arn:minio:sqs::1:webhook`. To learn more about ARN please follow [AWS ARN](http://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html) documentation.
  1307  
  1308  ```
  1309  mc mb myminio/images
  1310  mc mb myminio/images-thumbnail
  1311  mc event add myminio/images arn:minio:sqs::1:webhook --event put --suffix .jpg
  1312  ```
  1313  
  1314  Check if event notification is successfully configured by
  1315  
  1316  ```
  1317  mc event list myminio/images
  1318  ```
  1319  
  1320  You should get a response like this
  1321  
  1322  ```
  1323  arn:minio:sqs::1:webhook   s3:ObjectCreated:*   Filter: suffix=".jpg"
  1324  ```
  1325  
  1326  ### Step 3: Test with Thumbnailer
  1327  
  1328  We used [Thumbnailer](https://github.com/minio/thumbnailer) to listen for MinIO notifications when a new JPEG file is uploaded (HTTP PUT). Triggered by a notification, Thumbnailer uploads a thumbnail of new image to MinIO server. To start with, download and install Thumbnailer.
  1329  
  1330  ```
  1331  git clone https://github.com/minio/thumbnailer/
  1332  npm install
  1333  ```
  1334  
  1335  Then open the Thumbnailer config file at `config/webhook.json` and add the configuration for your MinIO server and then start Thumbnailer by
  1336  
  1337  ```
  1338  NODE_ENV=webhook node thumbnail-webhook.js
  1339  ```
  1340  
  1341  Thumbnailer starts running at `http://localhost:3000/`. Next, configure the MinIO server to send notifications to this URL (as mentioned in step 1) and use `mc` to set up bucket notifications (as mentioned in step 2). Then upload a JPEG image to MinIO server by
  1342  
  1343  ```
  1344  mc cp ~/images.jpg myminio/images
  1345  .../images.jpg:  8.31 KB / 8.31 KB ┃▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓┃ 100.00% 59.42 KB/s 0s
  1346  ```
  1347  
  1348  Wait a few moments, then check the bucket’s contents with mc ls — you will see a thumbnail appear.
  1349  
  1350  ```
  1351  mc ls myminio/images-thumbnail
  1352  [2017-02-08 11:39:40 IST]   992B images-thumbnail.jpg
  1353  ```
  1354  
  1355  ## Publish MinIO events to NSQ
  1356  
  1357  Install an NSQ Daemon from [here](https://nsq.io/). Or use the following Docker
  1358  command for starting an nsq daemon:
  1359  
  1360  ```
  1361  podman run --rm -p 4150-4151:4150-4151 nsqio/nsq /nsqd
  1362  ```
  1363  
  1364  ### Step 1: Add NSQ endpoint to MinIO
  1365  
  1366  MinIO supports persistent event store. The persistent store will backup events when the NSQ broker goes offline and replays it when the broker comes back online. The event store can be configured by setting the directory path in `queue_dir` field and the maximum limit of events in the queue_dir in `queue_limit` field. For eg, the `queue_dir` can be `/home/events` and `queue_limit` can be `1000`. By default, the `queue_limit` is set to 100000.
  1367  
  1368  To update the configuration, use `mc admin config get` command to get the current configuration for `notify_nsq`.
  1369  
  1370  ```
  1371  KEY:
  1372  notify_nsq[:name]  publish bucket notifications to NSQ endpoints
  1373  
  1374  ARGS:
  1375  nsqd_address*    (address)   NSQ server address e.g. '127.0.0.1:4150'
  1376  topic*           (string)    NSQ topic
  1377  tls              (on|off)    set to 'on' to enable TLS
  1378  tls_skip_verify  (on|off)    trust server TLS without verification, defaults to "on" (verify)
  1379  queue_dir        (path)      staging dir for undelivered messages e.g. '/home/events'
  1380  queue_limit      (number)    maximum limit for undelivered messages, defaults to '100000'
  1381  comment          (sentence)  optionally add a comment to this setting
  1382  ```
  1383  
  1384  or environment variables
  1385  
  1386  ```
  1387  KEY:
  1388  notify_nsq[:name]  publish bucket notifications to NSQ endpoints
  1389  
  1390  ARGS:
  1391  MINIO_NOTIFY_NSQ_ENABLE*          (on|off)    enable notify_nsq target, default is 'off'
  1392  MINIO_NOTIFY_NSQ_NSQD_ADDRESS*    (address)   NSQ server address e.g. '127.0.0.1:4150'
  1393  MINIO_NOTIFY_NSQ_TOPIC*           (string)    NSQ topic
  1394  MINIO_NOTIFY_NSQ_TLS              (on|off)    set to 'on' to enable TLS
  1395  MINIO_NOTIFY_NSQ_TLS_SKIP_VERIFY  (on|off)    trust server TLS without verification, defaults to "on" (verify)
  1396  MINIO_NOTIFY_NSQ_QUEUE_DIR        (path)      staging dir for undelivered messages e.g. '/home/events'
  1397  MINIO_NOTIFY_NSQ_QUEUE_LIMIT      (number)    maximum limit for undelivered messages, defaults to '100000'
  1398  MINIO_NOTIFY_NSQ_COMMENT          (sentence)  optionally add a comment to this setting
  1399  ```
  1400  
  1401  ```sh
  1402  $ mc admin config get myminio/ notify_nsq
  1403  notify_nsq:1 nsqd_address="" queue_dir="" queue_limit="0"  tls="off" tls_skip_verify="off" topic=""
  1404  ```
  1405  
  1406  Use `mc admin config set` command to update the configuration for the deployment. Restart the MinIO server to put the changes into effect. The server will print a line like `SQS ARNs: arn:minio:sqs::1:nsq` at start-up if there were no errors.
  1407  
  1408  ```sh
  1409  mc admin config set myminio notify_nsq:1 nsqd_address="127.0.0.1:4150" queue_dir="" queue_limit="0" tls="off" tls_skip_verify="on" topic="minio"
  1410  ```
  1411  
  1412  Note that, you can add as many NSQ daemon endpoint configurations as needed by providing an identifier (like "1" in the example above) for the NSQ instance and an object of per-server configuration parameters.
  1413  
  1414  ### Step 2: Enable NSQ bucket notification using MinIO client
  1415  
  1416  We will enable bucket event notification to trigger whenever a JPEG image is uploaded or deleted `images` bucket on `myminio` server. Here ARN value is `arn:minio:sqs::1:nsq`.
  1417  
  1418  ```
  1419  mc mb myminio/images
  1420  mc event add  myminio/images arn:minio:sqs::1:nsq --suffix .jpg
  1421  mc event list myminio/images
  1422  arn:minio:sqs::1:nsq s3:ObjectCreated:*,s3:ObjectRemoved:* Filter: suffix=”.jpg”
  1423  ```
  1424  
  1425  ### Step 3: Test on NSQ
  1426  
  1427  The simplest test is to download `nsq_tail` from [nsq github](https://github.com/nsqio/nsq/releases)
  1428  
  1429  ```
  1430  ./nsq_tail -nsqd-tcp-address 127.0.0.1:4150 -topic minio
  1431  ```
  1432  
  1433  Open another terminal and upload a JPEG image into `images` bucket.
  1434  
  1435  ```
  1436  mc cp gopher.jpg myminio/images
  1437  ```
  1438  
  1439  You should receive the following event notification via NSQ once the upload completes.
  1440  
  1441  ```
  1442  {"EventName":"s3:ObjectCreated:Put","Key":"images/gopher.jpg","Records":[{"eventVersion":"2.0","eventSource":"minio:s3","awsRegion":"","eventTime":"2018-10-31T09:31:11Z","eventName":"s3:ObjectCreated:Put","userIdentity":{"principalId":"21EJ9HYV110O8NVX2VMS"},"requestParameters":{"sourceIPAddress":"10.1.1.1"},"responseElements":{"x-amz-request-id":"1562A792DAA53426","x-minio-origin-endpoint":"http://10.0.3.1:9000"},"s3":{"s3SchemaVersion":"1.0","configurationId":"Config","bucket":{"name":"images","ownerIdentity":{"principalId":"21EJ9HYV110O8NVX2VMS"},"arn":"arn:aws:s3:::images"},"object":{"key":"gopher.jpg","size":162023,"eTag":"5337769ffa594e742408ad3f30713cd7","contentType":"image/jpeg","userMetadata":{"content-type":"image/jpeg"},"versionId":"1","sequencer":"1562A792DAA53426"}},"source":{"host":"","port":"","userAgent":"MinIO (linux; amd64) minio-go/v6.0.8 mc/DEVELOPMENT.GOGET"}}]}
  1443  ```