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.pswp.cn/news/697172.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/697172.shtml
英文地址,請注明出處:http://en.pswp.cn/news/697172.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

ReactNative進階(二十三)error: no type or protocol named ‘RCTBridgeModule’問題修復

文章目錄 一、前言三、拓展閱讀 一、前言 Jenkins組包RN技術棧實現的iOS應用時&#xff0c;遇到以下錯誤提示信息&#xff1a; error: no type or protocol named ‘RCTBridgeModule’ interface RCTEventDispatcher : NSObject <RCTBridgeModule>error: cannot find i…

【AIGC】基于深度學習的圖像生成與增強技術

摘要&#xff1a; 本論文探討基于深度學習的圖像生成與增強技術在圖像處理和計算機視覺領域的應用。我們綜合分析了主流的深度學習模型&#xff0c;特別是生成對抗網絡&#xff08;GAN&#xff09;和變分自編碼器&#xff08;VAE&#xff09;等&#xff0c;并就它們在實際應用中…

嵌入式linux開發 (三十四) 內存管理2.0(6) 各種段(.code .rodata .data .bss .stack .heap)的含義

我們知道, 邏輯程序在連接的時候在elf 文件中會有 .code .rodata .data 然后在內存中才會有 .code .rodata .data那么為什么鏈接器在鏈接生成的elf文件中會有這些段呢?這涉及到鏈接器的歷史問題

小程序性能優化

背景 在開發小程序的過程中我們發現&#xff0c;小程序的經常會遇到性能問題&#xff0c;尤其是在微信開發者工具的時候更是格外的卡&#xff0c;經過排查發現&#xff0c;卡頓的頁面有這么多的js代碼需要加載&#xff0c;而且都是在進入這個頁面的時候加載&#xff0c;這就會…

Java架構師之路九、設計模式:常見的設計模式,如單例模式、工廠模式、策略模式、橋接模式等

目錄 常見的設計模式&#xff1a; 單例模式&#xff1a; 工廠模式&#xff1a; 策略模式&#xff1a; 橋接模式&#xff1a; 責任鏈模式&#xff1a; Java架構師之路八、安全技術&#xff1a;Web安全、網絡安全、系統安全、數據安全等-CSDN博客Java架構師之路十、框架和工…

Android 仿信號格子強度動畫效果實現

效果圖 在 Android 中&#xff0c;如果你想要繪制一個圓角矩形并使其居中顯示&#xff0c;你可以使用 Canvas 類 drawRoundRect 方法。要使圓角矩形居中&#xff0c;你需要計算矩形的位置&#xff0c;這通常涉及到確定矩形左上角的位置&#xff08;x, y&#xff09;&#xff0…

Leetcode 第 384 場周賽題解

Leetcode 第 384 場周賽題解 Leetcode 第 384 場周賽題解題目1&#xff1a;3033. 修改矩陣思路代碼復雜度分析 題目2&#xff1a;3034. 匹配模式數組的子數組數目 I思路代碼復雜度分析 題目3&#xff1a;3035. 回文字符串的最大數量思路代碼復雜度分析 題目4&#xff1a;3036. …

C語言標準庫介紹:<string.h>

在C語言中&#xff0c;<string.h>頭文件是標準庫中的一個重要部分&#xff0c;它定義了一系列操作字符串和字符數組的函數。本文將詳細介紹<string.h>頭文件中包含的22個函數&#xff0c;并提供每個函數的完整示例代碼。 簡介 <string.h>頭文件定義了一個變…

設計模式-工廠模式(Factory Pattern)

一、工廠模式說明 工廠模式是一種創建型設計模式&#xff0c;它提供了一種將對象的創建與使用分離的方式。工廠模式通過引入一個公共的接口來創建對象&#xff0c;而不是通過直接調用構造函數來創建對象。這樣做的好處是使得代碼更加靈活&#xff0c;更容易維護和擴展。 工廠模…

第3部分 原理篇2去中心化數字身份標識符(DID)(2)

