On Tue, Jul 26, 2011 at 2:59 PM, Richard Kettelerij <richardkettele...@gmail.com> wrote: > Hi ghepardo, > > It's advisable to use the ExecuterServiceStrategy instead of starting your > own thread, see http://camel.apache.org/threading-model.html. That way your > component is ready for containers that don't support unmanaged threads (like > AppEngine or something like Websphere). >
As Richard said the ExecutorServiceStrategy allows end users to better control and plugin 3rd party thread pool providers. Likewise when using that Camel will ensures thread is given a consistent an unique name, so they are easier to spot in the logs. End users can as well configure the pattern for the name syntax Camel uses. Also when Camel shutdown, it ensures all thread pools is shutdown as well, to ensure no hanging resources etc. That is important when you run in containers and when doing hot deploys etc. > Futhermore since your keeping state is Subscriber thread-safe? > > Regards, > Richard > > On Tue, Jul 26, 2011 at 2:32 PM, ghepardo <e.gherard...@hotmail.com> wrote: > >> Hi, >> thanks for answering. I already went throught that pages. I will make my >> question more specific. >> >> Here is the code of my simple consumer: >> " >> public class CoherenceQueueConsumer extends DefaultConsumer implements >> Runnable { >> >> private final CoherenceQueueEndpoint queueEndpoint; >> private Subscriber subscription; >> >> public CoherenceQueueConsumer(CoherenceQueueEndpoint endpoint, >> Processor >> processor) { >> super(endpoint, processor); >> this.queueEndpoint = endpoint; >> log.info("CoherenceQueueConsumer succesfully created: " + >> this); >> } >> >> >> @Override >> protected void doStart() throws Exception { >> super.doStart(); >> MessagingSession session = >> this.queueEndpoint.getMessagingSession(); >> this.subscription = >> session.subscribe(this.queueEndpoint.getQueueIdentifier()); >> this.subscription.setAutoCommit(false); >> new Thread(this).start(); >> log.info("Consumer ["+this+"] started"); >> } >> >> >> @Override >> protected void doStop() throws Exception { >> this.subscription.unsubscribe(); >> log.info("Consumer ["+this+"] unsubscribed."); >> super.doStop(); >> } >> >> public void run() { >> this.consumeMessages(); >> } >> >> >> private void consumeMessages() { >> >> log.info("Consumer ["+this+"] is consuming messages..."); >> >> while(isRunAllowed()) { >> >> Object rawMessage = subscription.getMessage(); >> log.info("Received Message: [" +rawMessage+"]"); >> >> Exchange ex = getEndpoint().createExchange(); >> ex.getIn().setBody(rawMessage); >> >> try { >> getProcessor().process(ex); >> this.subscription.commit(); >> } catch (Exception e) { >> log.error("Exeception occurred consuming >> message", e); >> this.subscription.rollback(); >> } >> } >> >> } >> >> >> @Override >> public String toString() { >> return "CoherenceQueueConsumer [queueEndpoint=" + >> queueEndpoint + "]"; >> } >> >> >> } >> " >> >> As you can see, to start effectively receiving messages from the Oracle >> Coherence Queue, I start a new thread that calls the blocking method >> "subscription.getMessage()". >> >> My question is: is this approach correct ? Am I allowed to "rawly" create a >> new thread for each consumer or should I use the >> org.apache.camel.util.concurrent.ExecutorServiceHelper ? >> >> Thanks a lot. >> >> p.s. I am a volounter too, so I also don't have so much time ;) >> >> -- >> View this message in context: >> http://camel.465427.n5.nabble.com/Developing-Oracle-Coherence-3-7-Camel-Component-tp4618649p4634601.html >> Sent from the Camel Development mailing list archive at Nabble.com. >> > -- Claus Ibsen ----------------- FuseSource Email: cib...@fusesource.com Web: http://fusesource.com Twitter: davsclaus, fusenews Blog: http://davsclaus.blogspot.com/ Author of Camel in Action: http://www.manning.com/ibsen/