Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
185 views
in Technique[技术] by (71.8m points)

java - ActiveMQ Listener not listening even though push to the queue is success

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...