Skip to main content

MQTT Intro


MQTT Intro

Get started with Zilla by deploying our Docker Compose stack. Before proceeding, you should have Docker Composeopen in new window installed.

MQTT Broker onto Kafka event streams

Running this Zilla sample will create a simple API to create and list items. All of the data will be stored on a Kafka topic.

Setup

Create these files, zilla.yaml and docker-compose.yaml, in the same directory.

zilla.yaml
name: MQTT-intro
bindings:

# Proxy service entrypoint
  north_tcp_server:
    type: tcp
    kind: server
    options:
      host: 0.0.0.0
      port: 7183
    exit: north_mqtt_server

# MQTT Broker With an exit to Kafka
  north_mqtt_server:
    type: mqtt
    kind: server
    exit: north_mqtt_kafka_mapping

# Proxy MQTT messages to Kafka
  north_mqtt_kafka_mapping:
    type: mqtt-kafka
    kind: proxy
    options:
      topics:
        sessions: mqtt-sessions
        messages: mqtt-messages
        retained: mqtt-retained
    exit: north_kafka_cache_client

# Kafka sync layer
  north_kafka_cache_client:
    type: kafka
    kind: cache_client
    exit: south_kafka_cache_server
  south_kafka_cache_server:
    type: kafka
    kind: cache_server
    options:
      bootstrap:
        - mqtt-sessions
        - mqtt-retained
    exit: south_kafka_client

# Connect to local Kafka
  south_kafka_client:
    type: kafka
    kind: client
    exit: south_kafka_tcp_client
  south_kafka_tcp_client:
    type: tcp
    kind: client
    options:
      host: ${{env.KAFKA_HOST}}
      port: ${{env.KAFKA_PORT}}
    routes:
      - when:
          - cidr: 0.0.0.0/0










 














 
 
 












 
 

















Run Zilla and Kafka

docker-compose up -d

Send a greeting

Using eclipse-mosquittoopen in new window subscribe to the zilla topic.

docker run -it --rm eclipse-mosquitto \
mosquitto_sub --url mqtt://host.docker.internal:7183/zilla

In a separate session, publish a message on the zilla topic.

docker run -it --rm eclipse-mosquitto \
mosquitto_pub --url mqtt://host.docker.internal:7183/zilla --message 'Hello, world'

Send messages with the retained flag.

docker run -it --rm eclipse-mosquitto \
mosquitto_pub --url mqtt://host.docker.internal:7183/zilla --message 'Hello, retained' --retain

Then restart the mosquitto_sub above. The latest retained message is delivered, and the other messages are not.

Remove the running containers

docker-compose down

See more of what Zilla can do

Go deeper into this concept with the Running an MQTT Kafka broker example.

Going Deeper

Try out more MQTT examples: