I think the doc says it clearly. Every example in hornetq should follow the rule, although many of them only send/receive one message. I found there is a 'perf' example that sends mulitple messages. You can take a look.
I checked up the perf example and i see it does send messages twice but there is a anti-pattern used there itself as the code says whenever we are sending message a new factory and producer is created. I would like to know how can we avoid this antipattern of creating new producers everytime
i have a new message in a new thread.
To put it in different manner. Each of my threads generate a object which i need to put in queue. Right now i am creating a new session for each of them(I have a single instance of factory for all of them-- from which i create session). But the book says its an anti-pattern to create a session for each message. How can this be avoided. The problem is if i create one session for all of these threds then each session can cater to max of one thread at a time so all other threads would be blocking.
I hope you understand where i am going.
You just need to cache the object accordingly. How you do it, it will really depend on what you are doing.
If you have a single thread living, keep it there.
I will try and cache the session object. My only concern is the same session object will now be used across multiple threads to send data. Will try it out and see how the performce is.Thanks
You have to safely reuse it.
Example, a cached instance on a Servlet, but make its usage thread safe.
The performce improved drastically on using the same Session object for multiple producers. I am still using one Anti-pattern of creating multiple producer from single session....but the performance is better than multiple session. I am not sure if i can make the producer thread safe..but it seems ok for now..will update the thread is needed.