Search in sources :

Example 1 with DefaultProducerTemplate

use of org.apache.camel.impl.DefaultProducerTemplate in project camel by apache.

the class AbstractCamelProducerTemplateFactoryBean method getObject.

public ProducerTemplate getObject() throws Exception {
    CamelContext context = getCamelContext();
    if (defaultEndpoint != null) {
        Endpoint endpoint = context.getEndpoint(defaultEndpoint);
        if (endpoint == null) {
            throw new IllegalArgumentException("No endpoint found for URI: " + defaultEndpoint);
        } else {
            template = new DefaultProducerTemplate(context, endpoint);
        }
    } else {
        template = new DefaultProducerTemplate(context);
    }
    // set custom cache size if provided
    if (maximumCacheSize != null) {
        template.setMaximumCacheSize(maximumCacheSize);
    }
    // must start it so its ready to use
    ServiceHelper.startService(template);
    return template;
}
Also used : CamelContext(org.apache.camel.CamelContext) Endpoint(org.apache.camel.Endpoint) DefaultProducerTemplate(org.apache.camel.impl.DefaultProducerTemplate)

Example 2 with DefaultProducerTemplate

use of org.apache.camel.impl.DefaultProducerTemplate in project camel by apache.

the class DisruptorConcurrentTest method testDisruptorConcurrentInOutWithAsync.

@Test
public void testDisruptorConcurrentInOutWithAsync() throws Exception {
    final MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(20);
    mock.allMessages().body().startsWith("Bye");
    // should at least take 3 sec
    mock.setMinimumResultWaitTime(3000);
    // use our own template that has a higher thread pool than default camel that uses 5
    final ExecutorService executor = Executors.newFixedThreadPool(10);
    final ProducerTemplate pt = new DefaultProducerTemplate(context, executor);
    // must start the template
    pt.start();
    final List<Future<Object>> replies = new ArrayList<Future<Object>>(20);
    for (int i = 0; i < 20; i++) {
        final Future<Object> out = pt.asyncRequestBody("disruptor:bar", "Message " + i);
        replies.add(out);
    }
    assertMockEndpointsSatisfied();
    assertEquals(20, replies.size());
    for (int i = 0; i < 20; i++) {
        final String out = (String) replies.get(i).get();
        assertTrue(out.startsWith("Bye"));
    }
    pt.stop();
    executor.shutdownNow();
}
Also used : ProducerTemplate(org.apache.camel.ProducerTemplate) DefaultProducerTemplate(org.apache.camel.impl.DefaultProducerTemplate) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) ExecutorService(java.util.concurrent.ExecutorService) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) DefaultProducerTemplate(org.apache.camel.impl.DefaultProducerTemplate) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Example 3 with DefaultProducerTemplate

use of org.apache.camel.impl.DefaultProducerTemplate in project camel by apache.

the class RouteboxDefaultContextAndRouteBuilderTest method testRouteboxUsingDefaultContextAndRouteBuilder.

@Test
public void testRouteboxUsingDefaultContextAndRouteBuilder() throws Exception {
    template = new DefaultProducerTemplate(context);
    template.start();
    context.addRoutes(new RouteBuilder() {

        public void configure() {
            from(routeboxUri).to("log:Routes operation performed?showAll=true");
        }
    });
    context.start();
    LOG.debug("Beginning Test ---> testRouteboxUsingDefaultContextAndRouteBuilder()");
    Book book = new Book("Sir Arthur Conan Doyle", "The Adventures of Sherlock Holmes");
    String response = sendAddToCatalogRequest(template, routeboxUri, "addToCatalog", book);
    assertEquals("Book with Author " + book.getAuthor() + " and title " + book.getTitle() + " added to Catalog", response);
    book = sendFindBookRequest(template, routeboxUri, "findBook", "Sir Arthur Conan Doyle");
    LOG.debug("Received book with author {} and title {}", book.getAuthor(), book.getTitle());
    assertEquals("The Adventures of Sherlock Holmes", book.getTitle());
    LOG.debug("Completed Test ---> testRouteboxUsingDefaultContextAndRouteBuilder()");
    context.stop();
}
Also used : SimpleRouteBuilder(org.apache.camel.component.routebox.demo.SimpleRouteBuilder) RouteBuilder(org.apache.camel.builder.RouteBuilder) Book(org.apache.camel.component.routebox.demo.Book) DefaultProducerTemplate(org.apache.camel.impl.DefaultProducerTemplate) Test(org.junit.Test)

Example 4 with DefaultProducerTemplate

use of org.apache.camel.impl.DefaultProducerTemplate in project camel by apache.

the class ProducerTemplateMixedAutoRegisterTwoCamelContextsTest method testHasTemplateCamel1.

@Test
public void testHasTemplateCamel1() {
    DefaultProducerTemplate lookup = context1.getRegistry().lookupByNameAndType("template1", DefaultProducerTemplate.class);
    assertNotNull("Should lookup producer template", lookup);
    assertEquals("camel1", lookup.getCamelContext().getName());
}
Also used : DefaultProducerTemplate(org.apache.camel.impl.DefaultProducerTemplate) Test(org.junit.Test)

Example 5 with DefaultProducerTemplate

use of org.apache.camel.impl.DefaultProducerTemplate in project camel by apache.

the class ProducerTemplateMixedAutoRegisterTwoCamelContextsTest method testHasTemplateCamel2.

@Test
public void testHasTemplateCamel2() {
    DefaultProducerTemplate lookup = context1.getRegistry().lookupByNameAndType("template2", DefaultProducerTemplate.class);
    assertNotNull("Should lookup producer template", lookup);
    assertEquals("camel2", lookup.getCamelContext().getName());
}
Also used : DefaultProducerTemplate(org.apache.camel.impl.DefaultProducerTemplate) Test(org.junit.Test)

Aggregations

DefaultProducerTemplate (org.apache.camel.impl.DefaultProducerTemplate)11 Test (org.junit.Test)8 RouteBuilder (org.apache.camel.builder.RouteBuilder)5 Book (org.apache.camel.component.routebox.demo.Book)5 SimpleRouteBuilder (org.apache.camel.component.routebox.demo.SimpleRouteBuilder)5 ArrayList (java.util.ArrayList)2 ExecutorService (java.util.concurrent.ExecutorService)2 Future (java.util.concurrent.Future)2 ProducerTemplate (org.apache.camel.ProducerTemplate)2 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)2 CamelContext (org.apache.camel.CamelContext)1 Endpoint (org.apache.camel.Endpoint)1 DefaultConsumerTemplate (org.apache.camel.impl.DefaultConsumerTemplate)1