activeMq将mqtt发布订阅转成消息队列

1、activemq.xml置文件新增如下内容

2、mqttx测试发送:

主题(配置的模糊匹配,为了并发):VirtualTopic/device/sendData/12312

3、mqtt接收的结果

4、程序处理

package comimport cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;import org.apache.activemq.ActiveMQMessageAudit;
import org.apache.activemq.command.ActiveMQBytesMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component;import javax.jms.Message;
import java.nio.charset.Charset;
import java.util.Date;@Component
public class MessageHandler {@JmsListener(destination = "deviceQueue.receiveDate", containerFactory = "queueListener", concurrency = "1-3")public void deviceMessage(ActiveMQBytesMessage message) {System.out.println(StrUtil.str(message.getContent().getData(), Charset.defaultCharset()));System.out.println("###################" + message + "###################");}
}

 控制台打印

 全量的:activemq.xml

<!--Licensed to the Apache Software Foundation (ASF) under one or morecontributor license agreements.  See the NOTICE file distributed withthis work for additional information regarding copyright ownership.The ASF licenses this file to You under the Apache License, Version 2.0(the "License"); you may not use this file except in compliance withthe License.  You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, softwaredistributed under the License is distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.See the License for the specific language governing permissions andlimitations under the License.
-->
<!-- START SNIPPET: example -->
<beansxmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdhttp://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd"><!-- Allows us to use system properties as variables in this configuration file --><bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"><property name="locations"><value>file:${activemq.conf}/credentials.properties</value></property></bean><!--The <broker> element is used to configure the ActiveMQ broker.--><broker xmlns="http://activemq.apache.org/schema/core" brokerName="localhost" dataDirectory="${activemq.data}"><destinationPolicy><policyMap><policyEntries><policyEntry topic=">" ><!-- The constantPendingMessageLimitStrategy is used to preventslow topic consumers to block producers and affect other consumersby limiting the number of messages that are retainedFor more information, see:http://activemq.apache.org/slow-consumer-handling.html--><pendingMessageLimitStrategy><constantPendingMessageLimitStrategy limit="1000"/></pendingMessageLimitStrategy></policyEntry></policyEntries></policyMap></destinationPolicy><!--The managementContext is used to configure how ActiveMQ is exposed inJMX. By default, ActiveMQ uses the MBean server that is started bythe JVM. For more information, see:http://activemq.apache.org/jmx.html--><managementContext><managementContext createConnector="false"/></managementContext><!--Configure message persistence for the broker. The default persistencemechanism is the KahaDB store (identified by the kahaDB tag).For more information, see:http://activemq.apache.org/persistence.html--><persistenceAdapter><kahaDB directory="${activemq.data}/kahadb"/></persistenceAdapter><!--The systemUsage controls the maximum amount of space the broker willuse before disabling caching and/or slowing down producers. For more information, see:http://activemq.apache.org/producer-flow-control.html--><systemUsage><systemUsage><memoryUsage><memoryUsage percentOfJvmHeap="70" /></memoryUsage><storeUsage><storeUsage limit="100 gb"/></storeUsage><tempUsage><tempUsage limit="50 gb"/></tempUsage></systemUsage></systemUsage><!--The transport connectors expose ActiveMQ over a given protocol toclients and other brokers. For more information, see:http://activemq.apache.org/configuring-transports.html--><transportConnectors><!-- DOS protection, limit concurrent connections to 1000 and frame size to 100MB --><transportConnector name="openwire" uri="tcp://0.0.0.0:61616?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/><transportConnector name="amqp" uri="amqp://0.0.0.0:5672?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/><transportConnector name="stomp" uri="stomp://0.0.0.0:61613?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/><transportConnector name="mqtt" uri="mqtt://0.0.0.0:1883?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/><transportConnector name="ws" uri="ws://0.0.0.0:61614?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/></transportConnectors><!-- destroy the spring context on shutdown to stop jetty --><shutdownHooks><bean xmlns="http://www.springframework.org/schema/beans" class="org.apache.activemq.hooks.SpringContextHook" /></shutdownHooks><!-- 消息订阅 --><destinationInterceptors><virtualDestinationInterceptor><virtualDestinations><compositeTopic name="VirtualTopic.device.sendData.*"><forwardTo><queue physicalName="deviceQueue.receiveDate" /></forwardTo></compositeTopic></virtualDestinations></virtualDestinationInterceptor></destinationInterceptors><plugins><simpleAuthenticationPlugin><users><authenticationUser username="${activemq.username}" password="${activemq.password}" groups="users,admins"/><!--<authenticationUser username="user" password="password" groups="users"/><authenticationUser username="guest" password="password" groups="guests"/> --></users></simpleAuthenticationPlugin></plugins></broker><!--Enable web consoles, REST and Ajax APIs and demosThe web consoles requires by default login, you can disable this in the jetty.xml fileTake a look at ${ACTIVEMQ_HOME}/conf/jetty.xml for more details--><import resource="jetty.xml"/></beans>
<!-- END SNIPPET: example -->

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/478705.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Postgresql 怎么实现在局域网中访问

