mqtt-spring-boot-starter will help you use mqtt with Spring Boot.
<dependency>
<groupId>io.github.brandonbai</groupId>
<artifactId>mqtt-spring-boot-starter</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
{your applicaton.yml/applicaton.properties}
mqtt:
username: mqttPubClient
password: 123456
cleanSession: false
serverURIs:
- tcp://localhost:1883
async: true
completionTimeout: 20000
keepAliveInterval: 30
clientId: mqttPubClient
defaultQos: 1
public class YourClass {
@Resource
private MqttMessageClient mqttMessageClient;
public void yourMethod() {
mqttMessageClient.sendMessage("topic", "content");
}
}