Be A Dusun Distributor >>

MQTT Configuration & Setup on Dusun’s Gateway

Table of Contents

MQTT Configuration & Setup on Dusun's Gateway

Dusun smart gateways are Linux based and programmable. Then Dusun’s gateway can use any standard protocols to transfer data into Cloud.

1. Deploy your ActiveMQ Server

Dusun IoT Gatwey Impliment MQTT 3.1

1) Requirements Hardware:

~ 60 MB of free disk space for the ActiveMQ 5.x binary distribution.

(you need additional disk space for storing persistent messages to disk)

~ 300 MB of free disk space for the ActiveMQ 5.x source or developer’s distributions.

2) Environment:

Java Runtime Environment (JRE) JRE 1.7+ (1.6 for version <=5.10.0)

(a JDK is required if you plan to recompile source code)

The JAVA_HOME environment variable must be set to the directory where the JRE is installed

(Unix: the binary “java” has to be resolvable by the PATH variable; execute “which java” to verify)

3) Installation:

download-page :

Select the package corresponding your platfrom

unzip : tar zxvf activemq-xx-bin.tar.gz on your server directory;

Enabling the ActiveMQ Broker for MQTT
 vim [activemq_install_dir]/conf/activemq.xml
    in server section  add


Starting ActiveMQ
 cd [activemq_install_dir]/bin

   ./activemq console         //foregroud

   ./activemq  start         // daemon     
DM 20220706101551 001

2. Testing the Installation

1) Using the administrative interface:

use default settings

2) Open the administrative interface

URL: http://${your_activemq_server_ip}:8161/admin/

Login: admin

Passwort: admin

also you can edit ${ACTIVEMQ_HOME}/conf/jetty.xml to specify your password and account what you want.

DM 20220706101551 002

The topic name: according to your Dusun gateway device mac format: t/${mac};

​Now gateway connected to the mqtt server , We can control the device by producing message, to the topic ,and collect data by consuming the messages from the topic.

3. Programming with Java (spring boot)

1) You'll need

JDK 1.8 or later

Gradle 4+ or Maven 3.2+

You can also import the code straight into your IDE: Spring Tool Suite (STS) IntelliJ IDE

2) Create the directory structure

In a project directory of your choosing, create the following subdirectory structure;

for example, with mkdir -p src/main/java/hello on *nix systems:

					└── src
     └── main
         └── java
             └── mqttproject
3) Build with maven











4. Configuring ActiveMQ in Spring Boot

Following is the which has configurations for ActiveMQ. Here we are configuring the tcp broker url along with the username and password required to make ActiveMQ connection.


public class Listener {
@JmsListener(destination = "t")// dusun Gateway uplink topic name
public String receiveMessage(final Message jsonMessage) throws JMSException {
String messageData = null;
System.out.println("Received message " + jsonMessage);
String response = null;
if(jsonMessage instanceof TextMessage) {
TextMessage textMessage = (TextMessage)jsonMessage;
messageData = textMessage.getText();
Map map = new Gson().fromJson(message, Map.class);
response  = "Hello " + map.get("name");
return response;
1) JMS Producer

Spring boot provides a very convenient way to send message to a destined queue.Since the introduction of @SendTo annotation, it only requires the queue name in the parameter to send messages.Annotating any method with @SendTo annotation ensures the returning object of the method will be pushed to the queue.

2) Working with JMS Topic

Spring boot provides above-discussed default behaviors to work with the messaging queue. But to deal with the topic in Spring JMS, we require to manually tell spring to enable it. For this, we only require to set the boolean flag i.e. pubSubDomain to true. To do this, we require our and set pubSubDomain to true for the bean definition of JmsTemplate and DefaultJmsListenerContainerFactory. Following are the changes we require to do.



Once this is done, the rest of the configuration remains the same and in place of listening from a queue, our application can start listening from the topic and publish a message to a topic. Following are the lines I have added to consume message from a topic in

@JmsListener(destination = "t")
public String receiveMessageFromTopic(final Message jsonMessage) throws JMSException {
String messageData = null;
System.out.println("Received message " + jsonMessage);
String ctrlMsg = parse(messageData);// todo your logic
return ctrlMsg;  // the json Msg  will send to dusun GateWay
package com.devglan.tiles;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.jms.annotation.EnableJms;
public class Application {
    public static void main(String[] args) {, args);


you can run the application using ./mvnw spring-boot: run. Or you can build the JAR file with ./mvnw clean package.

Then you can run the JAR file: java -jar build/libs/mqttproject.jar

Thank for your reading!

Download to learn more

Looking For An IoT Device Supplier For Your Projects?


    This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


      This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

      Welcome to DusunIoT

      Hi there 👋 Is there anything we can help you with today? Please fill in the form below for the team to follow up if you become disconnected.