use of org.apache.camel.ProducerTemplate in project camel by apache.
the class JmsInOutWithSpringRestartIssueTest method testRestartSpringIssue.
@Test
public void testRestartSpringIssue() throws Exception {
context.startRoute("foo");
ProducerTemplate producer = context.createProducerTemplate();
producer.start();
Object out = producer.requestBody("activemq:queue:foo", "Foo");
assertEquals("Bye Foo", out);
// on purpose forget to stop the producer and it should still work
context.stopRoute("foo");
context.startRoute("foo");
out = producer.requestBody("activemq:queue:foo", "Bar");
assertEquals("Bye Bar", out);
}
use of org.apache.camel.ProducerTemplate in project camel by apache.
the class KratiConsumerSpringTest method testPutAndConsume.
@Test
public void testPutAndConsume() throws InterruptedException {
ProducerTemplate template = context.createProducerTemplate();
template.sendBodyAndHeader("direct:put", "TEST1", KratiConstants.KEY, "1");
template.sendBodyAndHeader("direct:put", "TEST2", KratiConstants.KEY, "2");
template.sendBodyAndHeader("direct:put", "TEST3", KratiConstants.KEY, "3");
MockEndpoint endpoint = context.getEndpoint("mock:results", MockEndpoint.class);
endpoint.expectedMessageCount(3);
endpoint.assertIsSatisfied();
}
use of org.apache.camel.ProducerTemplate in project camel by apache.
the class CamelAutoConfiguration method producerTemplate.
/**
* Default producer template for the bootstrapped Camel context.
*/
@Bean(initMethod = "", destroyMethod = "")
// Camel handles the lifecycle of this bean
@ConditionalOnMissingBean(ProducerTemplate.class)
ProducerTemplate producerTemplate(CamelContext camelContext, CamelConfigurationProperties config) throws Exception {
final ProducerTemplate producerTemplate = camelContext.createProducerTemplate(config.getProducerTemplateCacheSize());
camelContext.addService(producerTemplate);
return producerTemplate;
}
use of org.apache.camel.ProducerTemplate in project camel by apache.
the class CamelContextAutoStartupTest method testAutoStartupFalse.
public void testAutoStartupFalse() throws Exception {
ac = new ClassPathXmlApplicationContext("org/apache/camel/spring/config/CamelContextAutoStartupTestFalse.xml");
SpringCamelContext camel = ac.getBeansOfType(SpringCamelContext.class).values().iterator().next();
assertNotNull(camel.getName());
assertEquals(true, camel.isStarted());
assertEquals(Boolean.FALSE, camel.isAutoStartup());
assertEquals(1, camel.getRoutes().size());
assertEquals(false, camel.getRouteStatus("foo").isStarted());
// now starting route manually
camel.startRoute("foo");
assertEquals(Boolean.FALSE, camel.isAutoStartup());
assertEquals(1, camel.getRoutes().size());
assertEquals(true, camel.getRouteStatus("foo").isStarted());
// and now we can send a message to the route and see that it works
MockEndpoint mock = camel.getEndpoint("mock:result", MockEndpoint.class);
mock.expectedMessageCount(1);
ProducerTemplate template = camel.createProducerTemplate();
template.start();
template.sendBody("direct:start", "Hello World");
template.stop();
mock.assertIsSatisfied();
}
use of org.apache.camel.ProducerTemplate in project camel by apache.
the class CamelContextAutoStartupTest method testAutoStartupTrue.
public void testAutoStartupTrue() throws Exception {
ac = new ClassPathXmlApplicationContext("org/apache/camel/spring/config/CamelContextAutoStartupTestTrue.xml");
SpringCamelContext camel = ac.getBeansOfType(SpringCamelContext.class).values().iterator().next();
assertNotNull(camel.getName());
assertEquals(true, camel.isStarted());
assertEquals(Boolean.TRUE, camel.isAutoStartup());
assertEquals(1, camel.getRoutes().size());
// send a message to the route and see that it works
MockEndpoint mock = camel.getEndpoint("mock:result", MockEndpoint.class);
mock.expectedMessageCount(1);
ProducerTemplate template = camel.createProducerTemplate();
template.start();
template.sendBody("direct:start", "Hello World");
template.stop();
mock.assertIsSatisfied();
}
Aggregations