Skip to content

Instantly share code, notes, and snippets.

@tjsnell
Created May 29, 2012 13:05
Show Gist options
  • Save tjsnell/2828273 to your computer and use it in GitHub Desktop.
Save tjsnell/2828273 to your computer and use it in GitHub Desktop.
ExecutorService method
final RabbitMQConfiguration config = endpoint.getConfiguration();
int concurrentConsumers = endpoint.getConfiguration().getConcurrentConsumers();
ExecutorServiceManager manager = endpoint.getCamelContext().getExecutorServiceManager();
Runnable consumerRunner = new Runnable() {
@Override
public void run() {
try {
System.out.println("Launching: " + Thread.currentThread().getId());
Channel channel = createChannel();
MyConsumer myConsumer = new MyConsumer(channel);
channel.basicConsume(queueName, config.isAutoAck(), myConsumer);
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public String toString() {
return "AsyncStartListenerTask[" + queueName + "]";
}
};
ExecutorService executor = manager.newFixedThreadPool(consumerRunner, endpoint.getEndpointUri(), concurrentConsumers);
for (int i = 0; i < concurrentConsumers; i++) {
executor.execute(consumerRunner);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment