When I'm trying to listen through command line it works fine, but using Spring Boot it throws below error:

ERROR [org.springframework.jms.listener.DefaultMessageListenerContainer] (DefaultMessageListenerContainer-1) Could not refresh JMS Connection for destination 'wfQueue' - retrying using FixedBackOff{interval=5000, currentAttempts=44, maxAttempts=unlimited}. Cause: authentication failed javax.jms.JMSSecurityException: authentication failed 

This is my app class

@SpringBootApplication(scanBasePackages = {"com.source.lbm"}) public class EMSConsumerApp { public static main(String[] args){ run(EMSConsumerApp.class, args); } } 

This class configures definitions for JMS consumer

@EnableJMS @EnableTransactionManagement public abstract class SubscriberConfiguration { private final String url; private final String clientId; private final String username; private final String password; public SubscriberConfiguration(String url, String clientId, String username, String password) { this.url = url; this.clientId = clientId; this.username = username; this.password = password; } @Bean public DefaultJmsListenerContainerFactory jsmListenerContainerFactory(ConnectionFactory connectionFactory) { DefaultJmsListenerContainerFactory containerFactory = new DefaultJmsListenerContainerFactory(); containerFactory.setconnectionFactory(connectionFactory); containerFactory.setPubSubDomain(true); containerFactory.setSubscriptionDurable(true); containerFactory.setSessionTransacted(true); containerFactory.setAutoStartup(true); return containerFactory; } @Bean public ConnectionFactory jmsConnectionFactory() throws JMSException{ TibjmsXATopicConnectionFactory connectionFactory = new TibjmsXATopicConnectionFactory(); connectionFactory.setServerUrl(url); connectionFactory.setClientId(clientId); connectionFactory.setUserName(username); connectionFactory.setUserPassword(password); return connectionFactory; } } 

This sets configs for a subscriber

@Configuration public class LbmSubConfiguration extends SubscriberConfiguration { public LbmSubConfiguration( @Value("${ems.lbm.sub.url}") String emsUrl; @Value("${ems.lbm.sub.clientId}") String subClientId; @Value("${ems.lbm.sub.username}") String subUsername; @Value("${ems.lbm.sub.password}") String subPasword) { super(emsUrl,subClientId,subUsername,subPasword); } } 

This class listenes to ems and consumes messages

@Component public class LbmEventConsumer { @JmsListener(destination = "${ems.lbm.sub.destination}", containerFactory = "jmsListenerContainerFactory") public void onMessage(BytesMessage message){ System.out.println("Message " + message); } } 

Since these credentials work fine on command line there shouldn't be an issue with credentials. Possibly it's because I'm missing some configs (not sure though). Can you please help me figure out what's wrong with this?

6

2 Answers

Have a look at @JmsListener

@JmsListener(destination = "${ems.lbm.sub.destination}", containerFactory = "jmsListenerContainerFactory") 

There you have set "jmsListenerContainerFactory" change it to "jmsConnectionFactory"

@JmsListener(destination = "${ems.lbm.sub.destination}", containerFactory = "jmsConnectionFactory") 

This code will work fine, I missed to add SubscriberConfiguration's package in scanBasePackage config.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.