天天看點

ActiveMQ的認證和授權的簡單配置

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必須和配置檔案裡的一緻,否則會抛出異常.