Connect Self-Managed MQTT Proxy to Confluent Cloud

The Confluent Platform MQTT Proxy component enables MQTT clients to use the MQTT 3.1.1 protocol to publish data directly to Apache Kafka®. You can configure the Confluent MQTT Proxy to produce to a topic in a Kafka cluster in Confluent Cloud.

The following steps walk you through configuring the MQTT Proxy with Confluent Cloud.


Set up the cluster

In the following steps, you install the Confluent CLI and use it to sign in to Confluent Cloud, get the cluster endpoint, and create a topic and an API key that you will use to configure the MQTT proxy.

  1. Install Confluent CLI as described in the Confluent CLI installation guide. For a list of all of the Confluent CLI commands, see Confluent CLI Command Reference.

  2. Sign in to your Confluent Cloud cluster.

    confluent login

    Your output should resemble:

    Enter your Confluent credentials:
    Password: ***********************
    Logged in as ""
    Using environment "t118" ("default")
  3. Run the confluent kafka cluster list command to get the Kafka cluster ID.

    confluent kafka cluster list

    Your output should resemble:

         Id      |        Name         |   Type    | Provider |  Region  | Availability | Status
      lkc-m1234  | Dev                 | BASIC     | gcp      | us-west4 | single-zone  | UP
      lkc-r1234  | Test                | BASIC     | gcp      | us-east4 | single-zone  | UP
      lkc-g1234  | Prod                | DEDICATED | gcp      | us-west4 | single-zone  | UP
  4. Set the active Kafka cluster. In this example, the cluster ID is lkc-m1234.

    confluent kafka cluster use lkc-m1234
  5. Run the confluent kafka cluster describe command to get the endpoint for your Confluent Cloud cluster.

    confluent kafka cluster describe

    Your output should resemble:

     | Id           | lkc-m1234                                              |
     | Name         | mqtt-proxy-quickstart                                  |
     | Type         | BASIC                                                  |
     | Ingress      |                                                    100 |
     | Egress       |                                                    100 |
     | Storage      |                                                   5000 |
     | Provider     | gcp                                                    |
     | Availability | single-zone                                            |
     | Region       | us-west2                                               |
     | Status       | UP                                                     |
     | Endpoint     | SASL_SSL:// |
     | ApiEndpoint  |        |

    Save the Endpoint value, which you’ll use to configure the bootstrap server for the MQTT Proxy.

  6. Create a Kafka topic that the MQTT proxy will produce to. Use the Confluent CLI to create a topic named “temperature”.

    confluent kafka topic create temperature
  1. Create a Kafka API key and secret that the MQTT proxy can use to access Confluent Cloud. You must specify the cluster with the resource flag for this step.

    confluent api-key create --resource lkc-m1234

    Your output should resemble:

    It may take a couple of minutes for the API key to be ready.
    Save the API key and secret. The secret is not retrievable later.
    | API Key | ABCXQHYDZXMMUDEF                                                 |
    | Secret  | aBCde3s54+4Xv36YKPLDKy2aklGr6x/ShUrEX5D1Te4AzRlphFlr6eghmPX81HTF |


    Save the API key and secret. You need this information to configure your applications that communicate with Confluent Cloud. This is the only time that you can access, view, and save the key and secret.

Configure and start the MQTT Proxy

You can either configure and start the MQTT proxy by downloading Confluent Platform locally, or using a Docker container.

  1. Install Confluent Platform.

  2. Customize the /etc/confluent-kafka-mqtt/ properties file, specifying:

    • The Confluent Cloud Endpoint that you saved earlier for the bootstrap server.
    • Security information including the Confluent Cloud API key and secret you created in the previous section.
    • Topic information.
    # add bootstrap server
    #configure connection to Confluent Cloud
    producer.sasl.mechanism=PLAIN required username="<api-key>" password="<secret>";
    # configure topic settings
  3. Start the MQTT proxy, specifying the properties file:

    bin/kafka-mqtt-start etc/confluent-kafka-mqtt/

Send messages with the MQTT client

You can now send messages to the MQTT proxy using your client.

  • Use the previously configured MQTT client to publish messages to the MQTT proxy.

    mosquitto_pub -h -p 1883 -t car/engine/temperature -q 2 -m "190F"
    mosquitto_pub -h -p 1883 -t car/engine/temperature -q 2 -m "200F"
    mosquitto_pub -h -p 1883 -t car/engine/temperature -q 2 -m "210F"

View MQTT messages in Confluent Cloud

Sign in to the Cloud Console, and access the temperatures topic to see the MQTT messages.

Click the Messages tab, and you should see the messages sent from your client to the MQTT Proxy and then to Confluent Cloud.