permaculture playing cards*
The moose likes EJB and other Java EE Technologies and the fly likes ejb Stateless SessionBean send JMS msg's Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "ejb Stateless SessionBean send JMS msg Watch "ejb Stateless SessionBean send JMS msg New topic
Author

ejb Stateless SessionBean send JMS msg's

david lightman
Ranch Hand

Joined: Nov 03, 2004
Posts: 82
I have a Statelesss SB that puts messages on a queue queue to be sent to a remote system.

I have set the max connections to 10 on the QCF factory it is using.

Do I need to explicitly set close the connection for the queueconnection after the sendMessage() is called even though I have the cleanup in the ejbRemove()?

I am getting a new QCF connection with each call to the sendmessage(), so I guess the container tried to create this each time and it is running out?
even though it is pulling from a pool? Do some people put the createQueueConnection in the ejbCreate() ?

here is the message:

[3/4/05 11:13:46:548 EST] 61315440 FreePool E J2CA0045E: Connection not available while invoking method queueRequest for resource jms/SLSB/SLSBqcf001.
[3/4/05 11:13:46:836 EST] 61315440 ConnectionMan E J2CA0020E: The Connection Pool Manager could not allocate a Managed Connection: com.ibm.websphere.ce.j2c.ConnectionWaitTimeoutException: Connection not available, Timed out waiting for 180007
at com.ibm.ejs.j2c.poolmanager.FreePool.createOrWaitForConnection(FreePool.java:1030)
david lightman
Ranch Hand

Joined: Nov 03, 2004
Posts: 82
anybody at all understand how the session /connection work?
Valentin Tanase
Ranch Hand

Joined: Feb 17, 2005
Posts: 704
Hi David,


Do I need to explicitly set close the connection for the queueconnection after the sendMessage() is called even though I have the cleanup in the ejbRemove()?

No you don’t need to bother about connections or connection factories inside onMessage() method. The container gets the message from the JMS destination and passes it to the MDB via onMessage() method. You only need to configure your MDB to listen to the right destination and use either the default connection factory or an application specific connection factory. There is an exception from this rule though: if you decide that your MDB must send messages to other JMS destinations then you need to handle connections with care (like closing them inside of a finally block).

I am getting a new QCF connection with each call to the sendmessage(), so I guess the container tried to create this each time and it is running out?

Because your SLSB acts as a client to the JMS destination and because it runs on the server as well, you need to get a connection from the pool and close it after sending the message. Actually a good strategy might look like this:

This works exactly as with JDBC connections: it will return the connection back to the pool. Also remark that we do two look up(s) once for the factory and once for the queue. That’s ok, because a local look up is not very expensive. Caching the connection won’t be a good strategy, because it might not be returned to the pool after all.

Do some people put the createQueueConnection in the ejbCreate() ?

I don’t find this like a good solution because that implies that the connection will never return to the pool (although it is closed in ejbRemove(), but with SLSB clients might never call remove). What will happen next, depends upon the number of SLSB in the pool vs no of connections: if at any time there will be more bean instances than connections, the application will run out of connections.


I think, therefore I exist -- Rene Descartes
Tarun Chatterjee
Greenhorn

Joined: Mar 07, 2005
Posts: 25
Hi Valentin

I created the connection in the onMessage method, but i found certain issues when the mesages were Persistent and as a result of which the mesages were stored in a DB. Now the App server on which it was running was shut down and on restart started throwing Exceptions as on server startup on binding the MDB the onMesage method was getting fired.
Any idea as to how to mitigate the issue?
Valentin Tanase
Ranch Hand

Joined: Feb 17, 2005
Posts: 704
Hi Tarun,


I created the connection in the onMessage method

Why do you need to create connections inside of onMessage? Is your MDB a JMS producer as well? You might consider sharing some code with us and explain your decisions.

on restart started throwing Exceptions as on server startup on binding the MDB the onMesage method was getting fired.

What kind of exceptions? Can you provide the stack trace?
Regards.
david lightman
Ranch Hand

Joined: Nov 03, 2004
Posts: 82
thanks for the reply.

some was referring to MDB's, which I am not working withn rather a Stateless Session Bean that is sending messages.

I failed to mention one caviat. I am using a service locator to lookup the queues as they may be different but the actual queueConnfactory will be the same for the session bean.

Also, should I close the sesion prior to closing the qconn?
i see no mention of that

how does this work(sessions)?

thanks again!
[ March 08, 2005: Message edited by: david lightman ]
Valentin Tanase
Ranch Hand

Joined: Feb 17, 2005
Posts: 704

some was referring to MDB's, which I am not working withn rather a Stateless Session Bean that is sending messages.

I�m sorry David I didn�t read your posting very well. You mention something about sendMessage() and I thought is onMessage()� I�m getting older I suppose :-)

Also, should I close the sesion prior to closing the qconn?
i see no mention of that

No you don�t.

how does this work(sessions)?

A JMS connection represents a physical connection to the underlying messaging system. One thing to notice about JMS connections: they are thread safe and there is no special reason for a JMS client application to require more than one JMS connection. However sessions are completely different from this standpoint: they are single-threaded contexts for producing and consuming messages and are not thread-safe. Usually (and I can�t see any reason doing otherwise) sessions are created local by each thread and they are not shared across threads (by doing this the application will take the responsibility for synchronizing the data access). Closing the connection is required, in order to return the connection to the pool. Session variables are usually local variables and they are lost after each method call.
And by the way, you are very welcome David.
Tarun Chatterjee
Greenhorn

Joined: Mar 07, 2005
Posts: 25
Hi Valentin

this is the snippet in the onMessage method.
QueueConnection queueConnection = null ;
QueueSession queueSession = null ;
try
{
if(queueConnectionFactory==null)
{
String queueConnectionFactoryJNDIName = "JNDI" ;
queueConnectionFactory = ( QueueConnectionFactory ) jndiContext.lookup (
queueConnectionFactoryJNDIName ) ;
}
queueConnection = queueConnectionFactory.createQueueConnection () ;
queueConnection.start () ;
queueSession = queueConnection.createQueueSession ( false
, QueueSession.
AUTO_ACKNOWLEDGE ) ;
david lightman
Ranch Hand

Joined: Nov 03, 2004
Posts: 82
tarun ,

it may help to create a post of your own instead of asking questions in someone elses. You have a completelyly separate issue so put your problem in a NEW post with your problem in the heading, you may get the result you are looking for.
[ March 09, 2005: Message edited by: david lightman ]
Valentin Tanase
Ranch Hand

Joined: Feb 17, 2005
Posts: 704
Hi Tarun,

Again I don�t understand why would you need to open a connection inside of the onMessage method of an MDB. I will assume that you try to send messages to other JMS destinations. Otherwise you might consider revisiting your design.
Do you close your connection all the time (eventually inside of a finally block)?
Regards.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ejb Stateless SessionBean send JMS msg's
 
Similar Threads
WSAD JMS Configuration
WSAD5.1.1, Embedded JMS Server
JMS Configuration problem
hi kyle
WSAD51.1 WebSphere Embedded Messaging Client only has been installed