3
votes

I have two AMQ queues that have the same consumers. The first queue (Q1) handles 97% of the messages and the other (Q2) only 3%. Problem is that messages in Q2 need to process messages as soon as they are queued. So my problem is that when a message is available in Q2 I need somehow to suspend the first route to take it's consumers. The apache camel routing looks like this:

<route id="q1">
    <from uri="jms:recordAnalysisRequests" />
    <to uri="bean:analysisService" />
</route>
<route id="q2">
    <from uri="jms:recordAnalysisRequestsFastTrack" />
    <to uri="bean:analysisService" />
</route>

What strategy should use? I don't think I can use resequencer because Q1 could have thousands of messages queued up and I cannot fit all in a resequencer batch. I was looking at the route throttling but I cannot figure out how to do it. Also I was wondering if I can synchronize through a zookeeper node. Again I will need some guidance here if this solution is viable.

1
Please note that tags stand alone. That is, you can't combine multiple tags to create a single concept. The tags [apache] and [camel] together aren't the same thing as the single [apache-camel] tag. Always be sure to read the descriptions that appear when selecting tags! - Charles

1 Answers

3
votes

You could place all messages in a single queue and use message priority http://activemq.apache.org/how-can-i-support-priority-queues.html

Second option, use a Camel Resequencer

<route id="q1">
    <from uri="jms:recordAnalysisRequests" />
    <setHeader headerName="CustomPriority">
       <constant>2</constant>       
    </setHeader>
    <to uri="direct:analysisDirect" />
</route>
<route id="q2">
    <from uri="jms:recordAnalysisRequestsFastTrack" />
    <setHeader headerName="CustomPriority">
       <constant>1</constant>       
    </setHeader>
    <to uri="direct:analysisDirect" />
</route>
<route id="q3">
    <from uri="direct:analysisDirect">
    <resequence>
        <header>CustomPriority</header>
        <to uri="bean:analysisService" />
    </resequence>
</route>

Third option (Camel 2.12), insteads of using a resequencer, use a SEDA endpoint with a PriorityBlockingQueue https://camel.apache.org/seda.html#SEDA-ChoosingBlockingQueueimplementation