安装PostgreSQL后&#xff0c;默认情况下只能在本机进行连接访问&#xff0c;如果需要在其他主机上访问PostgreSQL数据库服务器&#xff0c;需要进行配置。 安装连接PostgresSQL数据库可以参考博文&#xff1a;安装连接PostgresSQL数据库教程 一. 整体步骤 主要包括下面几个步…

响应式建站系统源码:一站式建站平台 带完整的安装代码包以及搭建教程

在网络技术日新月异的今天&#xff0c;网站建设已经成为企业、个人展示自身形象、提供服务的重要窗口。然而&#xff0c;传统的网站建设方式往往需要投入大量的时间、金钱和人力成本&#xff0c;且对于非专业人士来说存在较高的技术门槛。为了解决这些问题&#xff0c;罗峰给大…

业务型 编辑器组件的封装(复制即可使用)

使用需要安装 wangeditor npm i --save wangeditor import React from react; import E from wangeditor; import ./index.lessclass EditorElem extends React.Component {constructor(props) {super(props);this.isChange false;this.state {}}componentDidMount() {con…

数据结构:动态内存分配+内存分区+宏+结构体

一、作业 1.定义一个学生结构体&#xff0c;包含结构体成员&#xff1a;身高&#xff0c;姓名&#xff0c;成绩&#xff1b;定义一个结构体数组有7个成员&#xff0c;要求终端输入结构体成员的值&#xff0c;根据学生成绩&#xff0c;进行冒泡排序。 #include <stdio.h>…

好书推荐丨《细说机器学习:从理论到实践》

文章目录 写在前面机器学习推荐图书内容简介编辑推荐作者简介 推荐理由粉丝福利写在最后 写在前面 本期博主给大家推荐一本有关机器学习的全新正版书籍&#xff0c;对机器学习、人工智能感兴趣的小伙伴们快来看看吧~ 机器学习 机器学习&#xff08;Machine Learning, ML&…

基于WOA优化的Bi-LSTM多输入分类预测(Matlab)鲸鱼算法优化双向长短期神经网络分类预测

目录 一、程序及算法内容介绍&#xff1a; 基本内容&#xff1a; 亮点与优势&#xff1a; 二、实际运行效果&#xff1a; 三、算法介绍&#xff1a; 鲸鱼优化算法&#xff08;WOA&#xff09;&#xff1a; 双向长短期神经网络&#xff08;Bi-LSTM&#xff09;&#xff1a…

配置Python环境及job运行的虚拟环境

1、配置Jenkins的Python环境&#xff1a;Manage Jnekins-Global Tool Configuration-Python 2、安装pyenv插件 此插件会给每个job都创建一个虚拟Python环境 安装后&#xff0c;在job config-build中选择 virtualenv builder build job的时候会自动在/opt/jenkins(node主机的…

亚马逊、沃尔玛、eBay等跨境平台自养号测评的风险和技术解析

亚马逊等平台延伸至世界各地&#xff0c;竞争激烈。许多卖家使用自养号测评来提高产品排名和销量。但自养号测评技术存在一定的技术局限性&#xff0c;很多卖家的账号因对自养号原理和底层环境搭建缺乏了解很多卖家的账号被关联封禁。本文将为您揭示自养号测评的风险&#xff0…

物流EDI:Verizon EDI 需求分析

作为物流行业的企业&#xff0c;Verizon与其供应商之间通过EDI来传输业务单据。在与Verizon建立EDI连接时&#xff0c;需要参考EDI 指南、采购订单条款和条件以及运输路线指南这三个文档。 点击此链接&#xff0c;获取上述的三个文档 Verizon供应商可以通过上述链接找到用于处…

小红书数据分析:sora爆火,为内容行业带来哪些变化

导语 春节还没过完&#xff0c;科技圈就出“大事”了~据悉&#xff0c;OpenAI发布了Sora&#xff0c;一种由文字生成视频的AI工具&#xff0c;且效果极其逼真&#xff0c;打破了多项纪录。Sora的出现&#xff0c;又让人类里通用人工智能AGI近了一步。那么。Sora的出现对于小红…

ESP32-Cam学习(2)——PC实时显示摄像头画面

具体代码和操作过程见&#xff1a; 3. 实时显示摄像头画面 (itprojects.cn)https://doc.itprojects.cn/0006.zhishi.esp32/02.doc/index.html#/e03.showvideo我主要记录一下我在复现的过程中&#xff0c;遇到的问题以及解决方法。 1.安装第三方库 首先电脑端的代码需要用pych…

RK3568平台开发系列讲解(Linux系统篇)内核中断机制

🚀返回专栏总目录 文章目录 一、注册中断处理程序二、下半部的概念2.1、Tasklet作为下半部2.2、工作队列作为下半部2.3、Softirq作为下半部沉淀、分享、成长,让自己和他人都能有所收获!😄 📢中断是设备中止内核的一种方法,告诉内核发生了有趣或重要的事情。这些在Linu…