2014/1/16 Ilya Kazakevich <[email protected]>: > Hello, > >>-----Original Message----- >>From: Jose María Zaragoza [mailto:[email protected]] >>Sent: Thursday, January 16, 2014 11:30 PM >>To: users >>Subject: Re: Connect ApacheMQ with web application using JMS > .... >>A Connection is thread safe, but Sessions, MessageProducers, and >>MessageConsumers are not. The recommended strategy is to use one Session > per >>application thread. > > Thank you. > So, I can store session and consumer in HTTP session and synchronize access > to it (to prevent access from several browser tabs), right? > Would not it be too heavy to have 200 sessions and 400 consumers (for 200 > users)? > > Or should I get all messages in one thread and then pass them to user > threads? > > Ilya. >
I think that browser tabs share HTTP session Anyway, I think that if you 've got 200 concurrent users , you can create 200 JMS sessions.Why not ? Is it so much 200 threads ? Tomcat does it to manages HTTP requests And AMQ PooledConnectionFactory has got several caches . For example, cache by sessions per connection. You could be create a shared consumer (singleton) and this consumer would notify to every session when a message arrives. And then, every session should check either this message is for it or not. I think that this could be slow if there are a lot of messages IMHO, I would get a connection from PooledConnectionFactory and I would create new consumer per user-session. And every consumer could subscribe with a selector ( ie, username='Mary' ) And in this case, you could use only one topic . If you want to send a message to some user, create a message with this selector and send it to the topic So, each onMessage() of every consumer ( remember, one per user-session ) would receive its messages It's up to you Regards
