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