I have a Activemq configuration, to make certain code flow as asynchronous. But at times I am seeing that messages are posting to the queue, but listeners are not able to listen to it in this particular code flow and I am not seeing any error or exception.
ActiveMQ version: 5.16.0
Code that I am trying
FirstService.java {
@Transactional
public void myMethod() {
//doing some logic
calling secondSerivce.method1();
}
}
@Service
SecondService.java {
@Transactional
public method1() {
//doing some logic
//pushing data to the queue.
}
}
@Component
QueueProducer.java {
public queueMethod() {
jmsTemplate.convertAndSend(QUEUE_NAME, DATAS, m -> {
m.setObjectProperty("data1", data1);
});
}
}
@Component
QueueListener.java {
@JmsListener(destination = QUEUE_NAME, containerFactory = "jmsListenerContainerFactory")
public void listenToQueue(MessageHeaders messageHeaders, @Payload List<long[]> payload) {
//logic after getting the message
}
}
//JMS configuration class
@Configuration
@EnableJms
public class JmsConfiguration {
@Bean
public ActiveMQConnectionFactory receiverActiveMQConnectionFactory() {
ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory();
activeMQConnectionFactory.setBrokerURL(broker);
return activeMQConnectionFactory;
}
@Bean
public JmsListenerContainerFactory<?> jmsListenerContainerFactory(ConnectionFactory connectionFactory, DefaultJmsListenerContainerFactoryConfigurer configurer) {
DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
factory.setConcurrency("1-20");
configurer.configure(factory, connectionFactory);
return factory;
}
What I cannot understand is the same queueProducer class is being called from some other codes and its working as expected. But not this code flow and once the queue call is stuck then the other scenarios which were working before is getting stuck. Also noted that in the ActiveMq console, the number of pending messages are also 0. I tried restarting the queue and the application but issue still remained
The only difference between the other code and the above, is I am calling the queueProducer from the service call itself, that is within the same transaction and at other places I am calling the queueProducer outside the transaction.
I am not sure what i have done wrong. please help
question from:
https://stackoverflow.com/questions/65882146/activemq-listener-not-listening-even-though-push-to-the-queue-is-success 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…