Skip to content

Java 版的 MQTT Client,小巧、简单、高效的连接工具

Notifications You must be signed in to change notification settings

owen-jia/shap-mqtt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

50 Commits
 
 
 
 
 
 
 
 

Repository files navigation

shap-mqtt

Shap是针对Java体系研发的一款mqtt连接client,简单、小巧、稳定、低耗的开源工具。

最新版本

<!-- https://repo.maven.apache.org/maven2/com/github/owen-jia/shap-mqtt/ -->
<dependency>
    <groupId>com.github.owen-jia</groupId>
    <artifactId>shap-mqtt</artifactId>
    <version>0.0.3</version>
</dependency>

Sample

在测试模块包中有ShapTest类有详细的测试用例。

订阅,需要继承IShapListener接口

public class NcSubscribe implements IShapListener {
    @Override
    public void messageArrived(String topic, MqttMessage message) throws Exception {
        System.out.println("topic:"+topic);
        System.out.println("id:"+message.getId());
        System.out.println("qos:"+message.getQos());
        System.out.println("context:"+message.getPayload());
    }
}

发布,使用类ShapMqtt.publish(...)

class Test {
    public static void main(String[] args){
        ShapMqtt shapMqtt = new ShapMqtt("tcp://127.0.0.1:1883");
        shapMqtt.subscribe("hello/+",new NcSubscribe());
        shapMqtt.publish("hello/one",1,"hello world!".getBytes(),false);
    }
}

新需求和错误提交

非常欢迎提出新需求和BUG,请在github的Issues中提交。

About

Java 版的 MQTT Client,小巧、简单、高效的连接工具

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages