3

I'm getting the following error when trying to connect to ActiveMQ Artemis Queue deployed on JBoss EAP 7.1.

Error: DefaultMessageListenerContainer: Could not refresh JMS Connection for destination 'jms/queue/QueueA' - retrying using FixedBackOff{interval=5000, currentAttempts=139, maxAttempts=unlimited}. Cause: AMQ119031: Unable to validate user

Here is the code I'm using:

@Bean public DefaultMessageListenerContainer myFactory() throws NamingException { 
   DefaultMessageListenerContainer listenerContainer = new DefaultMessageListenerContainer();
   listenerContainer.setConnectionFactory(getConnectionFactory());
   listenerContainer.setDestinationName("jms/queue/QueueA");
   listenerContainer.setMessageListener(new MessageReceiver());
   return listenerContainer; 
}

private ConnectionFactory getConnectionFactory() throws NamingException { 
   final Properties env = new Properties();
   env.put(Context.INITIAL_CONTEXT_FACTORY, org.wildfly.naming.client.WildFlyInitialContextFactory); 
   env.put(Context.PROVIDER_URL, "http-remoting://localhost:8080"); 
   env.put(Context.SECURITY_PRINCIPAL, "Username"); 
   env.put(Context.SECURITY_CREDENTIALS, "Password"); 
   InitialContext ic = new InitialContext(env); 
   return (ConnectionFactory) ic.lookup("jms/RemoteConnectionFactory");
}
James R. Perkins
  • 16,800
  • 44
  • 60
Spartan
  • 45
  • 1
  • 7
  • Can you provide the code and/or configuration where you're using the DefaultMessageListenerContainer? – Justin Bertram Apr 03 '18 at 19:55
  • @Bean public DefaultMessageListenerContainer myFactory() throws NamingException { DefaultMessageListenerContainer listenerContainer = new DefaultMessageListenerContainer(); listenerContainer.setConnectionFactory(getConnectionFactory()); listenerContainer.setDestinationName("jms/queue/QueueA"); listenerContainer.setMessageListener(new MessageReceiver()); return listenerContainer; } – Spartan Apr 03 '18 at 20:56
  • private ConnectionFactory getConnectionFactory() throws NamingException { final Properties env = new Properties(); env.put(Context.INITIAL_CONTEXT_FACTORY, org.wildfly.naming.client.WildFlyInitialContextFactory); env.put(Context.PROVIDER_URL, "http-remoting://localhost:8080"); env.put(Context.SECURITY_PRINCIPAL, "Username"); env.put(Context.SECURITY_CREDENTIALS, "Password"); InitialContext ic = new InitialContext(env); return (ConnectionFactory) ic.lookup("jms/RemoteConnectionFactory"); } – Spartan Apr 03 '18 at 20:56

1 Answers1

5

As the error message (i.e. AMQ119031: Unable to validate user) indicates, you have not provided the proper credentials when creating your JMS connection.

The username & password information you've provided in the properties for your JNDI lookup apply only for the JNDI lookup (i.e. not for the JMS connection). JNDI and JMS are 100% independent of each other.

You must configure the appropriate Spring component with your JMS username and password so it can be used when it invokes javax.jms.ConnectionFactory.createConnection(String,String) or javax.jms.ConnectionFactory.createContext(String,String). Try returning an instance of UserCredentialsConnectionFactoryAdapter from your getConnectionFactory() method.

Justin Bertram
  • 29,372
  • 4
  • 21
  • 43
  • Can you help me figure out how and which Spring component have to configured with the username and password. I haven't come through any article that does that in Spring(creating a connection,context) – Spartan Apr 04 '18 at 00:04
  • Thank You Justin. I was successfully able to connect and read messages from Queue.Below is my modified getConnectionFactory() – Spartan Apr 04 '18 at 20:45
  • Addition to code of getConnectionFactory in the post: ConnectionFactory connectionFactory = (ConnectionFactory) ic.lookup("jms/RemoteConnectionFactory"); UserCredentialsConnectionFactoryAdapter userCredentialsConnectionFactoryAdapter = new UserCredentialsConnectionFactoryAdapter(); userCredentialsConnectionFactoryAdapter.setUsername("Username"); userCredentialsConnectionFactoryAdapter.setPassword("Password"); userCredentialsConnectionFactoryAdapter.setTargetConnectionFactory(connectionFactory); return userCredentialsConnectionFactoryAdapter; – Spartan Apr 04 '18 at 20:56