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:
- Click Create your first project on the dashboard.
- Enter a project name, such as
my-iot-pipeline. - Choose your preferred cloud platform and region.
- 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
- In the project dashboard, go to Authentication.
- Click Add Credential.
- Enter a username and password.
- 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:
- In the project dashboard, go to Streams.
- Click Create Stream.
- Enter
sensor-datafor Stream Name. - Enter
sensors/#for Topic Filters. - 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:
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:
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:
kafka-console-consumer.sh \
--bootstrap-server your-project-id.flowmq.cloud:9093 \
--topic sensor-data \
--from-beginning \
--consumer.config client.propertiesThe consumer prints the payload published by MQTT:
{"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
- Learn how protocol mappings work in Cross-Protocol Messaging.
- Learn about durable streams, retention, and partitions in Streaming.
- Build an application with an MQTT SDK or Kafka SDK.