日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区

您的位置:首頁技術文章
文章詳情頁

Spring Boot ActiveMQ如何設置訪問密碼

瀏覽:293日期:2023-08-29 17:56:31

Apache ActiveMQ是Apache出品,是最流行的,能力很強的開源消息總線。默認情況下,程序連接ActiveMQ是不需要密碼的,為了安裝起見,需要設置密碼,提高安全性。本文分享如何設置訪問ActiveMQ的賬號密碼。

小編使用的ActiveMQ版本是apache-activemq-5.15.13。

一、設置控制臺管理密碼

ActiveMQ使用的是jetty服務器,找到 ActiveMQ安裝目錄下的confjetty.xml文件:

<bean class='org.eclipse.jetty.util.security.Constraint'> <property name='name' value='BASIC' /> <property name='roles' value='admin' /> <!-- set authenticate=false to disable login --> <property name='authenticate' value='true' /></bean>

注意:authenticate的屬性默認為'true',登錄管理界面時需要輸入賬戶和密碼;如果是“false”,需要改為'true'。

修改管理界面登錄時的用戶名和密碼,在conf/jetty-realm.properties文件中添加用戶

## ---------------------------------------------------------------------------## Licensed to the Apache Software Foundation (ASF) under one or more## contributor license agreements. See the NOTICE file distributed with## this 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 with## the License. You may obtain a copy of the License at#### http://www.apache.org/licenses/LICENSE-2.0#### Unless required by applicable law or agreed to in writing, software## distributed 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 and## limitations under the License.## ---------------------------------------------------------------------------# Defines users that can access the web (console, demo, etc.)# username: password [,rolename ...]# admin: admin, admin# user: user, userwiener: wiener1237, admin

配置信息按順序解釋,分別是:用戶名、密碼、角色名

二、消息生產者和消費者密碼認證

在confactivemq.xml中broker 標簽最后添加生產者和消費者密碼認證信息:

<!-- destroy the spring context on shutdown to stop jetty --> <shutdownHooks> <bean xmlns='http://www.springframework.org/schema/beans' /> </shutdownHooks> <!-- add plugins --> <plugins> <simpleAuthenticationPlugin><users> <authenticationUser username='${activemq.username}' password='${activemq.password}' groups='users,admins'/></users> </simpleAuthenticationPlugin> </plugins> </broker>

activemq.username和activemq.password的值在文件credentials.properties中配置,見如下步驟。

設置用戶名密碼,文件在confcredentials.properties

## ---------------------------------------------------------------------------## Licensed to the Apache Software Foundation (ASF) under one or more## contributor license agreements. See the NOTICE file distributed with## this 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 with## the License. You may obtain a copy of the License at#### http://www.apache.org/licenses/LICENSE-2.0#### Unless required by applicable law or agreed to in writing, software## distributed 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 and## limitations under the License.## ---------------------------------------------------------------------------# Defines credentials that will be used by components (like web console) to access the broker# activemq.username=system# activemq.password=manager# guest.password=passwordactivemq.username=wieneractivemq.password=wiener1237guest.password=password

三、Java端配置用戶名密碼

驗證代碼是在《【Spring Boot】ActiveMQ 發布/訂閱消息模式介紹》的基礎上做重構,除了新增類ActiveMQConfig之外,修改部分均用紅色字體標注。配置application.properties連接信息:

## URL of the ActiveMQ broker. Auto-generated by default. For instance `tcp://localhost:61616`# failover:(tcp://localhost:61616,tcp://localhost:61617)# tcp://localhost:61616spring.activemq.broker-url=tcp://localhost:61616spring.activemq.in-memory=truespring.activemq.pool.enabled=false#默認值false,表示point to point(點到點)模式,true時代表發布訂閱模式,需要手動開啟spring.jms.pub-sub-domain=truespring.activemq.user=wienerspring.activemq.password=wiener1237

在項目中配置 ActiveMQ連接屬性,新增ActiveMQConfig類:

