use of org.apache.camel.Processor 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.Processor in project camel by apache.
the class TwoSchedulerConcurrentTasksOneRouteTest method createRouteBuilder.
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
public void configure() {
// number of concurrent task a thread pool should have
SchedulerComponent comp = context.getComponent("scheduler", SchedulerComponent.class);
comp.setConcurrentTasks(2);
// let this route scheduler use all 2 concurrent tasks at the same time
from("scheduler://foo?delay=250&scheduler.concurrentTasks=2").process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
if (sleep.compareAndSet(true, false)) {
log.info("Thread is sleeping");
Thread.sleep(1000);
log.info("Thread is done sleeping");
}
}
}).to("log:done").to("mock:done");
}
};
}
use of org.apache.camel.Processor in project camel by apache.
the class RefComponentTest method bindToRegistry.
private void bindToRegistry(JndiRegistry jndi) throws Exception {
Component comp = new DirectComponent();
comp.setCamelContext(context);
Endpoint slow = comp.createEndpoint("direct:somename");
Consumer consumer = slow.createConsumer(new Processor() {
public void process(Exchange exchange) throws Exception {
template.send("mock:result", exchange);
}
});
consumer.start();
// bind our endpoint to the registry for ref to lookup
jndi.bind("foo", slow);
}
use of org.apache.camel.Processor in project camel by apache.
the class SedaEndpointTest method testSedaEndpoint.
public void testSedaEndpoint() throws Exception {
SedaEndpoint seda = new SedaEndpoint("seda://foo", context.getComponent("seda"), queue);
assertNotNull(seda);
assertEquals(1000, seda.getSize());
assertSame(queue, seda.getQueue());
assertEquals(1, seda.getConcurrentConsumers());
Producer prod = seda.createProducer();
seda.onStarted((SedaProducer) prod);
assertEquals(1, seda.getProducers().size());
Consumer cons = seda.createConsumer(new Processor() {
public void process(Exchange exchange) throws Exception {
// do nothing
}
});
seda.onStarted((SedaConsumer) cons);
assertEquals(1, seda.getConsumers().size());
assertEquals(0, seda.getExchanges().size());
}
use of org.apache.camel.Processor in project camel by apache.
the class SedaEndpointTest method testSedaEndpointUnboundedQueue.
public void testSedaEndpointUnboundedQueue() throws Exception {
BlockingQueue<Exchange> unbounded = new LinkedBlockingQueue<Exchange>();
SedaEndpoint seda = new SedaEndpoint("seda://foo", context.getComponent("seda"), unbounded);
assertNotNull(seda);
assertEquals(Integer.MAX_VALUE, seda.getSize());
assertSame(unbounded, seda.getQueue());
assertEquals(1, seda.getConcurrentConsumers());
Producer prod = seda.createProducer();
seda.onStarted((SedaProducer) prod);
assertEquals(1, seda.getProducers().size());
Consumer cons = seda.createConsumer(new Processor() {
public void process(Exchange exchange) throws Exception {
// do nothing
}
});
seda.onStarted((SedaConsumer) cons);
assertEquals(1, seda.getConsumers().size());
assertEquals(0, seda.getExchanges().size());
}
Aggregations