1.修改activemq.xml配置,需要新增一个插件,在<broker>节点里面<systemUsage>节点前面添加如下
<plugins>
<simpleAuthenticationPlugin>
<users>
<authenticationUser username="XXXXX" password="XXXXX" groups="users,admins"/>
</users>
</simpleAuthenticationPlugin>
</plugins>
2.ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("XXXXX","XXXXX",BROKER_URL);//第一个参数为用户名,第二个参数为密码