Created
May 29, 2012 13:05
-
-
Save tjsnell/2828273 to your computer and use it in GitHub Desktop.
ExecutorService method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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