camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rwoolf <>
Subject Re: Having problems with CamelContext.addRoutes() and ActiveMQ
Date Tue, 21 Jul 2015 20:17:11 GMT
I have done as you said, and I use activemq.xml and import a camel.xml file
that defines the route.  But I still can't get things I put in the queue to
then be processed via the route.


  <broker xmlns="" useJmx="false">

      <journalPersistenceAdapterFactory journalLogFiles="5"
      <transportConnector uri="vm://localhost"/>      
  <import resource="camel.xml"/>

I have the following route in camel.xml.

    <bean id="queue" class="com.tybera.caseinfo.workflow.QueueManager" />
    <bean id="activemq"
class="org.apache.activemq.camel.component.ActiveMQComponent" >
        <property name="connectionFactory">
          <bean class="org.apache.activemq.ActiveMQConnectionFactory">
            <property name="brokerURL" value="vm://localhost?create=false"/>
     <camelContext id="camel" trace="true"
		<jmxAgent id="agent" createConnector="true"/>
            <description>Example Camel Route</description>
            <from uri="activemq:eventQueue"/>
            <to uri="file:/home/ross/temp/camel2/"/>

Then in Java code I have:
	public static void putToEventQueue(String eventName, String eventStatus,
			String eventMessage) {
		CamelContext context = new DefaultCamelContext();
		ProducerTemplate template = context.createProducerTemplate();
		template.sendBody("vm://localhost:eventQueue", eventMessage(
				eventName, eventStatus, eventMessage));
		try {
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block

Here is the init method:
	private static void init() {
		if (broker == null) {
			try {
				broker = BrokerFactory.createBroker("xbean:activemq.xml", true);
			} catch (Exception e) {
				// TODO Auto-generated catch block

The problem I am still struggling with is anything that I put into the queue
via the ProducerTemplate in the method putToEventQueue() code is never
visible by the route defined in the XML.  It is fundamentally the exact same
problem my original post indicated.

I want in my code to be able to put things into a queue via Java code.  I
want my code to post events into the queue, and then I want to be able to
deal with those events via the routes.  

If I use a ConsumerTemplate in Java code I can see and get the items in the
queue.  But trying to get the queue items via a route, it cannot see any
items in the queue.  It seems they are looking at different queues, but I
can't see anything in my code that would cause this.  I don't know how to
correct.  All examples of using the ProducerTemplate are very simple and the
indication is that I can use it to put things into a queue, but where I am
going wrong is what confuses me.  It seems like it should all be quite
simple and straight forward, but I can't get it to work.

I know I have things working in the sense that I can change the "from" in
the route from the queue to a file directory and things work in moving a
file from one directory to another.  Or, if in the java code I use both the
ProducerTemplate and another method using the ConsumerTemplate then I put
the message into the queue and get the message from the queue.  But if I use
the ProducerTemplate to put to the queue and try to get it using the route,
nothing happens.  It is as if they are each dealing with a different queue.  

Any help in understanding how I can use the ProducerTemplate to put into the
queue and then let the route take care of dealing with the items put into
the queue would be much appreciated.

View this message in context:
Sent from the Camel - Users mailing list archive at

View raw message