import org.apache.activemq.ActiveMQConnectionFactory;import org.springframework.beans.factory.annotation.Value;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration;import org.springframework.jms.config.DefaultJmsListenerContainerFactory;import org.springframework.jms.config.JmsListenerContainerFactory;/*** 配置 ActiveMQ** @author east7* @date 2020/6/23 11:27*/@Configurationpublic class ActiveMQConfig { @Value('${spring.activemq.user}') private String usrName; @Value('${spring.activemq.password}') private String password; @Value('${spring.activemq.broker-url}') private String brokerUrl; @Bean public ActiveMQConnectionFactory connectionFactory() { System.out.println('password =========== ' + password); return new ActiveMQConnectionFactory(usrName, password, brokerUrl); } /** * 設置點對點模式,和下面的發布訂閱模式二選一即可 * @param connectionFactory * @return */ @Bean public JmsListenerContainerFactory<?> jmsListenerContainerQueue(ActiveMQConnectionFactory connectionFactory){ DefaultJmsListenerContainerFactory bean = new DefaultJmsListenerContainerFactory(); bean.setConnectionFactory(connectionFactory); return bean; } @Bean public JmsListenerContainerFactory<?> jmsListenerContainerTopic(ActiveMQConnectionFactory connectionFactory){ //設置為發布訂閱模式, 默認情況下使用生產消費者方式 DefaultJmsListenerContainerFactory bean = new DefaultJmsListenerContainerFactory(); bean.setPubSubDomain(true); bean.setConnectionFactory(connectionFactory); return bean; }}

bean.setPubSubDomain(true)配置會覆蓋properties文件中spring.jms.pub-sub-domain的屬性值,故可以在properties不設置spring.jms.pub-sub-domain屬性。另外,這種配置方式可以在系統中同時使用點對點和發布/訂閱兩種消息模式。修改訂閱者:

import org.slf4j.Logger;import org.slf4j.LoggerFactory;import org.springframework.jms.annotation.JmsListener;import org.springframework.stereotype.Component;import javax.jms.JMSException;/*** 消費者*/@Componentpublic class Subscriber1 { private static Logger logger = LoggerFactory.getLogger(Subscriber1.class); /** * 訂閱 topicListener1,僅僅加入containerFactory即可 * * @param text * @throws JMSException */ @JmsListener(destination = 'topicListener1', containerFactory = 'jmsListenerContainerTopic') public void subscriber(String text) { logger.info('Subscriber1 收到的報文:{}', text); }}

containerFactory 的值 'jmsListenerContainerTopic' 會自動匹配到ActiveMQConfig中的函數JmsListenerContainerFactory<?> jmsListenerContainerTopic(ActiveMQConnectionFactory connectionFactory)。 Subscriber2同樣修改即可,代碼省略。如果containerFactory 的值設置為jmsListenerContainerQueue,則開啟了點到點消息模式。

測試函數還可以使用topicTest()。下面提供一個新的測試途徑——在controller中測試。新增方法

@Autowiredprivate Publisher publisher;@GetMapping('/sendTopicMsg')public String sendTopicMsg(String msg) { // 指定消息發送的目的地及內容 Destination destination = new ActiveMQTopic('topicListener2'); for (int i = 0; i < 8; i++) { publisher.publish(destination, msg + i); } return msg + ' 發送完畢';}

執行結果省略。

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: Spring
相關文章:
日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区
久久免费高清| 日本麻豆一区二区三区视频| 日本免费在线视频不卡一不卡二| 亚洲激精日韩激精欧美精品| 日韩欧美一区二区三区免费观看| 精品三级久久| 99精品网站| 免费不卡中文字幕在线| 五月精品视频| 老鸭窝亚洲一区二区三区| 免费视频一区二区| 日韩欧美在线精品| 国产精品igao视频网网址不卡日韩| 91精品国产一区二区在线观看| 国产日韩欧美在线播放不卡| 国产精品v一区二区三区| 麻豆国产一区| 国产精品99一区二区三区| 婷婷激情一区| 91精品电影| 日韩高清一级| 国产精品www994| caoporn视频在线| 欧美日韩一二三四| 国产综合视频| 亚洲日产国产精品| 免费视频一区二区三区在线观看| 日韩大片免费观看| 另类av一区二区| 国产欧美一区| 日本在线啊啊| 99热精品在线观看| 91亚洲无吗| 国产成人精品亚洲线观看 | 麻豆精品网站| 欧美一区成人| 蜜臀国产一区| 日韩精品一二三区| 国产精品jk白丝蜜臀av小说| 久久网站免费观看| 日本一区二区三区视频在线看| 国产欧美日韩免费观看| 中文字幕成在线观看| 亚洲免费高清| 国产欧美一区二区三区精品观看| a天堂资源在线| 中文字幕免费精品| 久久精品欧洲| 亚洲免费中文| 国产精品二区不卡| 综合色一区二区| 欧美国产美女| 亚洲人成网77777色在线播放| 国产一区调教| 亚洲丝袜啪啪| 欧美二三四区| 日韩av一区二区三区| 成人羞羞视频在线看网址| 伊人久久大香伊蕉在人线观看热v| 久久中文字幕一区二区三区| 亚洲精品小说| 国产激情精品一区二区三区| 99国产精品久久久久久久成人热| 嫩草伊人久久精品少妇av杨幂| 91精品福利| 国产一区调教| 亚洲精品在线a| 亚洲www啪成人一区二区| 日本中文字幕一区二区| 久久国产电影| 老司机精品视频在线播放| 日韩中文欧美在线| 日本免费一区二区三区四区| 日韩和欧美一区二区三区| 日韩在线免费| 欧美日韩中出| 不卡一区2区| 欧美国产美女| 91成人小视频| 蜜臀av一区二区三区| 亚洲天堂资源| 免费在线观看一区| 日韩av一区二区三区四区| 夜夜嗨一区二区三区| 国产网站在线| 久久久91麻豆精品国产一区| 日本少妇一区二区| 视频一区欧美日韩| 久久精品播放| а√天堂8资源中文在线| 日韩不卡在线观看日韩不卡视频 | 欧美一区成人| 日韩在线a电影| 精品日韩毛片| 亚洲1234区| 精品视频网站| 欧美激情精品| 国产一卡不卡| 亚洲麻豆一区| 亚洲精品乱码久久久久久蜜桃麻豆| 亚洲电影在线一区二区三区| 涩涩av在线| 久久中文在线| 国产剧情在线观看一区| 视频一区日韩| 中文字幕成人| 免费欧美在线视频| 午夜一级在线看亚洲| 99国产精品私拍| 亚洲少妇在线| 亚洲免费一区二区| 免费在线成人网| 一级欧美视频| 亚洲一区二区三区无吗| 久久国产精品亚洲77777| 亚洲激情黄色| 欧美特黄一区| 激情欧美一区二区三区| 亚洲高清激情| 欧美粗暴jizz性欧美20| 国精品一区二区三区| 91久久久精品国产| aa亚洲婷婷| 一二三区精品| 日韩av一区二区三区四区| 日本成人在线不卡视频| 色综合视频一区二区三区日韩| 亚洲自啪免费| 日韩区一区二| 国产精品久久免费视频| 久久字幕精品一区| zzzwww在线看片免费| 丝袜美腿一区| 欧美精品一二| 蜜桃免费网站一区二区三区| 日韩欧美中文字幕电影| 国产精品亚洲欧美日韩一区在线 | 亚洲一级黄色| 欧美资源在线| 日本v片在线高清不卡在线观看| 欧美一区精品| 久久精品一区二区国产| yellow在线观看网址| 久久精品91| 久久一二三区| 在线精品一区| 欧美1区2区3| 国产 日韩 欧美一区| 免费久久精品| 日韩高清一级| 91欧美在线| 亚洲欧洲一区| 国产日韩欧美中文在线| 91一区二区三区四区| 激情欧美亚洲| 日本一区二区三区视频在线看| 91成人在线网站| 日韩一区电影| 亚洲一区二区三区高清| 日本va欧美va精品发布| 久久免费影院| 91精品国产调教在线观看| 天堂av在线一区| 国产精品久久久网站| 亚洲性色av| 日韩一区二区三区四区五区| 精品理论电影在线| 亚洲激情偷拍| 国产精品午夜av| 999国产精品| 日韩国产欧美三级| 黄色在线网站噜噜噜| 性欧美精品高清| 欧美精品二区| 欧美91精品| 欧美综合精品| 婷婷成人在线| 国产毛片一区二区三区| 99成人在线视频| 久久精品超碰| 精品中文字幕一区二区三区av| 日韩国产成人精品| 99精品在线观看| 国产精品日本一区二区不卡视频 | 亚洲人成网77777色在线播放 | 欧美另类中文字幕| 欧美成人亚洲| 久久一区欧美| 免费欧美日韩| 国产精品精品国产一区二区| 亚洲伊人精品酒店| 日韩三区免费| 国产精品久久久网站| 亚洲一区二区三区免费在线观看 | 成人日韩在线观看| 国产欧美一区二区色老头| japanese国产精品| 精品久久视频| 日本在线不卡视频一二三区| 午夜久久福利|