camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rwoolf <r...@rosswoolf.com>
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.

activemq.xml
<beans
  xmlns="http://www.springframework.org/schema/beans"
  xmlns:amq="http://activemq.apache.org/schema/core"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
  http://activemq.apache.org/schema/core
http://activemq.apache.org/schema/core/activemq-core.xsd
  http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd">

  
  <broker xmlns="http://activemq.apache.org/schema/core" useJmx="false">

    <persistenceFactory>
      <journalPersistenceAdapterFactory journalLogFiles="5"
dataDirectory="/home/ross/cmsqueue"/>
    </persistenceFactory>
    <transportConnectors>
      <transportConnector uri="vm://localhost"/>      
    </transportConnectors>
        
  </broker>
  <import resource="camel.xml"/>
</beans>

I have the following route in camel.xml.

<beans
   xmlns="http://www.springframework.org/schema/beans"  
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="
     http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd
     http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
  
    <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"/>
          </bean>
        </property>
    </bean>
     <camelContext id="camel" trace="true"
xmlns="http://camel.apache.org/schema/spring">
		<jmxAgent id="agent" createConnector="true"/>
        <route>
            <description>Example Camel Route</description>
            <from uri="activemq:eventQueue"/>
            <to uri="file:/home/ross/temp/camel2/"/>
        </route>
    </camelContext>
</beans>

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

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


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: http://camel.465427.n5.nabble.com/Having-problems-with-CamelContext-addRoutes-and-ActiveMQ-tp5768117p5769700.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Mime
View raw message