activeMq的安全机制

activemq添加用户名密码认证,找到activemq配置文件activemq.xml  在conf目录下

在<broker></broker>节点下添加这段代码

1 <plugins>
2     <simpleAuthenticationPlugin>
3         <users>
4             <authenticationUser username="ssc" password="ssc" groups="users,admin"/>
5                       <!--如果多个账号密码时,可以添加多个配置-->
6                        <authenticationUser username="aaa" password="aaa" groups="users,admin"/>
7         </users>
8     </simpleAuthenticationPlugin>
9 </plugins>

然后重启activemq

java对应的连接,默认使用的用户名和密码是null

//创建连接工厂
connectionFactory=new ActiveMQConnectionFactory(ActiveMQConnectionFactory.DEFAULT_USER,ActiveMQConnectionFactory.DEFAULT_PASSWORD, BROKER_URL);

修改为

connectionFactory=new ActiveMQConnectionFactory("aaa","aaa",BROKER_url );

如果账号密码不对将会报javax.jms.JMSSecurityException

生于忧患,死于安乐
原文地址:https://www.cnblogs.com/songlove/p/14704718.html