如何实现MQTT的Java代码

Spring整合mqtt原理分析 Spring整合Mqtt原理分析 阅读详情

MQTT(消息队列遥测传输)是ISO 标准(ISO/IEC PRF 20922)下基于发布/订阅]范式的消息协议。它工作在 TCP/IP协议族上,是为硬件性能低下的远程设备以及网络状况糟糕的情况下而设计的发布/订阅型消息协议,为此,它需要一个消息中间件 。

为rabbit开启mqtt

1.在yml文件中添加一个mqtt的端口映射1883:1883

<pre class="prettyprint hljs less" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 1.5em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">restart: always
container_name: rabbitmq
ports:
  - 5672:5672
  - 15672:15672
  - 1883:1883 #mqtt
volumes:
  - ./data:/var/lib/rabbitmq</pre>

2.进入rabbit的docker容器内部

<pre class="hljs nginx" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 0.75em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">docker exec -it rabbitmq bash</pre>

3.rabbit内运行

<pre class="hljs bash" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 0.75em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">rabbitmq-plugins enable rabbitmq_mqtt</pre>

4.在网页视图中查看mqtt

使用MQTT软件测试mqtt

1.连接mqtt

2.在MQTT软中添加订阅

在RabbitMQ的队列中查看

3.测试

方法一、在Rabbitmq网页发送消息

方法二、自己给自己发

一、发送消息

  1. 创建springBoot项目,在xml中导入springBoot项目所需要配置以及相关依赖包
<pre class="prettyprint hljs xml" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 1.5em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"><parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.6.8</version>
</parent>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <!--使用spring集成启动器,Spring集成提供了对消息传递和其他传输(如HTTP、TCP等)的抽象。-->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-integration</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.integration</groupId>
        <artifactId>spring-integration-mqtt</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.integration</groupId>
        <artifactId>spring-integration-stream</artifactId>
    </dependency>
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
    </dependency>
</dependencies></pre>

注意寻找依赖包:spring.io->projects->LEARN(右边)->2.6.10 GA Refence Doc.-> Documentation Overview ->7.Messaging-> Spring Integration: Auto-configuration for Spring Integration

  1. 创建配置类(2步骤可忽略,此地只为推导使用,配置类的正确使用方式见步骤6)
<pre class="prettyprint hljs java" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 1.5em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">//修正官网后的(这个配置文件还不可以使用,正确的使用方式见在后面--此地是视频课程讲的讲解中推导步骤,可以省略不看)
@Configuration
public class  MqttConfig  { 
    @Bean
    public  MessageChannel  mqttInputChannel()  { 
        return new DirectChannel();
    }

    /**
     * 连接mqtt服务器的工厂
     * @return
     */
    @Bean
    public  MqttPahoClientFactory  mqttClientFactory()  { 
        DefaultMqttPahoClientFactory factory = new DefaultMqttPahoClientFactory();
        MqttConnectOptions options = new MqttConnectOptions();
        options.setServerURIs(new String[] {
  "tcp://10.9.48.165:1883" });
        options.setUserName("guest");
        options.setPassword("guest".toCharArray());
        factory.setConnectionOptions(options);
        return factory;
    }

    @Bean
    public  MessageProducer  inbound(MessageChannel mqttInputChannel,MqttPahoClientFactory mqttClientFactory)  { 
        MqttPahoMessageDrivenChannelAdapter adapter =
                new MqttPahoMessageDrivenChannelAdapter("springclient",mqttClientFactory,
                        "zheshisha");
        adapter.setCompletionTimeout(5000);
        adapter.setConverter(new DefaultPahoMessageConverter());
        //设置一次需要应答
        adapter.setQos(1);
        //设置对外的通道
        adapter.setOutputChannel(mqttInputChannel);
        return adapter;
    }
}</pre>
<pre class="prettyprint hljs java" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 1.5em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">//官方文档
@Bean
public  MessageChannel  mqttInputChannel()  { 
    return new DirectChannel();
}

@Bean
public  MessageProducer  inbound()  { 
    MqttPahoMessageDrivenChannelAdapter adapter =
            new MqttPahoMessageDrivenChannelAdapter("tcp://localhost:1883", "testClient",
                                             "topic1", "topic2");
    adapter.setCompletionTimeout(5000);
    adapter.setConverter(new DefaultPahoMessageConverter());
    adapter.setQos(1);
    //问题所在:mqttInputChannel()这个是调用方法,而在这个方法上面加一一个注解@Bean相当于白加~~~
    adapter.setOutputChannel(mqttInputChannel());
    return adapter;
}</pre>
  1. 创建接口
<pre class="prettyprint hljs kotlin" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 1.5em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">@MessagingGateway(defaultRequestChannel =  "mqttOutboundChannel")
public interface  MyGateway  { 
    void sendToMqtt(String data);
}</pre>
  1. 启动类
<pre class="prettyprint hljs less" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 1.5em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">@SpringBootApplication
//扫描整合的注解
@IntegrationComponentScan
public class MqttStartApp { 
    public static void main(String[] args) { 
        SpringApplication.run(MqttStartApp.class, args);
    }
}</pre>
  1. 编写controller类测试
<pre class="prettyprint hljs kotlin" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 1.5em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">@RestController
public class  MqttController  { 

    private MyGateway myGateway;

    @Autowired
    public void setMyGateway(MyGateway myGateway) { 
        this.myGateway = myGateway;
    }

    @PostMapping("/msg")
    public String sendMsg(String msg){ 
        myGateway.sendToMqtt(msg);
        return "success";
    }
}</pre>
  1. 修改后的配置类
<pre class="prettyprint hljs java" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 1.5em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">@Configuration
public class  MqttConfig  { 

    /**
     * 连接mqtt服务器的工厂
     * @return
     */
    @Bean
    public  MqttPahoClientFactory  mqttClientFactory()  { 
        DefaultMqttPahoClientFactory factory = new DefaultMqttPahoClientFactory();
        MqttConnectOptions options = new MqttConnectOptions();
        options.setServerURIs(new String[] {
  "tcp://10.9.48.165:1883" });
        options.setUserName("guest");
        options.setPassword("guest".toCharArray());
        factory.setConnectionOptions(options);
        return factory;
    }

    @Bean
    public  MessageChannel  mqttOutboundChannel()  { 
        return new DirectChannel();
    }

    @Bean
    @ServiceActivator(inputChannel = "mqttOutboundChannel") //inputChannel的名字必须和上面的MessageChannel的方法名保持一致
    public  MessageHandler  mqttOutbound()  { 
        MqttPahoMessageHandler messageHandler =
                new MqttPahoMessageHandler("testClient", mqttClientFactory());
        messageHandler.setAsync(true);
        messageHandler.setDefaultTopic("zheshisha");
        return messageHandler;
    }

}</pre>

二、收消息

在配配置文件中加入

<pre class="prettyprint hljs java" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 1.5em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">/**
 * 收消息的通道,注意实际开发中和发的可能不在一起
 * @return
 */
@Bean
public  MessageChannel  mqttInputChannel()  { 
    return new DirectChannel();
}

@Bean
public  MessageProducer  inbound()  { 
    MqttPahoMessageDrivenChannelAdapter adapter =
            new MqttPahoMessageDrivenChannelAdapter("tcp://10.9.48.165:1883", "testClient",
                    "chixihua");
    adapter.setCompletionTimeout(5000);
    adapter.setConverter(new DefaultPahoMessageConverter());
    adapter.setQos(1);
    adapter.setOutputChannel(mqttInputChannel());
    return adapter;
}

/**
 * 收消息的处理器,用于如何处理消息
 * mqttInputChannel 代表的是收消息的通道对象的id
 * @return
 */
@Bean
@ServiceActivator(inputChannel = "mqttInputChannel")
public  MessageHandler  handler()  { 
    return new MessageHandler() { 

        @Override
        public  void  handleMessage(Message<?> message)  throws  MessagingException  { 
            System.out.println(message.getPayload());
        }

    };
}</pre>

三、SpringBoot整合MQTT

  1. 导入依赖包
<pre class="prettyprint hljs xml" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 1.5em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"><!--使用spring集成启动器,Spring集成提供了对消息传递和其他传输(如HTTP、TCP等)的抽象。-->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-integration</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.integration</groupId>
    <artifactId>spring-integration-mqtt</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.integration</groupId>
    <artifactId>spring-integration-stream</artifactId>
</dependency></pre>
  1. 创建配置类
<pre class="prettyprint hljs java" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 1.5em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">@Configuration
public class  MqttConfig  { 

