Use username and password to connect ActiveMQ JMS

Apache ActiveMQ creates a secure connection using a username and password.

InitialContext initCtx = new InitialContext(); javax.jms.ConnectionFactory qcf = (javax.jms.ConnectionFactory) initCtx.lookup(factoryName); Connection connection = qcf.createConnection(userName, password); 

Where can I find these credentials. Are these usernames and passwords configured in any ActiveMQ configuration file?

+5
source share
2 answers

To answer your question: indeed, they are, and the name of the file in which the credentials are defined is activemq.xml . It can be found in the conf directory of your ActiveMQ installation, for example. C:\Program Files (x86)\apache-activemq-5.10.0\conf .

Now, on this site , there are fairly detailed instructions for setting up ActiveMQ to use simple authentication or JAAS, but I will give you a brief summary and some tips:

  • All of the following materials should be inserted into the plugins section of the above XML file.

  • Use SimpleAuthentication to simply “add” users to groups, for example.

      <simpleAuthenticationPlugin anonymousAccessAllowed="true"> <users> <authenticationUser username="system" password="system" groups="users,admins"/> <authenticationUser username="admin" password="admin" groups="users,admins"/> <authenticationUser username="user" password="user" groups="users"/> <authenticationUser username="guest" password="guest" groups="guests"/> </users> </simpleAuthenticationPlugin> 
  • Use AuthorizationPlugin to configure which groups have access to those queues and topics.

  • If you plan to use SimpleAuthentication , make sure that your active plugins do not have <jaasAuthenticationPlugin configuration="activemq-domain" /> . Just in case, you plan to copy this one sample from the page that I mentioned earlier.

  • You might want to enable anonymous access. To do this, add the appropriate attribute to your SimpleAuthenticatoinPlugin node. Once this is done, you can connect to the queues without specifying a username and password when creating a connection.

+5
source

You tried to connect without providing a username and password, by default you must do this.

 ConnectionFactory connectionFactoryProd = new ActiveMQConnectionFactory("failover://tcp://yourServerWhereActiveMqIs:61616"); Connection connectionProd = connectionFactoryProd.createConnection(); connectionProd.start(); 
-1
source

Source: https://habr.com/ru/post/1213121/


All Articles