Skip to content

Guide to Publishing Messages on Coreflux Broker with Mosquitto Client

This guide covers how to publish messages to a Coreflux broker using the Mosquitto MQTT client. We'll explore two methods: securely with SSL/TLS certificates and an insecure method without certificate verification.

Prerequisites

  • Ubuntu or similar Linux distribution
  • Mosquitto client installed
  • Coreflux broker credentials (username and password)
  • (For secure connection) SSL/TLS certificates: CA certificate, client certificate, and client key

Installation of Mosquitto Client

Before proceeding, ensure you have Mosquitto client installed on your system:

sudo apt-get update
sudo apt-get install mosquitto mosquitto-clients

Secure Connection Using SSL/TLS Certificates

1. Prepare Your Certificates

Ensure you have the CA certificate (ca.crt), client certificate (client.crt), and client key (client.key) ready and accessible on your system. For our cloud broker, please contact us through email, the support form, or join our Discord channel and request a support ticket to receive access to your server certificate.

2. Publish a Message with Certificates

Use the following command to publish a message securely:

mosquitto_pub -h [Broker Address] -p 8883 -t [Topic] -m "[Message]" -u [Username] -P [Password] --cafile /path/to/ca.crt --cert /path/to/client.crt --key /path/to/client.key

Replace placeholders with your actual data: - [Broker Address]: Your Coreflux broker address - [Topic]: The MQTT topic to publish to - [Message]: Your message - /path/to/ca.crt: Path to your CA certificate - /path/to/client.crt: Path to your client certificate - /path/to/client.key: Path to your client key

3. Example Command

mosquitto_pub -h broker-projectKey.brokerUUID.region.coreflux.cloud -p 8883 -t "secure/topic" -m "Hello, securely!" -u admin -P 'thepassword' --cafile /etc/mosquitto/certs/ca.crt --cert /etc/mosquitto/certs/client.crt --key /etc/mosquitto/certs/client.key

Insecure Connection Without Certificate Verification (just for testing!)

We recommend using this method to test TLS connectivity only. By bypassing the validation, you are ensuring that your connectivity is fine and that you have the correct address and credentials. This method only leaves certificate validation out of the picture. While it's a good method for testing connectivity, it should not be used in production.

1. Bypass SSL Certificate Verification

For testing or development in a trusted network, you can bypass the SSL certificate verification:

mosquitto_pub -h [Broker Address] -p 8883 -t [Topic] -m "[Message]" -u [Username] -P [Password] --insecure

Replace placeholders with your actual data, and use the --insecure flag to bypass certificate verification.

2. Example Command

mosquitto_pub -h broker-projectKey.brokerUUID.region.coreflux.cloud -p 8883 -t "test/topic" -m "Hello, insecurely!" -u admin -P 'thepassword' --insecure

Conclusion

This guide has provided instructions for publishing messages to a Coreflux broker using the Mosquitto client, both securely with SSL/TLS certificates and insecurely without certificate verification. Ensure to use the secure method for production environments to protect your data and communications.