In this guide I’m going to walk you through deploying a powerful open-source MQTT broker called EMQX. I’ll also show you how to connect the MQTTX test client to the EMQX broker.
EMQX is the most feature rich, secure, and reliable MQTT broker available as both an open-source project and as a managed cloud service.
If you’re unfamiliar, MQTT stands for Message Queuing Telemetry Transport. It’s a robust messaging protocol with a publish and subscriber model - using topics to define where messages are coming from or going to.
You can use MQTT to make devices like Arduino compatible dev boards talk to each-other or applications in various languages.
The EMQX open-source MQTT broker is light weight and can be run on most platforms.
Running EMQX Locally and Creating a Client UserEMQX can be installed on a local machine or cloud instance in a number of ways. The easiest is to follow the instructions for your operating system here https://www.emqx.io/downloads
Accessing the EMQX DashboardEMQX serves a dashboard and management portal over the web. It can be accessed by navigating to localhost:18083
from a browser.
The default username/password is admin/public
Before any client can connect to the newly deployed EMQX MQTT Broker, an authenticator needs to be created. Password-Based Authentication using the Built-in Database can quickly be created using the management portal.
- From the dashboard navigate to the Authentication page.
- Click on + Create.
- Select Password-Based and click Next.
- Select Built-in Database and click Next.
- Leave all the default settings and click Create.
Now that we've created a Password-Based authenticator using the Built-in database, we need to add users to the database.
- From the Authentication page, under the Actions column for the Password-based authenticator, click Users.
- Click the plus icon to create a new user with a username/password.
Repeat this process as necessary to create users for clients to connect as.
Connecting a Client to EMQX using MQTTXMQTTX is a free tool that helps you test client connections to an MQTT broker. It also lets you publish and subscribe to topics. We'll use it to connect to the EMQX broker using the credentials created in the last step.
- Download, install, and open the MQTTX application.
- Click on the plus icon to create a New Connection.
- Name your connection, supply the username/password, and set the host to match the IP address or hostname of the machine hosting EMQX.
- Click Connect.
Topics are named routes for knowing where a message is going to or coming from. They use a slash notation. For example, sensors/temp or sensors/humidity.
To publish messages to a topic, connect a device, construct a payload in the visible text box, and use the send button to publish it. The following image shows how to send a simple JSON message to testtopic/1.
To subscribe to a message, click on New subscription and supply the topic you'd like to subscribe to. Any message published to that topic will appear in the window for that connection. Try this out by creating a new user, a new connection, and subscribe to a topic that the other connection is publishing to.
You can also subscribe to all sub-topics under a topic using the # pound sign. For example, the topic sensors/# would yield any message published under the sensors/ topic.
Viewing Topic Metrics in the EMQX DashboardClick the Magnifying Lens icon to open the Topic Metrics page. Here you can add Topics to monitor. Any subsequent messages to that topic will be tracked here and you can get an idea of how many messages are going through.
Now that you've learned how to connect a test client from MQTTX, you'll want to connect your applications or devices to the broker.
We've published a series of blogs on how to connect using a variety of languages. MQTT is also a long-standing protocol in the IoT industry and there are numerous libraries for embedded devices, such as Arduino, available.
We have an amazing community of open-source contributors and users of the EMQX project and cloud service. Join in on the discussions, share your projects, or feel free to ask any questions! We'd love to hear from you!
Comments
Please log in or sign up to comment.