EventLoopGroup loop = new NioEventLoopGroup();
MqttClient mqttClient = new MqttClientImpl(((topic, payload) -> {
System.out.println(topic + "=>" + payload.toString(StandardCharsets.UTF_8));
}));
mqttClient.setEventLoop(loop);
mqttClient.getClientConfig().setClientId("{clientId}");
mqttClient.getClientConfig().setUsername("{username}");
mqttClient.getClientConfig().setPassword("{password}");
mqttClient.getClientConfig().setProtocolVersion(MqttVersion.MQTT_3_1_1);
mqttClient.getClientConfig().setReconnect(true);
mqttClient.setCallback(new MqttClientCallback() {
@Override
public void connectionLost(Throwable cause) {
cause.printStackTrace();
}
@Override
public void onSuccessfulReconnect() {
}
});
MqttConnectResult result = mqttClient.connect("127.0.0.1", 1883).await().get();
if (result.getReturnCode() != MqttConnectReturnCode.CONNECTION_ACCEPTED) {
System.out.println("error:" + result.getReturnCode());
mqttClient.disconnect();
} else {
System.out.println("success");
// mqttClient.publish("test", Unpooled.copiedBuffer("{\"type\":\"event\"}", StandardCharsets.UTF_8));
}
This repository has been archived by the owner on Jan 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 43
jetlinks/netty-mqtt-client
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
No description or website provided.
Topics
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published