Code Monkey home page Code Monkey logo

springboot-mqtt-mapping's Introduction

mqtt-mapping

基于spring boot的mqtt例子,使用注解将不同的主题分派给不同的任务。支持+、#通配符。

1,已经定义的注解

MqttMassageController
MqttMassageMapping
OnConnectComplete
OnDisconnect
RequestMassage
RequestTopic

2,yml配置

spring:
  mqtt:
    domain: 127.0.0.1
    port: 1883
    clientId: SERVER00000001
    username: admin
    password: admin
    connectionTimeout: 10
    automaticReconnect: true
    cleanSession: true
    keepAliveInterval: 60

3,使用方法,程序里已经包含了mptt

    /**
     * @author wuxh
     * @version v1.0.0
     */
    @MqttMassageController
    //根主题
    @MqttMassageMapping("mqtt")
    public class MqttController {
    
        //注入mqtt处理类。
        @Autowired
        private MqttTemplate mqttTemplate;
    
        @OnConnectComplete
        public void onConnect() {
            mqttTemplate.subscribe("mqtt/msg", MqttConstant.MqttQos.QOS1);
    
    
            mqttTemplate.publish("mqtt/msg", MqttConstant.MqttQos.QOS1,"hello");
        }
        
        //订阅的主题,框架会自动将 mqtt/msg 派发到此函数
        @MqttMassageMapping("/msg")
        public void iotMsg(@RequestTopic String topic, @RequestMassage MqttMessage msg) {
           System.out.println(new String( msg.getPayload()));
        }

        @OnDisconnect
        public void onDisconnect() {
           //do something...
        }
    }

springboot-mqtt-mapping's People

Contributors

wuxh123 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.