use of org.apache.camel.ConsumerTemplate in project camel by apache.
the class FileConsumePollEnrichFileUsingProcessorTest method createRouteBuilder.
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
from("file://target/enrich?move=.done").process(new Processor() {
public void process(Exchange exchange) throws Exception {
String name = exchange.getIn().getHeader(Exchange.FILE_NAME_ONLY, String.class);
name = FileUtil.stripExt(name) + ".dat";
// use a consumer template to get the data file
Exchange data = null;
ConsumerTemplate con = exchange.getContext().createConsumerTemplate();
try {
// try to get the data file
data = con.receive("file://target/enrichdata?move=.done&fileName=" + name, 5000);
} finally {
// stop the consumer as it does not need to poll for files anymore
con.stop();
}
// if we found the data file then process it by sending it to the direct:data endpoint
if (data != null) {
template.send("direct:data", data);
} else {
// otherwise do a rollback
throw new CamelExchangeException("Cannot find the data file " + name, exchange);
}
}
}).to("mock:start");
from("direct:data").to("mock:result");
}
};
}
use of org.apache.camel.ConsumerTemplate in project camel by apache.
the class DefaultConsumerTemplateTest method testCacheConsumers.
public void testCacheConsumers() throws Exception {
ConsumerTemplate template = new DefaultConsumerTemplate(context);
template.setMaximumCacheSize(500);
template.start();
assertEquals("Size should be 0", 0, template.getCurrentCacheSize());
// test that we cache at most 500 consumers to avoid it eating to much memory
for (int i = 0; i < 503; i++) {
Endpoint e = context.getEndpoint("direct:queue:" + i);
template.receiveNoWait(e);
}
// the eviction is async so force cleanup
template.cleanUp();
assertEquals("Size should be 500", 500, template.getCurrentCacheSize());
template.stop();
// should be 0
assertEquals("Size should be 0", 0, template.getCurrentCacheSize());
}
use of org.apache.camel.ConsumerTemplate in project camel by apache.
the class DefaultConsumerTemplateTest method testCacheConsumersFromContext.
public void testCacheConsumersFromContext() throws Exception {
ConsumerTemplate template = context.createConsumerTemplate(500);
assertEquals("Size should be 0", 0, template.getCurrentCacheSize());
// test that we cache at most 500 consumers to avoid it eating to much memory
for (int i = 0; i < 503; i++) {
Endpoint e = context.getEndpoint("direct:queue:" + i);
template.receiveNoWait(e);
}
// the eviction is async so force cleanup
template.cleanUp();
assertEquals("Size should be 500", 500, template.getCurrentCacheSize());
template.stop();
// should be 0
assertEquals("Size should be 0", 0, template.getCurrentCacheSize());
}
use of org.apache.camel.ConsumerTemplate in project camel by apache.
the class CamelAutoConfiguration method consumerTemplate.
/**
* Default consumer template for the bootstrapped Camel context.
*/
@Bean(initMethod = "", destroyMethod = "")
// Camel handles the lifecycle of this bean
@ConditionalOnMissingBean(ConsumerTemplate.class)
ConsumerTemplate consumerTemplate(CamelContext camelContext, CamelConfigurationProperties config) throws Exception {
final ConsumerTemplate consumerTemplate = camelContext.createConsumerTemplate(config.getConsumerTemplateCacheSize());
camelContext.addService(consumerTemplate);
return consumerTemplate;
}
use of org.apache.camel.ConsumerTemplate in project camel by apache.
the class ConsumerTemplateAlreadyExistTest method testHasExistingTemplate.
@Test
public void testHasExistingTemplate() {
assertNotNull("Should have injected a consumer template", template);
ConsumerTemplate lookup = context.getRegistry().lookupByNameAndType("myConsumerTemplate", ConsumerTemplate.class);
assertNotNull("Should lookup consumer template", lookup);
ConsumerTemplate lookup2 = context.getRegistry().lookupByNameAndType("consumerTemplate", ConsumerTemplate.class);
assertNull("Should not be able to lookup consumer template", lookup2);
}
Aggregations