    @Bean
    public  MqttConnectOptions  options(){ 
        MqttConnectOptions mqttConnectOptions=new MqttConnectOptions();
        mqttConnectOptions.setServerURIs(new String[] {
  "tcp://10.9.48.190:1883" });
        mqttConnectOptions.setUserName("dc3");
        mqttConnectOptions.setPassword("dc3".toCharArray());
        return mqttConnectOptions;
    }

    /**
     * 创建连接工厂
     * @param options
     * @return
     */
    @Bean
    public  MqttPahoClientFactory  mqttPahoClientFactory(MqttConnectOptions options){ 
        DefaultMqttPahoClientFactory defaultMqttPahoClientFactory=new DefaultMqttPahoClientFactory();
        defaultMqttPahoClientFactory.setConnectionOptions(options);
        return defaultMqttPahoClientFactory;
    }

    @Bean
    public  MessageChannel  messageInputChannel(){ 
        return new DirectChannel();
    }

    @Bean
    public  MessageProducer  mqttInbound(MessageChannel messageInputChannel,  MqttPahoClientFactory mqttPahoClientFactory){ 
        MqttPahoMessageDrivenChannelAdapter adapter =
                new MqttPahoMessageDrivenChannelAdapter("testClient",mqttPahoClientFactory, "chixihua");
        adapter.setCompletionTimeout(5000);
        adapter.setConverter(new DefaultPahoMessageConverter());
        adapter.setQos(1);
        adapter.setOutputChannel(messageInputChannel);
        return adapter;
    }

}</pre>
  1. 配置消息处理的类
<pre class="prettyprint hljs kotlin" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 1.5em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">@Configuration
public class  MessageReceiverHandler  { 

    /**
     * 收到设备发送来的上行数据的时候执行,具体怎么做取决于业务,比如这里面可能是设备发来的一些传感器数据,我们需要保存并发送到统计平台
     * @return
     */
    @Bean
    @ServiceActivator(inputChannel =  "messageInputChannel")
    public MessageHandler messageHandler(){ 
        return message -> { 
            //获取到消息正文
            Object payload = message.getPayload();
            System.err.println(payload);
            //处理消息
            System.err.println("等下就处理消息");
        };
    }

}</pre>
  1. 在启动类添加注解
<pre class="prettyprint hljs less" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 1.5em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">@SpringBootApplication
@IntegrationComponentScan
public class MqttStartApp { 
    public static void main(String[] args) { 
        SpringApplication.run(MqttStartApp.class, args);
    }
}</pre>
SpringBoot 整合MQTT 消息推送 springboot整合mqtt, 消息推送 阅读详情

相关推荐

SpringBoot实现MQTT消息发送和接收

SpringBoot实现MQTT消息发送和接收。

大猩猩的博客 1万+

Mqtt消息发送、主题订阅

<!-- mqtt依赖 --> <dependency> <groupId>org.springframework.integration</groupId> <artifactId>spring-integration-mqtt</artifactId> </dependency> -- application.yml配置 mqtt: client: url: tcp://123.57.

yuyanguai的博客 1506

Linux下自动化解析q7签名文件的有效期与时间戳

本文详细介绍了在Linux环境下自动化解析q7签名文件有效期与时间戳的方法。通过编写高效脚本,开发者可以批量提取签名时间信息,验证签名有效性,并集成到CI/CD流程中。文章提供了完整的脚本实现,包括错误处理、批量处理功能,并解决了常见环境问题,特别适用于国产操作系统如UOS的开发场景。

weixin_30872499的博客 522

MQTT 消息通信工具使用

MQTT 是一种基于发布/订阅模式的 轻量级物联网消息传输协议 ,可以用极少的代码和带宽为联网设备提供实时可靠的消息服务,它广泛应用于物联网、移动互联网、智能硬件、车联网、电力能源等行业。

LP学长的博客 2390

用Python玩转共现分析:从NLTK到热力图可视化(附完整代码)

本文详细介绍了如何使用Python进行文本共现分析,从NLTK基础文本处理到构建共现矩阵,并实现热力图可视化。通过完整的代码示例,帮助数据分析师和开发者掌握这一揭示词语间关联网络的实用NLP技术,快速从文本中提取语义关系和主题结构。

weixin_29313817的博客 350

基于深度学习的UWB门禁检测

针对基于UWB技术智能门禁管理系统,由于测距误差或非视距原因导致门禁产生不合理动作的现象。分析如何采用基于深度学习的方法,通过对TWR测距数据、TWR监听数据、到达角度差(PDOA)、信道脉冲响应(CIR)等数据维度进行深度学习,利用 TensorFlow建立相应的推导模型,对卡片姿态进行更加精准可靠的检测,从而更好完成闸机开合控制。

tenth_quadrant的博客 2027

MQTT的Java代码实现

MQTT基于SpringBoot框架实现

weixin_44388391的博客 9927

Autojs实战教程---番茄免费小说Apk文件和源码

邀请码:782383363 字节跳到的App,推荐给大家,还是值得用一用的。不废话直接代码。 代码是带UI的复制后可以直接使用。 "ui"; //#region UI var rootUrl = "http://114.115.220.1:91";//各位大神小弟自己的服务器别黑谢谢 var storaySign = "FanqieXiaoShuo0412326@163.com"; var woolStorage = storages.create(storaySign);//创建本地存储 var

zy0412326的专栏 2万+

mqtt server java_MQTT推送简单例子服务端java代码实现

【实例简介】IBM的MQTT给了一个PHP的服务端代码,在网上找了一个JAVA实现服务端代码的例子,调通了。如果想做这个例子需要自己用电脑建一个wifi,手机连上这个wifi,代码中要改几个个地方1 android服务里有几个MQTT_HOST是ip地址改成自己wifi的ip;2 服务端的publish方法是用来发送的,第一个参数是客户端id clientId,要改成自己在手机客户端设定的名字,前...

weixin_32060429的博客 1369

solidworks vba二次开发配合问题

solidworks vba二次开发配合问题二次开发装配的步骤 二次开发装配的步骤 solidworks可以使用宏录制配合过程从而得到配合的vba代码,步骤如下: 1.选择两个配合的面(点、线等) 2. 建立配合 例如将两个圆柱面同心(图中高亮): 配合后 我们看一下宏录制的代码: Sub main() //激活solidworks接口 Set swApp = Application.SldWorks Set Part = swApp.ActiveDoc //选择两个圆柱面,注意此处是根据坐标选择,不

Alejandro123的博客 3407

Windows10下RTABMAP+T265实现三维建图

win10+rtabmap+t265扫描地形

Suxiang1997的博客 3486

java 实现mqtt发送和接收消息 客户端代码

mqtt的特点就是可以用很少的网络和硬件资源来保证高并发量的数据传输,其传输的稳定性也可以手动设置Qos(消息质量)。 mqtt服务器多种多样,常见的有ActiveMqtt EMQ 等,不过无论是什么服务器,其底层机制都是一样的。mqtt客户端可以由java、c语言等多种预言实现,我接下来就以java来示例。 1、mqtt客户端发送消息 mqtt发送消息首先要建立与服务器连接,接下来...

goxingman的博客 6万+

MeloTTS 生成 RKNN 模型

摘要: 本方案基于RK3588平台,利用RKNN工具链实现高效语音合成(TTS)。采用MeloTTS开源模型,支持中英文混合语音生成。部署流程包括:1) 导出ONNX模型;2) 转换为RKNN格式;3) 在RK3588开发板运行。关键步骤包含环境配置(RKNN Toolkit2≥1.4.0)、模型转换(非量化处理)及音频处理实现。方案充分发挥RK3588的NPU加速能力,适用于边缘设备语音合成场景

J。 352

MQTT发布与订阅主题机制以及JAVA的代码实现

MQTT通信协议使用IDEA开发基于JAVA的发布与订阅主题功能

weixin_54825900的博客 2248

在Keil uv5里面添加STC元器件库,不影响其他元件

先到网上下载stc.CBD(宏晶网站的地址实效了)还有STC新系列单片机的头文件,宏晶的网站就有1、在Keil/C51/INC下新建目录"STC"文件夹, 把所有STC新系列单片机的头文件拷贝到"STC"目录下。2、下载的用于keil下的STC器件数据库更名为STC.CDB并拷贝到Keil/UV4目录下。3、打开Keil文件夹下的TOOLS.ini文件。4、在[UV2]下键入CDB0="UV2\S

技术联盟 1万+

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

MQTT Java代码demo,实现消息收发

需安装mosquitto客户端,并将服务启动,服务默认端口为1883 client-接收端代码 package com.liang.demo.MQTT; /** * @Author Li Yang * @Created on 2021/10/3. * mqtt-消息接受客户端 */ import java.util.concurrent.ScheduledExecutorService; import org.eclipse.paho.client.mqttv3.MqttClient;.

梅林's hat 482

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

java mqtt 断线重连,C# Mqtt 断线重连的实现代码

在通过 MqttClient 客户端连接之后,在服务端服务重启时,客户端如果没有重连机制,则无法再接收到订阅的消息。使用的 Mqtt 组件为:M2Mqtt.Net.dll一些特性发现(1)如果提供的服务端地址是不可解析的,会引发异常无法实例化 MqttClient 对象。(2)Connect 无法连接时会引发异常,IsConnected 为 false。(3)服务端断开会触发客户端的 Connec...

weixin_39629269的博客 348

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

mqttjar包_MQTT简单demo(java)

上次已经简单的谈了一些MQTT协议的一些知识,今天就来就上次的知识具体的Java实现。现在就来具体说说实现这一步吧。中间的时间也是有点久。MQTT消息的发送和订阅都是依赖MQTT服务器的,没有MQTT服务器,你的客户端是无法订阅和发送消息的。所以在最开始的时候,可以选择性的在你的电脑上面安装一个MQTT服务器。MQTT服务器有很多,大家也可以在网上去找一些安装教程,这里因为和我要讲内容关系不大,所...

weixin_39771791的博客 1814

mqtt的java代码实现_mqtt使用二(集成到java代码中)

import org.eclipse.paho.client.mqttv3.*;importorg.eclipse.paho.client.mqttv3.persist.MemoryPersistence;importorg.slf4j.Logger;importorg.slf4j.LoggerFactory;importorg.springframework.beans.factory.anno...

weixin_30744725的博客 906

mqtt java 框架_moquette-master MQTT 的java broker实现,使用了netty 和disruptor 框架 Develop 243万源代码下载- www.pudn....

文件名称: moquette-master下载 收藏√ [5 4 3 2 1]开发工具: Java文件大小: 270 KB上传时间: 2015-07-31下载次数: 0提 供 者: mfm详细说明:MQTT 的java broker实现,使用了netty 和disruptor 框架-Java broker MQTT implementation, using the netty a...

weixin_39771775的博客 242

java实现MQTT服务

/连接方法//断开连接方法//订阅主题方法//发布消息方法//关闭客户端@Service@Autowiredtry {// 连接到 MQTT 服务connect();// 获取需要订阅的主题列表System.out.println("正在获取订阅的主题...");// 订阅每个主题@Overrideif (!// 设置回调System.out.println("连接到MQTT代理.");@Override。

admin_zjy的博客 2794

MQTT简单demo(java)

  上次已经简单的谈了一些MQTT协议的一些知识,今天就来就上次的知识具体的Java实现。   现在就来具体说说实现这一步吧。中间的时间也是有点久。   MQTT消息的发送和订阅都是依赖MQTT服务器的,没有MQTT服务器,你的客户端是无法订阅和发送消息的。所以在最开始的时候,可以选择性的在你的电脑上面安装一个MQTT服务器。MQTT服务器有很多,大家也可以在网上去找一些安装教程,这里因为和我...

qq_38533859的博客 1960

Java使用MQTT协议

MQTT(Message Queuing Telemetry Transport,消息队列遥测传输协议)是一种轻量级的、基于发布/订阅模式的物联网通信协议。它构建于TCP/IP协议之上,由IBM在1999年发布。MQTT协议通过简单的发布和订阅机制,实现了消息的可靠传输和分发,是物联网领域中的重要通信协议之一。

dan_seek的博客 5498

EMQX mqtt服务器搭建+java实现客户端推送和接收代码+调试

1.mqtt服务搭建 centos7环境: https://blog.youkuaiyun.com/lxw983520/article/details/89442373 感谢大哥 2. 客户端代码实现 # ①在spring boot项目中下载好下方依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-integration</

weixin_45506408的博客 9919

java 实现mqtt发送和接收消息客户端具体用法及测试代码

注:客户端代码实现请看我的上一篇 1mqtt发送消息 发送时不用多讲,每次发送肯定需要运行一次发送消息方法 MyMqttClient mqttClient = new MyMqttClient(); @org.junit.Test public void testMqtt1() throws InterruptedException, MqttException { fin...

goxingman的博客 1万+
上一篇: Maven 入门具体教程
下一篇: Java二叉树的遍历方式有几种?
Java_ttcd
博客等级 码龄4年 198粉丝 190原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值