2
votes

After trying to activate priority with activemq, I was told to try using camel (see here). But I can't get it working, and I'm not even sure how it should work.

I've added the following code, in my spring configuration:

<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
  <route>
    <from uri="jms:queue:myqueue" />
    <resequence>
      <batch-config batchSize="200" batchTimeout="3000" allowDuplicates="true" reverse="true"/>
      <header>JMSPriority</header>
    <to uri="mock:result"/>
    </resequence>
   </route>
</camelContext>

<bean id="jmsConfig" class="org.apache.camel.component.activemq.ActiveMQConfiguration">
  <property name="connectionFactory" ref="pooledConnectionFactory"/>
  <property name="transacted" value="false"/>
  <property name="concurrentConsumers" value="10"/>
</bean>

<bean id="activemq" class="org.apache.camel.component.activemq.ActiveMQComponent">
  <property name="configuration" ref="jmsConfig"/>
</bean>

But this configuration doesn't work (nothing is ordered), and I have a few questions:

  • What does mock:result mean? I couldn't find it in the documentation.
  • How is camel supposed to re-order the queue, is it done after the messages were created, or when a message is added?
  • Can it be independent from the spring activemq basic configuration? (I use here the camel ActiveMQComponent)
1
why are you using camel anyway ?Pujan

1 Answers

1
votes

First, a mock endpoint is for unit testing. You can use it to validate that the expected messages were received:

MockEndpoint resultEndpoint = context.resolveEndpoint("mock:result", MockEndpoint.class);
resultEndpoint.expectedMessageCount(3);
resultEndpoint.expectedBodiesReceived("firstMessageBody", "secondMessageBody", "thirdMessageBody");
resultEndpoint.message(0).header("foo").isEqualTo("bar"); 

Next, the resequencer is designed to order messages based on some attribute (the header "JMSPriority" in your case) and will perform this over all messages that flow through it over a given timeout period or batch size (by default, the batch size is 100 and the timeout is 1000 ms).

Long story short, you can use the resequencer to order messages (in batches) before they are sent to the queue, in between queues or in between a queue and a consumer...