• Post Reply Bookmark Topic Watch Topic
  • New Topic

Message-Driven Beans JMS

 
Jeff Storey
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi - I'm somewhat new to EJBs but specifically MDBs, and I'm having a problem sending messages from my server to my client.

The situation is that each client gets specific messages from a server (each client gets a stateful bean which is responsible for sending the messages). Each time a client logs on, it gets a new copy of the stateful bean which creates a new queue specific to that client and thus the client and server communicate via that queue (this may or may not be a good choice of design, but for now, it works). The problem is that the messaging logic is in that stateful bean - when the bean is passivated, an error is thrown because the TopicConnection and Topic objects which are used by the stateful bean to send the message are not serializable.

Is there a way I can use MDBs (or some other strategy) to send JMS messages, so the setting up of the queues and topics does not need to be done in the stateful bean, and thus preventing this passivation/serialization error?

If I have not explained this clearly enough, please let me know and I will try to explain more. If you can offer any advice to this problem, I would greatly appreciate it.

Thank you,
Jeff Storey
 
Mark Spritzler
ranger
Sheriff
Posts: 17290
9
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well basically the situation is this, you are using a stateful bean.

MDB's are asynchronouse, therefore once the client sends a message it is gone and the client has no link to it, and it shouldn't. The only thing you can do is have your client be a subscriber, and asynchronously receive them, meaning they cannot be held in state in your stateful bean. You could take the message and put it into a plain old java object and hold that state, because you would make the POJO Serializable.

Mark
 
Jeff Storey
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mark,

Thanks for your response. I'm still a little confused though...yes, I do have a stateful bean which sends messages via JMS. I do not need to maintain state after the message is sent, which I do not currently do. I'm just really wondering if it makes sense to have the Stateful bean make the calls to JMS (i.e. creating a publisher and publishing the messages to the queue) - the fact that the JMS objects are not serializable makes me think it shouldn't be in a stateful bean which may be serialized by the ejb container during passivation. Is this a poor design choice that I am making or should I just not be storing the publisher as a member in my bean (rather recreate the connection and publisher on each message I need to publish)?

Thanks,
Jeff
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!