use of org.apache.camel.impl.DefaultScheduledPollConsumerScheduler in project camel by apache.
the class SqsEndpoint method createConsumer.
public Consumer createConsumer(Processor processor) throws Exception {
SqsConsumer sqsConsumer = new SqsConsumer(this, processor);
configureConsumer(sqsConsumer);
sqsConsumer.setMaxMessagesPerPoll(maxMessagesPerPoll);
DefaultScheduledPollConsumerScheduler scheduler = new DefaultScheduledPollConsumerScheduler();
scheduler.setConcurrentTasks(configuration.getConcurrentConsumers());
sqsConsumer.setScheduler(scheduler);
return sqsConsumer;
}
use of org.apache.camel.impl.DefaultScheduledPollConsumerScheduler in project camel by apache.
the class IronMQEndpoint method createConsumer.
public Consumer createConsumer(Processor processor) throws Exception {
IronMQConsumer ironMQConsumer = new IronMQConsumer(this, processor, getClient().queue(configuration.getQueueName()));
configureConsumer(ironMQConsumer);
ironMQConsumer.setMaxMessagesPerPoll(configuration.getMaxMessagesPerPoll());
DefaultScheduledPollConsumerScheduler scheduler = new DefaultScheduledPollConsumerScheduler();
scheduler.setConcurrentTasks(configuration.getConcurrentConsumers());
ironMQConsumer.setScheduler(scheduler);
return ironMQConsumer;
}
use of org.apache.camel.impl.DefaultScheduledPollConsumerScheduler in project camel by apache.
the class HdfsConsumerTest method testReadWithReadSuffix.
@Test
public void testReadWithReadSuffix() throws Exception {
if (!canTest()) {
return;
}
String[] beforeFiles = new File("target/test").list();
int before = beforeFiles != null ? beforeFiles.length : 0;
final Path file = new Path(new File("target/test/test-camel-boolean").getAbsolutePath());
Configuration conf = new Configuration();
FileSystem fs1 = FileSystem.get(file.toUri(), conf);
SequenceFile.Writer writer = createWriter(fs1, conf, file, NullWritable.class, BooleanWritable.class);
NullWritable keyWritable = NullWritable.get();
BooleanWritable valueWritable = new BooleanWritable();
valueWritable.set(true);
writer.append(keyWritable, valueWritable);
writer.sync();
writer.close();
context.addRoutes(new RouteBuilder() {
public void configure() {
from("hdfs:localhost/" + file.getParent().toUri() + "?scheduler=#myScheduler&pattern=*&fileSystemType=LOCAL&fileType=SEQUENCE_FILE&initialDelay=0&readSuffix=handled").to("mock:result");
}
});
ScheduledExecutorService pool = context.getExecutorServiceManager().newScheduledThreadPool(null, "unitTestPool", 1);
DefaultScheduledPollConsumerScheduler scheduler = new DefaultScheduledPollConsumerScheduler(pool);
((JndiRegistry) ((PropertyPlaceholderDelegateRegistry) context.getRegistry()).getRegistry()).bind("myScheduler", scheduler);
context.start();
MockEndpoint resultEndpoint = context.getEndpoint("mock:result", MockEndpoint.class);
resultEndpoint.expectedMessageCount(1);
resultEndpoint.assertIsSatisfied();
// synchronize on pool that was used to run hdfs consumer thread
scheduler.getScheduledExecutorService().shutdown();
scheduler.getScheduledExecutorService().awaitTermination(5000, TimeUnit.MILLISECONDS);
Set<String> files = new HashSet<String>(Arrays.asList(new File("target/test").list()));
// there may be some leftover files before, so test that we only added 2 new files
assertThat(files.size() - before, equalTo(2));
assertTrue(files.remove("test-camel-boolean.handled"));
assertTrue(files.remove(".test-camel-boolean.handled.crc"));
}
use of org.apache.camel.impl.DefaultScheduledPollConsumerScheduler in project camel by apache.
the class HdfsConsumerTest method testReadWithReadSuffix.
@Test
public void testReadWithReadSuffix() throws Exception {
if (!canTest()) {
return;
}
String[] beforeFiles = new File("target/test").list();
int before = beforeFiles != null ? beforeFiles.length : 0;
final Path file = new Path(new File("target/test/test-camel-boolean").getAbsolutePath());
Configuration conf = new Configuration();
SequenceFile.Writer writer = createWriter(conf, file, NullWritable.class, BooleanWritable.class);
NullWritable keyWritable = NullWritable.get();
BooleanWritable valueWritable = new BooleanWritable();
valueWritable.set(true);
writer.append(keyWritable, valueWritable);
writer.sync();
writer.close();
context.addRoutes(new RouteBuilder() {
public void configure() {
from("hdfs2:localhost/" + file.getParent().toUri() + "?scheduler=#myScheduler&pattern=*&fileSystemType=LOCAL&fileType=SEQUENCE_FILE&initialDelay=0&readSuffix=handled").to("mock:result");
}
});
ScheduledExecutorService pool = context.getExecutorServiceManager().newScheduledThreadPool(null, "unitTestPool", 1);
DefaultScheduledPollConsumerScheduler scheduler = new DefaultScheduledPollConsumerScheduler(pool);
((JndiRegistry) ((PropertyPlaceholderDelegateRegistry) context.getRegistry()).getRegistry()).bind("myScheduler", scheduler);
context.start();
MockEndpoint resultEndpoint = context.getEndpoint("mock:result", MockEndpoint.class);
resultEndpoint.expectedMessageCount(1);
resultEndpoint.assertIsSatisfied();
// synchronize on pool that was used to run hdfs consumer thread
scheduler.getScheduledExecutorService().shutdown();
scheduler.getScheduledExecutorService().awaitTermination(5000, TimeUnit.MILLISECONDS);
Set<String> files = new HashSet<String>(Arrays.asList(new File("target/test").list()));
// there may be some leftover files before, so test that we only added 2 new files
assertThat(files.size() - before, equalTo(2));
assertTrue(files.remove("test-camel-boolean.handled"));
assertTrue(files.remove(".test-camel-boolean.handled.crc"));
}
Aggregations