2

When adding messages to a queue in an ActiveMQ broker where there is no subscriber the queue fills up and eventually the producer thread hangs, unable to publish any more messages.

In an attempt to resolve the problem I set an expiry on the messages, thinking that this would free up memory but unfortunately this doesn't work. Does anyone know how I can resolve the issue?

My broker ActiveMQ version is 5.7 and broker definition is:

<bean id="mqBroker" class="org.apache.activemq.broker.BrokerService" init-method="start" destroy-method="stop">
    <property name="brokerName" value = "mainBroker"/>
    <property name="persistent" value="false"/>
    <property name="useJmx" value="false"/>
    <property name="transportConnectorURIs">
        <list>
            <value>tcp://localhost:7000</value>
        </list>
    </property>
</bean>

Looking in JConsole when it's unable to publish any more messages to the broker the memory usage looks fine (0% usage) and expired count=published count.

The code I'm using to publish messages is with spring integration:

<jms:outbound-channel-adapter
    channel="jsonChannel"
    connection-factory="jmsConnectionFactory"
    pub-sub-domain="false"
    destination-name="MY_QUEUE"
    time-to-live="60000"
    wxplicit-qos-enabled="true" />
James
  • 1,720
  • 5
  • 29
  • 50

2 Answers2

3

The Broker does do periodic sweeps of the queues to discard expired messages. The question is what is happening to the expired messages. They are probably ending up in a DLQ given the configuration you have, so you might want to look into configuring the discarding policy to not add expired messages to a DLQ. Refer to the ActiveMQ documentation on the issue.

Tim Bish
  • 17,475
  • 4
  • 32
  • 42
0

Did you

  • use message.setJMSExpiration(...); for your javax.jms.Message or
  • set the 'time to live' property (which is designed for topic-publish, but can in special cases also be used for queues)

?

Mayoares
  • 1,234
  • 2
  • 13
  • 21
  • I've set the time to live to 60s - see code edit above. Also it might be worth noting that whilst messages are being produced successfull the ExpiredCount attribute on the queue in JConsole increments for each message after the expiry time (60s) – James Oct 02 '13 at 16:01