日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【Spring Boot】ActiveMQ 设置访问密码

發(fā)布時(shí)間:2025/6/17 编程问答 23 如意码农
生活随笔 收集整理的這篇文章主要介紹了 【Spring Boot】ActiveMQ 设置访问密码 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

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

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

一、設(shè)置控制臺(tái)管理密碼

    ActiveMQ使用的是jetty服務(wù)器,找到 ActiveMQ安裝目錄下的\conf\jetty.xml文件:
<bean id="adminSecurityConstraint" 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的屬性默認(rèn)為"true",登錄管理界面時(shí)需要輸入賬戶和密碼;如果是“false”,需要改為"true"。

修改管理界面登錄時(shí)的用戶名和密碼,在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, user
wiener: wiener1237, admin

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

二、消息生產(chǎn)者和消費(fèi)者密碼認(rèn)證

   在\conf\activemq.xml中broker 標(biāo)簽最后添加生產(chǎn)者和消費(fèi)者密碼認(rèn)證信息:
        <!-- 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>
<!-- 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中配置,見如下步驟。

   設(shè)置用戶名密碼,文件在\conf\credentials.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=password activemq.username=wiener
activemq.password=wiener1237
guest.password=password

三、Java端配置用戶名密碼

驗(yàn)證代碼是在《【Spring Boot】ActiveMQ 發(fā)布/訂閱消息模式介紹》的基礎(chǔ)上做重構(gòu),除了新增類ActiveMQConfig之外,修改部分均用紅色字體標(biāo)注。配置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:61616
spring.activemq.broker-url=tcp://localhost:61616
spring.activemq.in-memory=true
spring.activemq.pool.enabled=false
#默認(rèn)值false,表示point to point(點(diǎn)到點(diǎn))模式,true時(shí)代表發(fā)布訂閱模式,需要手動(dòng)開啟
spring.jms.pub-sub-domain=true
spring.activemq.user=wiener
spring.activemq.password=wiener1237

在項(xiàng)目中配置 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
*/
@Configuration
public 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);
} /**
* 設(shè)置點(diǎn)對(duì)點(diǎn)模式,和下面的發(fā)布訂閱模式二選一即可
* @param connectionFactory
* @return
*/
@Bean
public JmsListenerContainerFactory<?> jmsListenerContainerQueue(ActiveMQConnectionFactory connectionFactory){
DefaultJmsListenerContainerFactory bean = new DefaultJmsListenerContainerFactory();
bean.setConnectionFactory(connectionFactory);
return bean;
} @Bean
public JmsListenerContainerFactory<?> jmsListenerContainerTopic(ActiveMQConnectionFactory connectionFactory){
//設(shè)置為發(fā)布訂閱模式, 默認(rèn)情況下使用生產(chǎn)消費(fèi)者方式
DefaultJmsListenerContainerFactory bean = new DefaultJmsListenerContainerFactory();
bean.setPubSubDomain(true);
bean.setConnectionFactory(connectionFactory);
return bean;
}
}

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

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component; import javax.jms.JMSException; /**
* 消費(fèi)者
*/
@Component
public 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 收到的報(bào)文:{}", text);
}
}

containerFactory 的值 "jmsListenerContainerTopic" 會(huì)自動(dòng)匹配到ActiveMQConfig中的函數(shù)JmsListenerContainerFactory<?> jmsListenerContainerTopic(ActiveMQConnectionFactory connectionFactory)。  Subscriber2同樣修改即可,代碼省略。如果containerFactory 的值設(shè)置為jmsListenerContainerQueue,則開啟了點(diǎn)到點(diǎn)消息模式。

    測(cè)試函數(shù)還可以使用topicTest()。下面提供一個(gè)新的測(cè)試途徑——在controller中測(cè)試。新增方法
@Autowired
private Publisher publisher; @GetMapping("/sendTopicMsg")
public String sendTopicMsg(String msg) {
// 指定消息發(fā)送的目的地及內(nèi)容
Destination destination = new ActiveMQTopic("topicListener2");
for (int i = 0; i < 8; i++) {
publisher.publish(destination, msg + i);
}
return msg + " 發(fā)送完畢";
}

執(zhí)行結(jié)果省略。

總結(jié)

以上是生活随笔為你收集整理的【Spring Boot】ActiveMQ 设置访问密码的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 亚洲色婷婷久久精品av蜜桃 | 福利视频一区二区三区 | 亚洲国产清纯 | 亚洲黄网在线 | 久久r视频 | se94se欧美| 青草草在线视频 | 黄色一级片视频 | 天天骑夜夜操 | 天天操你 | 免费av一区 | 波多野结衣之潜藏淫欲 | 一级看片| 黄色性网站 | 日韩一级完整毛片 | 五月视频 | 精品黑人一区二区三区久久 | 免费无毒av| 动漫3d精品一区二区三区乱码 | 肥臀浪妇太爽了快点再快点 | 国产无码日韩精品 | 日韩影视一区二区三区 | 9·1·黄·色·视·频 | www网站在线观看 | 操到喷水 | 怡红院一区二区 | 亚洲精品污 | 在线97视频| 欧美少妇激情 | 四虎网站最新网址 | 黄色av免费在线播放 | 日本精品一区二区三区视频 | 国产成人在线观看 | 伊人福利视频 | 尤物视频在线 | www.色婷婷 | 日韩黄色三级 | www.x日本| av在线天堂 | 日本少妇性高潮 | 三级理论电影 | 国产偷国产偷av亚洲清高 | 综合黄色 | 亚洲av成人无码久久精品 | 亚洲精品四区 | 啊av在线| 欧美在线播放一区 | 免费日韩毛片 | 国产日韩欧美日韩大片 | 中文一级片 | 这里只有久久精品 | 麻豆传媒在线观看视频 | 精品亚洲一区二区 | 国产性生活网站 | 青青啪啪 | 日韩视频在线观看视频 | 人体内射精一区二区三区 | 香蕉毛片 | 欧美一区二区三区久久成人精品 | 国产人免费人成免费视频 | 一区二区三区不卡在线 | 久久国产精品99久久人人澡 | 精品熟女一区二区三区 | 亚洲熟女乱综合一区二区 | 极品videosvideo喷水 | 精品熟女一区二区三区 | wwwxxx日韩 | 日韩综合另类 | 日韩在线观看网站 | 四虎免费影视 | 涩涩网站免费 | 嫩草国产精品 | 伊人亚洲精品 | аⅴ资源天堂资源库在线 | 综合性色 | 久久精品免费一区二区 | 91久久久久久久久久 | 人妻少妇偷人精品久久久任期 | 亚洲tv在线观看 | www.av日韩| 日韩精品成人在线观看 | 四虎毛片| eeuss日韩 | 日本黄色三级视频 | 国内毛片毛片毛片 | 日本一本在线 | 精品少妇一区二区三区免费观看 | 久久九九综合 | 亚洲射射射 | 少妇视频网站 | 中文字幕第22页 | 欧美人吸奶水吃奶水 | 欲求不满的岳中文字幕 | а√天堂资源官网在线资源 | 神马午夜伦理影院 | 婷婷六月综合网 | 波多野结衣视频一区二区 | 国产成人麻豆精品午夜在线 | 香蕉网在线 |