Apache ActiveMQ是Apache出品,是最流行的,能力很强的开源消息总线。默认情况下,程序连接ActiveMQ是不需要密码的,为了安装起见,需要设置密码,提高安全性。本文分享如何设置访问ActiveMQ的账号密码。
小编使用的ActiveMQ版本是apache-activemq-5.15.13。
一、设置控制台管理密码
ActiveMQ使用的是jetty服务器,找到 ActiveMQ安装目录下的\conf\jetty.xml文件:
注意: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://ponentpublic 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中测试。新增方法
执行结果省略。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。