3.2.2. DID相關概念 3.2.2.1. 去中心化標識符 (Decentralized identifier&#xff0c;DID) 本聰老師&#xff1a;DID有兩個含義&#xff0c;一是Decentralized identity&#xff0c;就是去中心化身份&#xff0c;是廣泛意義的DID。另外一個是Decentralized identifier&#xf…

Web性能優化-瀏覽器工作原理-MDN文檔學習筆記

瀏覽器工作原理 查看更多學習筆記&#xff1a;GitHub&#xff1a;LoveEmiliaForever MDN中文官網 導航 導航是加載 web 頁面的第一步&#xff1a;輸入 URL、點擊一個鏈接、提交表單等等 DNS查詢 導航的第一步是要去尋找頁面資源的位置 例如訪問https://example.com&#x…

如何解決DNS解析錯誤故障

DNS解析錯誤會導致將一個域名解析為錯誤的IP地址&#xff0c;或者根本無法確定某個域名對應的IP地址&#xff0c;從而無法通過域名訪問相應的站點&#xff0c;形成DNS解析故障。最常見的癥狀是訪問站點對應的IP地址沒有問題&#xff0c;但訪問其域名時卻出現錯誤。 DNS解析異常…

qt-動畫圓圈等待-LED數字

qt-動畫圓圈等待-LED數字 一、演示效果二、關鍵程序三、下載鏈接 一、演示效果 二、關鍵程序 #include "LedNumber.h" #include <QLabel>LEDNumber::LEDNumber(QWidget *parent) : QWidget(parent) {//設置默認寬高比setScale((float)0.6);//設置默認背景色se…

【深入了解TensorFlow】TensorFlow的安裝與配置

【深入了解TensorFlow】TensorFlow的安裝與配置 TensorFlow的安裝與配置準備就緒:開始前的準備工作1. 確定您的硬件和操作系統2. 選擇安裝方式3. 創建虛擬環境(可選)安裝TensorFlow使用pip安裝使用conda安裝從源代碼編譯安裝配置TensorFlow導入TensorFlow模塊檢查安裝是否成…

Oracle 表被刪除或重命名后賬戶間的授權與同義詞關系

Oracle 表被刪除或重命名后賬戶間的授權與同義詞關系 情景一、 當數據表刪除后 數據表被刪除后&#xff0c;同義詞還是存在的&#xff0c;可以查看當前用戶下查看同義詞&#xff1a; -- 查看當前用戶下的同義詞 select * from user_synonyms但授權關系不在了&#xff0c;若重…

10 個 Linux 中超方便的 Bash 別名

1、 你有幾次遇到需要解壓 .tar 文件但無法記住所需的確切參數&#xff1f;別名可以幫助你&#xff01;只需將以下內容添加到 .bash_profile 中&#xff0c;然后使用 untar FileName 解壓縮任何 .tar 文件。 alias untartar -zxvf 2、 下載文件時&#xff0c;如果出現問題想要…

websocket與Socket的區別

概念講解 網絡&#xff1a;通俗意義上&#xff0c;也就是連接兩臺計算器 五層網絡模型&#xff1a;應用層、傳輸層、網絡層、數據鏈路層、物理層 應用層 (application layer)&#xff1a;直接為應用進程提供服務。應用層協議定義的是應用進程間通訊和交互的規則&#xff0c;不…

明明正常,卻不停return

明明正常&#xff0c;卻不停return if(!is); { return ; } 熬人

應急響應速查

最重要的&#xff1a;我是誰&#xff1f;我在哪&#xff1f;別人怎么進來的&#xff1f;我就是這個被挖礦被勒索的電腦。 分析項 &#xff1a; 一、了解大概的被入侵系統情況&#xff1a; 發現時間&#xff1f;怎么發現的&#xff1f;這臺機器有沒有人運維&#xff1f;平時還…

排序第三篇 直接插入排序

插入排序的基本思想是&#xff1a; 每次將一個待排序的記錄按其關鍵字的大小插入到前面已排好序的文件中的適當位置&#xff0c; 直到全部記錄插入完為止。 一 簡介 插入排序可分為2類 本文介紹 直接插入排序 它的基本操作是&#xff1a; 假設待排充序的記錄存儲在數組 R[1……