I am fairly new to Camel and had a question about what are the best practices for using Threads in Camel Routes. I have Camel in Action which is a great book; but when it came to Threading the book only showed how to configure Camel. It did not go into what happens behind the scenese. It also doesn't talk about what needs to happen with Processors, etc. I am hoping to get a little more detail in this Topic.
Camel Route Example: Spring Configuration <?xml version="1.0" encoding="UTF-8"?> RouteBuilder: public class SomeRouteBuilder extends RouteBuilder { private String fromQueue; private String toQueue; private Processor somProcessor; private ExecutorService threadPool; public String getFromQueue() { return fromQueue; } public void setFromQueue(String fromQueue) { this.fromQueue = fromQueue; } public String getToQueue() { return toQueue; } public void setToQueue(String toQueue) { this.toQueue = toQueue; } public Processor getSomeProcessor() { return someProcessor; } public void setSomeProcessor(Processor someProcessor) { this.someProcessor = someProcessor; } @Override public void configure() throws Exception { ThreadPoolBuilder builder = new ThreadPoolBuilder(getContext()); setThreadPool(builder.poolSize(1).maxPoolSize(10).maxQueueSize(100).build("somePool")); from(getFromQueue()).threads().executorService(getThreadPool()).process(getSomeProcessor()).to(getToQueue()); } } Processor: public class SomeProcessor implements Processor { @Override public void process(Exchange exchange) throws Exception { SomeClass someClassFromExchange = (SomeClass)exchange.getIn().getBody(); SomeClass someClassFromDb = lookupClassById(someClass.getId()); compareAndUpdate(someClassFromExchange, someClassFromDb); } private SomeClass lookupClassById(String id) { // Do a DB Lookup } private void compareAndUpdate(SomeClass someClassFromExchange, SomeClass someClassFromDb) { // Do some sort of comparison, and update 'someClassFromExchange' } } >From what I understand about Threading and Camel, there will be one instance of the Processor used between the Threads. This forces the Processor to use Thread Safe Classes/Techniques. I saw there was a ThreadProcessor object; should this be extended? Does the same Threading rules apply to a RouteBuilder configured using the Spring DSL? <?xml version="1.0" encoding="UTF-8"?> In order to avoid Threading problems: What if you wanted a separate instance of the Processor created for each Thread? Would it be best to not do any Threading at this time, but to create separate Camel Contexts in separate JVMs? If so, what if Camel lives within a Servlet Container. I have noticed that even though there are separate deployed WebApps (using Tomcat 7); the Camel Context IDs must be unique between the WebApps. What are some of the best practices for Threading Camel Routes to maximize throughput? Thanks, Peter -- View this message in context: http://camel.465427.n5.nabble.com/Best-Practice-fro-Thread-Safe-processor-tp4288973p4288973.html Sent from the Camel - Users mailing list archive at Nabble.com.