Trying to implement a non-XML JMS listener using Spring 4 and ActiveMQ. My issue is that I keep getting the following error with my client:
Setup of JMS message listener invoker failed for destination 'topic.FromJndiProperties' [...]
Cause: The JMS connection has failed: Force close due to SecurityException on connect.
Cause: User name [null] or password is invalid.
So the connection to the destination is being made with username and password null. I think I may have not setup the destinationResolver correctly but I am stuck working out how to resolve this. Can anyone help me fix this?
My AppConfig:
@Autowired
private Environment env;
@Autowired
private BeanFactory springContextBeanFactory;
@Bean
public DefaultJmsListenerContainerFactory myListenerContainerFactory() throws NamingException {
Properties props = new Properties();
props.setProperty(Context.INITIAL_CONTEXT_FACTORY, env.getProperty("java.naming.factory.initial"));
props.setProperty(Context.PROVIDER_URL, env.getProperty("java.naming.provider.url"));
props.setProperty(Context.SECURITY_PRINCIPAL, env.getProperty("java.naming.security.principal"));
props.setProperty(Context.SECURITY_CREDENTIALS, env.getProperty("java.naming.security.credentials"));
Context jndiContext = new InitialContext(props);;
ConnectionFactory connectionFactory = (ConnectionFactory) jndiContext.lookup("ConnectionFactory");
DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
factory.setConnectionFactory(connectionFactory);
factory.setDestinationResolver(new BeanFactoryDestinationResolver(springContextBeanFactory));
factory.setPubSubDomain(true);
factory.setSessionAcknowledgeMode(Session.AUTO_ACKNOWLEDGE);
return factory;
}
The listener:
@JmsListener(containerFactory = "myListenerContainerFactory", destination = "topic.FromJndiProperties")
public void receiveMessage(String message) {
try {
System.out.println("Received <" + message + ">");
} catch (Exception e) {
e.printStackTrace();
}
}