Setup Guide
This guide walks you through setting up an MQTT broker that the Ballerina MQTT connector will connect to.
Prerequisites
- An MQTT v5 compatible broker. You can use a cloud-hosted broker (e.g., HiveMQ Cloud, EMQX Cloud) or install one locally (e.g., Eclipse Mosquitto).
Install or provision an MQTT broker
Option A: Local broker (Mosquitto):
- Download and install Eclipse Mosquitto for your platform.
- Start the broker with the default configuration:
By default, the broker listens on
mosquittotcp://localhost:1883.
Option B: Cloud-hosted broker:
- Sign up for a managed MQTT service such as HiveMQ Cloud or EMQX Cloud.
- Create a new MQTT cluster/instance.
- Note the broker URL (e.g.,
ssl://your-broker.hivemq.cloud:8883).
For development and testing, a local Mosquitto broker is the quickest way to get started.
Configure authentication (if required)
If your broker requires authentication:
- Create a username and password on your broker.
- Mosquitto: Edit the
mosquitto.conffile to setallow_anonymous falseand create a password file usingmosquitto_passwd. - Cloud brokers: Use the broker's web console to create credentials.
- Mosquitto: Edit the
- Note the username and password; you will supply these in the connector's
ConnectionConfiguration.
Many local development brokers allow anonymous connections by default. For production, always enable authentication.
Configure TLS/SSL (if required)
For secure connections (recommended for production and required by most cloud brokers):
- Obtain the broker's CA certificate, or configure your own certificates.
- Cloud brokers: Download the CA certificate from the broker's dashboard.
- Mosquitto: Configure TLS by setting
cafile,certfile, andkeyfileinmosquitto.conf.
- Note the paths to your certificate and key files: you will use these in the connector's
SecureSocketconfiguration. - Ensure the broker URL uses the
ssl://scheme (e.g.,ssl://localhost:8883).
Store certificates and private keys securely. Do not commit them to source control.
Verify broker connectivity
Test that your broker is reachable:
- Use an MQTT client tool such as MQTTX or the Mosquitto CLI clients. Start the subscriber first (in one terminal):
Then, in a second terminal, publish a test message:
mosquitto_sub -h localhost -t "test/topic"mosquitto_pub -h localhost -t "test/topic" -m "hello"noteStart the subscriber before publishing. Non-retained messages are delivered only to active subscribers: if you publish first, the message will be missed.
- Confirm that the message
helloappears in the subscriber terminal.
What's next
- Action reference: Available operations
- Trigger reference: Event-driven integration