简介
默认安装的activemq 使用 ActiveMQConnectionFactory 时没有用户名/密码。只要有人知道了我们activemq服务器的ip和端口,就可以连上去消费掉我们的消息,所以我们需要给activemq设置一个username和pasword;
ActiveMQ也提供了安全认证。就是用户名密码登录规则。ActiveMQ如果需要使用安全认证的话,必须在activemq的核心配置文件中开启安全配置。配置文件就是conf/activemq.xml
配置文件:
conf/login.config
user代表用户信息配置文件,group代表用户组信息配置文件。寻址路径为相对当前配置文件所在位置开始寻址。
conf/users.properties
户信息配置文件,格式:用户名=密码
conf/groups.properties
用户组信息配置文件,格式:组名=用户名,用户名…
二、配置用户名/密码
方式1:
在conf下的activemq.xml的broker节点插入一个子节点如下:
<plugins>
<simpleAuthenticationPlugin>
<users>
<authenticationUser username="vincent" password="123456" groups="users,admins" />
</users>
</simpleAuthenticationPlugin>
</plugins>
重启activemq 并执行
ConnectionFactory factory = new ActiveMQConnectionFactory(null,null,"tcp://localhost:61616");