Skip to content

Quick Start: Publish with MQTT, Consume with Kafka

In this quick start, you'll publish device telemetry using MQTT, persist it in a FlowMQ stream, and consume it using a standard Kafka client.

Prerequisites

1. Create a Project

Sign up for FlowMQ with your email, GitHub, or Google account. After signing in:

  1. Click Create your first project on the dashboard.
  2. Enter a project name, such as my-iot-pipeline.
  3. Choose your preferred cloud platform and region.
  4. Click Create.

Provisioning takes a few seconds. When the project is ready, its MQTT and Kafka connection details appear on the Overview page.

2. Create Authentication Credentials

  1. In the project dashboard, go to Authentication.
  2. Click Add Credential.
  3. Enter a username and password.
  4. Click Create Credential.

IMPORTANT

Save the password when it is displayed. It cannot be viewed again.

FlowMQ requires TLS and authentication for both MQTT and Kafka connections. The examples below use the same credential for both protocols.

3. Create a Stream

Create the stream before publishing so that it can persist every matching message:

  1. In the project dashboard, go to Streams.
  2. Click Create Stream.
  3. Enter sensor-data for Stream Name.
  4. Enter sensors/# for Topic Filters.
  5. Click Create Stream.

The sensors/# filter routes every message whose topic starts with sensors/ into the stream. Kafka clients see the stream as a Kafka topic named sensor-data.

4. Publish a Message with MQTT

Get the MQTT hostname from the project's Overview page, then replace the hostname and credentials in this command:

bash
mqttx pub \
  --hostname your-project-id.flowmq.cloud \
  --port 8883 \
  --protocol mqtts \
  --topic sensors/device-1/temperature \
  --username your-username \
  --password your-password \
  --message '{"device_id":"device-1","value":25.6,"unit":"celsius"}'

The MQTT topic sensors/device-1/temperature matches the stream filter sensors/#, so FlowMQ appends the message to sensor-data.

5. Configure the Kafka Client

Create a client.properties file with the credential from step 2:

properties
security.protocol=SASL_SSL
sasl.mechanism=PLAIN
sasl.jaas.config=org.apache.kafka.common.security.plain.PlainLoginModule required username="your-username" password="your-password";

6. Consume the Message with Kafka

Get the Kafka bootstrap server from the project's Overview page, then consume the sensor-data stream:

bash
kafka-console-consumer.sh \
  --bootstrap-server your-project-id.flowmq.cloud:9093 \
  --topic sensor-data \
  --from-beginning \
  --consumer.config client.properties

The consumer prints the payload published by MQTT:

json
{"device_id":"device-1","value":25.6,"unit":"celsius"}

You have now sent a message with MQTT and consumed the same message with Kafka, without deploying a separate broker or protocol bridge.

Next Steps