0

I have a single instance of ActiveMQ and a producer is pushing data to a queue. Currently, we have a single consumer with concurrency set as 1-5 which was developed using Spring Boot. Now I ran the same Spring Boot application (Consumer) in different ports to scale out the consumers. When I checked the logs, only one consumer is receiving the message and another consumer (which is a replica of the other) is not receiving any messages from that queue.

Please find the consumer code below

    public JmsListenerContainerFactory<?> orderEventListenerFactory(ConnectionFactory connectionFactory,
            DefaultJmsListenerContainerFactoryConfigurer configurer) {
        DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
        factory.setConcurrency("1-5");
        factory.setSessionAcknowledgeMode(javax.jms.Session.CLIENT_ACKNOWLEDGE);
        configurer.configure(factory, connectionFactory);
        return factory;
    }

    @JmsListener(destination = "order_queue?consumer.prefetchSize=1", containerFactory = "orderEventListenerFactory")
    @Override
    public void consumeOrderEvent(String event) {
        // Some BL
    }

Do I need to configure something on the broker or consumer side so that messages will be consumed in round-robin fashion i.e. basically sharing the load between these two consumers? I tried setting prefetch equals to 1 but still whichever consumer starts first is receiving the messages.

CrazyCoder
  • 2,465
  • 8
  • 36
  • 57
  • @JustinBertram What I meant is another consumer is not receiving any messages. All the messages were received by the consumer which was started first and second consumer were not receiving any messages from the broker. – CrazyCoder Aug 12 '21 at 17:01
  • @JustinBertram I have reworded the question now. – CrazyCoder Aug 13 '21 at 10:45
  • Have you tried setting the prefetch configuration on the URL rather than the destination, e.g. `tcp://localhost:61616?jms.prefetchPolicy.all=1` – Justin Bertram Aug 13 '21 at 13:00
  • @CrazyCoder Did this resolve the issue? I am also observing something similar while using default prefetch settings whereby all metrics on one of the servers (CPU/Memory) seem to be very high while on the other server they are low suggesting majority of the messages could be processed by consumers running on only one server – Jacob Sep 14 '21 at 11:54
  • @Jacob Not yet. I am trying out few things so I will let you know once I have some working solution. – CrazyCoder Sep 28 '21 at 17:27

0 Answers0