Netty MQTT Client


License

License

Categories

Categories

Net CLI User Interface Netty Networking
GroupId

GroupId

org.jetlinks
ArtifactId

ArtifactId

netty-mqtt-client
Last Version

Last Version

1.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

Netty MQTT Client
Netty MQTT Client
Project URL

Project URL

https://github.com/jetlinks/netty-mqtt-client
Source Code Management

Source Code Management

https://github.com/jetlinks/netty-mqtt-client

Download netty-mqtt-client

How to add to project

<!-- https://jarcasting.com/artifacts/org.jetlinks/netty-mqtt-client/ -->
<dependency>
    <groupId>org.jetlinks</groupId>
    <artifactId>netty-mqtt-client</artifactId>
    <version>1.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.jetlinks/netty-mqtt-client/
implementation 'org.jetlinks:netty-mqtt-client:1.0.0'
// https://jarcasting.com/artifacts/org.jetlinks/netty-mqtt-client/
implementation ("org.jetlinks:netty-mqtt-client:1.0.0")
'org.jetlinks:netty-mqtt-client:jar:1.0.0'
<dependency org="org.jetlinks" name="netty-mqtt-client" rev="1.0.0">
  <artifact name="netty-mqtt-client" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.jetlinks', module='netty-mqtt-client', version='1.0.0')
)
libraryDependencies += "org.jetlinks" % "netty-mqtt-client" % "1.0.0"
[org.jetlinks/netty-mqtt-client "1.0.0"]

Dependencies

compile (4)

Group / Artifact Type Version
io.netty : netty-codec-mqtt jar 4.1.32.Final
io.netty : netty-handler jar 4.1.32.Final
io.netty : netty-transport-native-epoll jar 4.1.32.Final
com.google.guava : guava jar 21.0

test (1)

Group / Artifact Type Version
junit : junit jar 4.12

Project Modules

There are no modules declared in this project.

netty-mqtt-client

Maven Central

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));
}
org.jetlinks

JetLinks IoT Platform

JetLinks 开源物联网平台社区

Versions

Version
1.0.0