The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

solomon_13000 (34) [Avatar] Offline
#1
package org.test;
import org.apache.camel.builder.RouteBuilder;

public class DispatcherRouteBuilder extends RouteBuilder {
@Override
public void configure() throws Exception{
from("activemq:queue:EVENTS").to("log:Events?showAll=true");
}
}


---------------------------------------------------------------------------------------------------------------

package org.test;
import org.apache.activemq.broker.BrokerService;
import org.apache.camel.CamelContext;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

public class DispatcherRouteBuilderTest extends CamelTestSupport {

@Autowired
ProducerTemplate template;

@Override
protected RouteBuilder createRouteBuilder() throws Exception{
return new DispatcherRouteBuilder();
}
@BeforeClass
public void setUpClass() throws Exception{
BrokerService brokerSvc = new BrokerService();
brokerSvc.setBrokerName("TestBroker");
brokerSvc.setUseJmx(false);
brokerSvc.setPersistent(true);
brokerSvc.setDataDirectory("C:\Program Files\db");
brokerSvc.addConnector("tcp://localhost:61619");
brokerSvc.start();
System.out.println("Started");
}
@Test
public void testConfigure() throws Exception{
CamelContext context = super.createCamelContext();
template = context.createProducerTemplate();
System.out.println("Testing-1");
template.sendBody("activemq:queue:EVENTS","<hello>world!</hello>");
System.out.println("Testing-2");

}
}

My IDE was displaying the following information:


Sep 26, 2012 10:10:45 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [TestCamel.xml]
636 [main] INFO org.apache.activemq.store.kahadb.plist.PListStore - PListStore:Csmilierogram FilesdbTestBroker mp_storage started
647 [main] INFO org.apache.activemq.broker.BrokerService - Using Persistence Adapter: KahaDBPersistenceAdapter[Csmilierogram FilesdbTestBrokerKahaDB]
1374 [main] INFO org.apache.activemq.store.kahadb.MessageDatabase - KahaDB is version 3
1547 [main] INFO org.apache.activemq.store.kahadb.MessageDatabase - Recovering from the journal ...
1565 [main] INFO org.apache.activemq.store.kahadb.MessageDatabase - Recovery replayed 2 operations from the journal in 0.161 seconds.
1662 [main] INFO org.apache.activemq.broker.BrokerService - ActiveMQ 5.5.0 JMS Message Broker (TestBroker) is starting
1662 [main] INFO org.apache.activemq.broker.BrokerService - For help or more information please see: http://activemq.apache.org/
1962 [main] INFO org.apache.activemq.transport.TransportServerThreadSupport - Listening for connections at: tcp://127.0.0.1:61619
1962 [main] INFO org.apache.activemq.broker.TransportConnector - Connector tcp://127.0.0.1:61619 Started
2001 [main] INFO org.apache.activemq.broker.BrokerService - ActiveMQ JMS Message Broker (TestBroker, ID:Eugene-VAIO-52598-1348668647904-0:1) started
Started
Testing-1
2724 [main] INFO org.apache.camel.impl.converter.DefaultTypeConverter - Loaded 175 type converters
3230 [main] INFO org.apache.camel.management.ManagementStrategyFactory - JMX enabled.

------------------------------------------------------------------------------------------------------------------

It appears that at this like of the code:

template.sendBody("activemq:queue:EVENTS","<hello>world!</hello>");

the action is idle as in the 'Testing-2' is not displayed.
davsclaus (413) [Avatar] Offline
#2
Re: template.sendBody idle
In your test method you are creating CamelContext again. You should not do that, as the CamelTestSupport class already does this for you.
davsclaus (413) [Avatar] Offline
#3
Re: template.sendBody idle
Chapter 7 covers JMS. You may want to take a look at that, as the source code for this has examples with ActiveMQ, Camel and unit tests, eg how to do that.

And chapter 6 talks about testing, which would be a good read as well.