This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes EJB and other Java EE Technologies and the fly likes ConnectionPool or resource-ref for JMS connection for P2P in WAS 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 "ConnectionPool or resource-ref for JMS connection for P2P in WAS" Watch "ConnectionPool or resource-ref for JMS connection for P2P in WAS" New topic
Author

ConnectionPool or resource-ref for JMS connection for P2P in WAS

Sam Gehouse
Ranch Hand

Joined: Jul 21, 2003
Posts: 281
This is for a P2P application deployed in WebSphere 5.1.x.

I want to make sure that queueconnections are obtained from a pool and returned to pool.

I see 2 alternative approaches - one with connectionpooling, another with resource-ref.

ConnectionPooling Approach:

1) While configuring queueconnectionfactory in server, we can configure connectionpool.
2) For each message, do following:

- Create QueueConnection.
- Send Message
- Close QueueSession
- Close QueueConnection.

Code is:
try {
qConnection = qConnectionFactory.createQueueConnection();
qSession = qConnection.createQueueSession
(false,Session.AUTO_ACKNOWLEDGE);
sender = qSession.createSender(queue);
message = qSession.createTextMessage();
message.setText(msgText);
sender.send(message);
} finally {
sender.close();
qSession.close();
qConnection.close();
}

Is the approach above fine for sending message from POJO?

resource-ref approach under:
http://developers.sun.com/prodtech/appserver/reference/techart/tip1_june_2003.html
http://www.devx.com/getHelpOn/10MinuteSolution/16630/0/page/3

In resourece-ref approach, I see creating connectionFactory, but I do not see closing it.

InitialContext ctx = new InitialContext();
QueueConnectionFactory qcf_final = (QueueConnectionFactory)
ctx.lookup("java:comp/env/jms/QcfFinal");
Queue queue_final = (Queue) ctx.lookup("java:comp/env/jms/QueueFinal");

QueueConnection queue_conn = qcf_final.createQueueConnection();
QueueSession queue_session =queue_conn.createQueueSession(false,
Session.AUTO_ACKNOWLEDGE);
QueueSender queue_sender = queue_session.createSender(queue_final);

TextMessage message = queue_session.createTextMessage();
message.setText("This message is from MDB MessageBeanFirst ");
queue_sender.send(message);

In ejb-jar.xml, add the following lines to the end of the MDB declaration (under the <message-driven> element):

<resource-ref>
<res-ref-name>jms/QcfFinal</res-ref-name>
<res-type>javax.jms.QueueConnectionFactory</res-type>
<res-auth>Container</res-auth>
<resource-sharing-scope>Shareable</resource-sharing-scope>
</resource-ref>
<resource-env-ref>
<resource-env-ref-name>jms/QueueFinal</resource-env-ref-name>
<resource-env-ref-type>javax.jms.Queue</resource-env-ref-type>
</resource-env-ref>

Which alternative (connection pool, or resource-ref) is the correct approach?

Is it not necessary to close connection if resource-ref approach is taken?

Is it fine to use connectionPool approach if message is sent from POJO?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ConnectionPool or resource-ref for JMS connection for P2P in WAS
 
Similar Threads
New To JMS
A simple JNDI question....
Simple Send, Receive (Messaging) Bean
JMS REMOTE CONNECTION Problems
MQ JMS problem in WSAD