1.編輯: ${activemq.base}/conf/activemq.xml配置文件,
在<broker xmlns="http://activemq.apache.org/schema/core" brokerName="localhost" dataDirectory="${activemq.base}/data">節點下添加以下節點
<plugins>
<simpleAuthenticationPlugin>
<users>
<authenticationUser username="system" password="manager" groups="users,admins"/>
<authenticationUser username="user" password="password" groups="users"/>
<authenticationUser username="guest" password="password" groups="guests"/>
</users>
</simpleAuthenticationPlugin>
</plugins>
2.編寫JMS客戶端程序:
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(url,username,password);
注意: username 和password必須和配置文件裏的一致,否則會拋出異常.