How to set a dispatch rate to ActiveMQ queue

219 views Asked by At

Given a queue in ActiveMQ with 50+ consumers, Is there a way to dispatch at the most 1 event per second to consumer? This is to control a flood of events dispatch.

Event producers are outside my application. Hence I need to handle the controlled dispatch from consumers side.
I have a jms prefetch policy configured to as low as 5. I do not want to dispatch 100's of messages to consumers in a span of few seconds. Instead I want it to be a steady flow.

How do I configure the Queue consumers to dispatch in a controlled flow?

1

There are 1 answers

0
Petter Nordlander On

As far as I know, there is no way to throttle the Consumers.

What you can do is to limit the flow to the consumer queue using built in Camel-routes. Maybe you can find a way to use this feature for your case?

  1. copy examples/camel.xml to your conf folder.
  2. edit the connection factory in the camel.xml file. In a default setup, change broker uri to vm://localhost?create=false
  3. include camel.xml in your activemq.xml <include resource="camel.xml"/>

Edit the route in camel.xml to something like this (1msg/1000ms)

    <route>
        <description>Throttler 1 msg/s</description>
        <from uri="activemq:msgs.in"/>
        <throttle timePeriodMillis="1000" asyncDelayed="true">
          <constant>1</constant>
          <to uri="activemq:msgs.out"/>
        </throttle>
    </route>