-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
1,381 additions
and
1,478 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,121 +18,15 @@ Create these files, `zilla.yaml` and `docker-compose.yaml`, in the same director | |
|
||
@tab zilla.yaml | ||
|
||
|
||
```yaml {11,26-28,41-42} | ||
name: MQTT-intro | ||
bindings: | ||
|
||
# Gateway ingress config | ||
tcp_server: | ||
type: tcp | ||
kind: server | ||
options: | ||
host: 0.0.0.0 | ||
port: | ||
- 1883 | ||
exit: mqtt_server | ||
|
||
# MQTT Broker With an exit to Kafka | ||
mqtt_server: | ||
type: mqtt | ||
kind: server | ||
exit: mqtt_kafka_proxy | ||
|
||
# Proxy MQTT messages to Kafka | ||
mqtt_kafka_proxy: | ||
type: mqtt-kafka | ||
kind: proxy | ||
options: | ||
topics: | ||
sessions: mqtt-sessions | ||
messages: mqtt-messages | ||
retained: mqtt-retained | ||
exit: kafka_cache_client | ||
|
||
# Kafka caching layer | ||
kafka_cache_client: | ||
type: kafka | ||
kind: cache_client | ||
exit: kafka_cache_server | ||
kafka_cache_server: | ||
type: kafka | ||
kind: cache_server | ||
options: | ||
bootstrap: | ||
- mqtt-sessions | ||
- mqtt-retained | ||
exit: kafka_client | ||
|
||
# Connect to local Kafka | ||
kafka_client: | ||
type: kafka | ||
kind: client | ||
exit: kafka_tcp_client | ||
kafka_tcp_client: | ||
type: tcp | ||
kind: client | ||
options: | ||
host: kafka | ||
port: 29092 | ||
routes: | ||
- when: | ||
- cidr: 0.0.0.0/0 | ||
<!-- @include: ./zilla.yaml --> | ||
``` | ||
@tab docker-compose.yaml | ||
```yaml {9,40-42} | ||
version: '3' | ||
services: | ||
|
||
zilla: | ||
image: ghcr.io/aklivity/zilla:latest | ||
depends_on: | ||
- kafka | ||
ports: | ||
- 1883:1883 | ||
volumes: | ||
- ./zilla.yaml:/etc/zilla/zilla.yaml | ||
command: start -v -e | ||
|
||
kafka: | ||
image: docker.io/bitnami/kafka:latest | ||
container_name: kafka | ||
ports: | ||
- 9092:9092 | ||
- 29092:9092 | ||
environment: | ||
ALLOW_PLAINTEXT_LISTENER: "yes" | ||
KAFKA_CFG_NODE_ID: "1" | ||
KAFKA_CFG_BROKER_ID: "1" | ||
KAFKA_CFG_CONTROLLER_QUORUM_VOTERS: "[email protected]:9093" | ||
KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP: "CLIENT:PLAINTEXT,INTERNAL:PLAINTEXT,CONTROLLER:PLAINTEXT" | ||
KAFKA_CFG_CONTROLLER_LISTENER_NAMES: "CONTROLLER" | ||
KAFKA_CFG_LOG_DIRS: "/tmp/logs" | ||
KAFKA_CFG_PROCESS_ROLES: "broker,controller" | ||
KAFKA_CFG_LISTENERS: "CLIENT://:9092,INTERNAL://:29092,CONTROLLER://:9093" | ||
KAFKA_CFG_INTER_BROKER_LISTENER_NAME: "INTERNAL" | ||
KAFKA_CFG_ADVERTISED_LISTENERS: "CLIENT://localhost:9092,INTERNAL://kafka:29092" | ||
KAFKA_CFG_AUTO_CREATE_TOPICS_ENABLE: "true" | ||
|
||
kafka-init: | ||
image: docker.io/bitnami/kafka:3.2 | ||
command: | ||
- "/bin/bash" | ||
- "-c" | ||
- | | ||
/opt/bitnami/kafka/bin/kafka-topics.sh --bootstrap-server kafka:29092 --create --if-not-exists --topic mqtt-messages | ||
/opt/bitnami/kafka/bin/kafka-topics.sh --bootstrap-server kafka:29092 --create --if-not-exists --topic mqtt-sessions --config cleanup.policy=compact | ||
/opt/bitnami/kafka/bin/kafka-topics.sh --bootstrap-server kafka:29092 --create --if-not-exists --topic mqtt-retained --config cleanup.policy=compact | ||
depends_on: | ||
- kafka | ||
init: true | ||
|
||
|
||
networks: | ||
default: | ||
name: zilla-network | ||
driver: bridge | ||
```yaml {10,41-43} | ||
<!-- @include: ./docker-compose.yaml --> | ||
``` | ||
::: | ||
|
@@ -143,25 +37,33 @@ networks: | |
docker-compose up -d | ||
``` | ||
|
||
### Use [mosquitto_pub](https://mosquitto.org/download/) to send a greeting | ||
### Send a greeting | ||
|
||
Subscribe to the `zilla` topic | ||
Using [eclipse-mosquitto](https://hub.docker.com/_/eclipse-mosquitto) subscribe to the `zilla` topic. | ||
|
||
```bash:no-line-numbers | ||
mosquitto_sub -V 'mqttv5' --topic 'zilla' --debug | ||
docker run -it --rm eclipse-mosquitto \ | ||
mosquitto_sub -V 'mqttv5' --topic 'zilla' \ | ||
--host 'host.docker.internal' --port 7183 --debug | ||
``` | ||
|
||
In a separate session publish a message on the `zilla` topic | ||
In a separate session, publish a message on the `zilla` topic. | ||
|
||
```bash:no-line-numbers | ||
mosquitto_pub -V 'mqttv5' --topic 'zilla' --message 'Hello, world' --debug --insecure | ||
docker run -it --rm eclipse-mosquitto \ | ||
mosquitto_pub -V 'mqttv5' --topic 'zilla' --message 'Hello, world' \ | ||
--host 'host.docker.internal' --port 7183 --debug --insecure | ||
``` | ||
|
||
Your subscribed session should receive the message | ||
Send messages with the retained flag. | ||
|
||
::: note Wait for the services to start | ||
if you are stuck on `Client null sending CONNECT`, the likely cause is Zilla and Kafka are still starting up. | ||
::: | ||
```bash:no-line-numbers | ||
docker run -it --rm eclipse-mosquitto \ | ||
mosquitto_pub -V 'mqttv5' --topic 'zilla' --message 'Hello, retained' --retain \ | ||
--host 'host.docker.internal' --port 7183 --debug --insecure | ||
``` | ||
|
||
Then restart the `mosquitto_sub` above. The latest retained message is delivered, and the other messages are not. | ||
|
||
### Remove the running containers | ||
|
||
|
@@ -170,12 +72,11 @@ docker-compose down | |
``` | ||
|
||
::: tip See more of what Zilla can do | ||
Go deeper into this concept with the [mqtt.kafka.broker](https://github.com/aklivity/zilla-examples/tree/main/mqtt.kafka.broker) example. | ||
Go deeper into this concept with the [Running an MQTT Kafka broker](../../how-tos/mqtt/mqtt.kafka.broker.md) example. | ||
::: | ||
|
||
## Going Deeper | ||
|
||
Try out more MQTT examples: | ||
|
||
- [mqtt.kafka.broker](https://github.com/aklivity/zilla-examples/tree/main/mqtt.kafka.broker) | ||
- [mqtt.kafka.broker.jwt](https://github.com/aklivity/zilla-examples/tree/main/mqtt.kafka.broker.jwt) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.