-
1. Re: Re-using of HornetQ Core API Objects
clebert.suconic Sep 7, 2011 1:59 PM (in response to dro_k)- You should keep at least one ServerLocator (with the latest version)
- Cache your ClientSessionFactory
- You need a ClientSession per thread.
And mainly, cache your ClientConsumer. If you create a consumer every time you receive a message, it means you are doing a round trip, adding a collection on the Queue, receiving the message, and then doing another round trip to close the consumer, remove it from the queue and retransmit cached messages on the client. It really sucks if you do that! (that's a valid optimization for any message system you chose, it's nothing specific for HornetQ).
-
2. Re: Re-using of HornetQ Core API Objects
dro_k Sep 7, 2011 2:02 PM (in response to clebert.suconic)Thanks Clebert.How about the ClientConsumer and ClientProducer, I assume one per thread too, right?
-
3. Re: Re-using of HornetQ Core API Objects
clebert.suconic Sep 7, 2011 2:16 PM (in response to dro_k)ClientConsumer and ClientPRoducer belong to a session, so yes.
-
4. Re: Re-using of HornetQ Core API Objects
dro_k Sep 7, 2011 7:58 PM (in response to clebert.suconic)Just to clarify something. The reason you're saying the ClientSession is per thread, is for thread safety right not beacause it uses ThreadLocal?
What I mean, is that let's say that I have a Runnable class and I have a guarantee that only one instance of this Runnable class will be running at each time, using ScheduledExecutorService. Can I cache the ClientSession in the Runnable class, or do I have to create a new ClientSession on each run?
-
5. Re: Re-using of HornetQ Core API Objects
clebert.suconic Sep 8, 2011 12:03 AM (in response to dro_k)Right... it's just because Clientsession is not thread safe.. if you use it among multi threads like it was a single thread (through executors for instance) it's fine. We don't use ThreadLocal or anything like that.
-
6. Re: Re-using of HornetQ Core API Objects
dro_k Sep 8, 2011 1:38 AM (in response to clebert.suconic)Thanks Clebert.