Java实现的小巧稳定快速的Mqtt-Client工具

Owen Jia 2019年05月21日 767次浏览

shap-mqtt

基于java实现的一个mqtt客户端连接工具包:shap-mqtt

这是我第一款发布的开源工具

使用样例

订阅,需要继承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);
    }
}

发布Maven Nexus仓库

在项目pom.xml文件中可直接引入

groupId: com.github.owen-jia
artifactId: shap-mqtt
version: 0.0.1

差不多花了2小时,看了网上一篇博客创建nexus帐号配置maven pom再deploy成功。

首先Maven配置

这两篇文章很靠谱,按流程走一次性就成功了;

issues.sonatype.org 创建新project task

task

官方办事效率真是让人钦佩不已,1小时内搞定审核。

deploy

Maven中央仓库的更新速度也是令人佩服,才上传完立马就能在项目中引入使用。

友链

作者:Owen Jia

推荐关注他的博客:Owen Blog

公众号: 冬天就要吃胖点

冬天就要吃胖点