Search in sources :

Example 11 with DefaultProducerTemplate

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

the class SedaConcurrentTest method testSedaConcurrentInOutWithAsync.

public void testSedaConcurrentInOutWithAsync() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(20);
    mock.allMessages().body().startsWith("Bye");
    // should at least take 3 sec
    mock.setResultMinimumWaitTime(3000);
    // use our own template that has a higher thread pool than default camel that uses 5
    ExecutorService executor = Executors.newFixedThreadPool(10);
    ProducerTemplate pt = new DefaultProducerTemplate(context, executor);
    // must start the template
    pt.start();
    List<Future<Object>> replies = new ArrayList<Future<Object>>(20);
    for (int i = 0; i < 20; i++) {
        Future<Object> out = pt.asyncRequestBody("seda:bar", "Message " + i);
        replies.add(out);
    }
    assertMockEndpointsSatisfied();
    assertEquals(20, replies.size());
    for (int i = 0; i < 20; i++) {
        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)

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