Search code examples
spring-bootmicroservicesspring-jmsjboss-eap-7activemq-artemis

Getting an error "Cause: AMQ119031: Unable to validate user" in Spring-Boot app


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");
}

Solution

  • 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.