This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes EJB and other Java EE Technologies and the fly likes Statefulness using JMS Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Statefulness using JMS" Watch "Statefulness using JMS" New topic
Author

Statefulness using JMS

Mahesh Trikannad
Ranch Hand

Joined: Dec 14, 2004
Posts: 68
We plan to use JMS and MDB’s to create a certain service. We need to maintain state between methods, which means between the JMS messages.

To demonstrate using an example , Lets say the service has 2 methods login and book..
I get a JMS message for a login, the service consumes it, and returns a token. Now, I send a JMS message for book, in which I pass the token. I would like book to access the state of login.

I guess the short of it is, I am trying to figure out a way to create statefulness using JMS and MDB’s.

Appreciate ideas on this.

Mahesh Trikannad
Pallav Bora
Ranch Hand

Joined: Oct 13, 2009
Posts: 73
Some options that come to my mind..

1] Write something to a database.
2] Put something in Application Context.

-Pallav
Mahesh Trikannad
Ranch Hand

Joined: Dec 14, 2004
Posts: 68
I would prefer the database option, but it may not be an option for us.
Can you tell me more about Application Context.
Mahesh Trikannad
Ranch Hand

Joined: Dec 14, 2004
Posts: 68
Keep in mind , I may not have a servlet. Just JMS and MDB.
Anastasia Klimchuk
Greenhorn

Joined: Sep 21, 2011
Posts: 10
If the main interest is to return a token to client after login, then probably temporary queue can help?

In short, the idea is that client creates a TemporaryQueue that is associated with Connection object (exist only for this connection lifetime), and pass queue name in its "request" message.
MDB can send a "response" with login token (or whatever else), using this queue name. Client consumes the response.

The approach is described in more details here:
http://onjava.com/pub/a/onjava/2007/04/10/designing-messaging-applications-with-temporary-queues.html?page=1
Hope this could help!
Mahesh Trikannad
Ranch Hand

Joined: Dec 14, 2004
Posts: 68
It involves more than just login. There can be 5 or 8 messages , which need to maintain session data between them.

Looking to see how I can maintain session between session messages ( Besides the database approach )

Thanks

Mahesh
Vladimir Ozerov
Greenhorn

Joined: Sep 27, 2011
Posts: 14
Emm...what about stateful session beans? This is exactly what they are intended for.
Mahesh Trikannad
Ranch Hand

Joined: Dec 14, 2004
Posts: 68
Iam looking for a solution , with JMS.
Anastasia Klimchuk
Greenhorn

Joined: Sep 21, 2011
Posts: 10
What about a session data you mentioned, is it something huge or more like several attributes?

What about the following:
After certain client logged in, and recieved back a token from MDB, this token can later be passed to MDB as clientID with all the following messages that belong to the same "conversation".
Or it's possible to pass clientID + some other attribute.
So, session state would be identified by clientID.

Pallav, do you mean application context used by Spring?
Mahesh Trikannad
Ranch Hand

Joined: Dec 14, 2004
Posts: 68
Anastasia,

I think in (1) you are talking about sending all the information in the request itself.
(2) - saving in a session on the server, is what Iam trying to figure out.
If you have a servlet, I can see how one can have a session to save data in.

But if there is just a MDB how do you do it. Obviously, the session data should be available across servers.

Anastasia Klimchuk
Greenhorn

Joined: Sep 21, 2011
Posts: 10
I was talking about sending data in a message that client sends to a MDB, e.g. adding an attribute to message "clientState" or some other attributes. For this case client will send its state every time with a message.

By (2) - saving data on server (and no database), do you mean saving data in MBD for that it could recognize subsequent client calls and individual client data?
I have only one straightforward thought, to have a local hashmap inside an MDB with clientID as a key and session data as a value. But anyway, clientID should be passed in every message... and this all is only for little-sized session data
Mahesh Trikannad
Ranch Hand

Joined: Dec 14, 2004
Posts: 68
Storing in a hashmap, would make it accessible only if the next request goes to the same instance, the hashmap store was done in.
If I have 10 instances of a APP server ( lets say distributed among 5 physical servers ) - it would not work.
Anastasia Klimchuk
Greenhorn

Joined: Sep 21, 2011
Posts: 10
Oh, sure

But the possibility to send additional attributes in a message still exist
Mahesh Trikannad
Ranch Hand

Joined: Dec 14, 2004
Posts: 68
Yes
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Statefulness using JMS