Search in sources :

Example 21 with ProducerTemplate

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);
}
Also used : ProducerTemplate(org.apache.camel.ProducerTemplate) Test(org.junit.Test)

Example 22 with ProducerTemplate

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();
}
Also used : ProducerTemplate(org.apache.camel.ProducerTemplate) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Example 23 with ProducerTemplate

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;
}
Also used : ProducerTemplate(org.apache.camel.ProducerTemplate) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 24 with 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();
}
Also used : ProducerTemplate(org.apache.camel.ProducerTemplate) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) SpringCamelContext(org.apache.camel.spring.SpringCamelContext)

Example 25 with ProducerTemplate

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();
}
Also used : ProducerTemplate(org.apache.camel.ProducerTemplate) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) SpringCamelContext(org.apache.camel.spring.SpringCamelContext)

Aggregations

ProducerTemplate (org.apache.camel.ProducerTemplate)130 Test (org.junit.Test)58 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)53 CamelContext (org.apache.camel.CamelContext)48 Exchange (org.apache.camel.Exchange)36 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)27 Deployment (org.activiti.engine.test.Deployment)16 RouteBuilder (org.apache.camel.builder.RouteBuilder)16 Processor (org.apache.camel.Processor)8 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)8 HashMap (java.util.HashMap)7 Task (org.activiti.engine.task.Task)7 Endpoint (org.apache.camel.Endpoint)7 File (java.io.File)6 ArrayList (java.util.ArrayList)5 Message (org.apache.camel.Message)4 List (java.util.List)3 ExecutorService (java.util.concurrent.ExecutorService)3 HistoricVariableInstance (org.activiti.engine.history.HistoricVariableInstance)3 ConsumerTemplate (org.apache.camel.ConsumerTemplate)3