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();
}
Aggregations