Gary Xue
Gary Xue

Reputation: 153

How to prevent message from going to "Dispatched Queue"

I'm using ActiveMQ with the Spring framework.

I have two consumers setup in the JMS container. When I send 4 message to the queue, and some of the message are transferred to the "Dispatched Queue" because it takes a long time to the consumer to process the message.

I'm trying to find the way to prevent the message from going to the "Dispatched Queue". That is, I want them to be available to any consumer that is ready to consume the message.

I tried to set queuePrefetch to 0, but it doesn't seem to work at all.

    <bean id="prefetchPolicy" class="org.apache.activemq.ActiveMQPrefetchPolicy">
      <property name="queuePrefetch" value="0"/>
    </bean>

    <bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
      <constructor-arg index="0" value="tcp://localhost:61616" />
      <property name="prefetchPolicy" ref="prefetchPolicy"/>
    </bean>

The following is the setup for my JMS container:

        <bean id="jmsContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
            <property name="connectionFactory" ref="connectionFactory"/>
            <property name="destination" ref="defaultDestination" />
            <property name="messageListener" ref="messageListener" />
            <property name="concurrentConsumers" value="2" />
        </bean>

Upvotes: 1

Views: 2534

Answers (1)

Gary Xue
Gary Xue

Reputation: 153

I found the problem. I had the same beans declared twice at two different places. The second bean that was loaded did not have pre-fetch set to 0 and therefore it didn't work out.

The above setup I posted works!

Thank you!

Upvotes: 1

Related Questions