Search code examples
apache-camelactivemq-classicinterceptor

Intercept ActiveMQ message with Camel


I need to register the time a message leaves ActiveMQs queue. I have Q1 and the consumer is a java application on Jboss server through activemq-ra.rar.

Is it possible to do that with Camel (included in ActiveMQ) interceptor? I am not programmer, so solution in XML DSL will be perfect.

Any help would be appreciated. thanx.


Solution

  • Using advisoryForConsumed and forwarding the advisory messages to a queue solved the problem for me.

    In activemq.xml:

    <destinationPolicy>
        <policyMap>
            <policyEntries>
                <policyEntry queue="Q1" advisoryForConsumed="true"/>
            </policyEntries>
        </policyMap>
    </destinationPolicy>
    

    then forwarding ActiveMQ.Advisory.MessageConsumed.Queue.Q1 to another queue, AvisoryConsumed.

    <destinationInterceptors> 
        <virtualDestinationInterceptor> 
            <virtualDestinations> 
                <compositeTopic name="ActiveMQ.Advisory.MessageConsumed.Queue.Q1" >
                    <forwardTo><queue physicalName="AvisoryConsumed" /> </forwardTo>
            </compositeTopic>
        </virtualDestinations>
    </virtualDestinationInterceptor>
    

    then when a message is consumed, there will be a message with brokerOutTime in AvisoryConsumed and the original message's properties.