.. _mqtt-sink-connector:

MQTT Sink Connector
===================

This connector connects to a MQTT broker and publishes data to the specified topics.
SSL is supported. For information on how to create SSL keys and certificates see :ref:`Security Tutorial <generating_keys_certs>`. For the relevant configuration properties, see the :ref:`MQTT sink connector configuration reference <mqtt-sink-connector-config>`.

Usage Notes
-----------
If you want to change the topic take a look at the :ref:`RegexRouter <regexrouter>` transformation which can be used to change the topic name it is sent to the MQTT Server.

This connector publishes using the |ak-tm| topic name. If you need to publish to a different topic name use a transformation to change the topic name.

Examples
--------

Property-based example
^^^^^^^^^^^^^^^^^^^^^^


This configuration is used typically along with :ref:`standalone workers <standalone-workers>`.

.. codewithvars:: bash
   :emphasize-lines: 4,5

    name=MqttSinkConnector1
    connector.class=io.confluent.connect.mqtt.MqttSinkConnector
    tasks.max=1
    topics=< Required Configuration >
    mqtt.server.uri=< Required Configuration >


REST-based example
^^^^^^^^^^^^^^^^^^

This configuration is used typically along with :ref:`distributed workers <distributed-workers>`.
Write the following json to ``connector.json``, configure all of the required values, and use the command below to
post the configuration to one the distributed connect worker(s). Check here for more information about the
|kconnect-long| :ref:`REST API <connect_userguide_rest>`

**Connect Distributed REST example:**

.. codewithvars:: json
   :emphasize-lines: 6,7

    {
      "config" : {
        "name" : "MqttSinkConnector1",
        "connector.class" : "io.confluent.connect.mqtt.MqttSinkConnector",
        "tasks.max" : "1",
        "topics" : "< Required Configuration >",
        "mqtt.server.uri" : "< Required Configuration >"
      }
    }


Use curl to post the configuration to one of the |kconnect-long| Workers. Change `http://localhost:8083/` the endpoint of
one of your |kconnect-long| worker(s).

**Create a new connector:**

.. codewithvars:: bash

    curl -s -X POST -H 'Content-Type: application/json' --data @connector.json http://localhost:8083/connectors

**Update an existing connector:**

.. codewithvars:: bash

    curl -s -X PUT -H 'Content-Type: application/json' --data @connector.json http://localhost:8083/connectors/MqttSinkConnector1/config
    

Additional Documentation
------------------------

.. toctree::
   :maxdepth: 1

   mqtt_sink_connector_config
   mqtt_sink_connector_quickstart
   ../mqtt_connector_advanced_debugging