  | Mailing List | | Home | | Forum Home | | JBoss - Java Application Server | | Tomcat - JSP/Servlet container | | Struts - A MVC web framework | | iText - An open source PDF Java Library | | JDOM - JDOM XML Parser | | J2EE - A mailing list for Java(tm) 2 Platform, Enterprise Edition | | J2EE Pattern - An interest list for Sun Java Center J2EE Pattern Catalog | | JSP - A mailing list about Java Server Pages specification and reference | | Servlet - A mailing list for discussion about Sun Microsystem's Java Servlet API Technology | |
Struts & Hibernate
|
|
|
  | | | Spam:Re: Using JMS in a session bean | Spam:Re: Using JMS in a session bean 2004-10-30 - By Partha Ranjan Das
Back It is not right to have a synchronous approach for a solution that is designed to be asynchronous. Your session bean should not be made to wait as it is not designed for such a scenario. Session beans should used and immediatly released . The bean that fits your scenario is a message-driven bean approach where you receive the message in the onMessage() method of an MDB and do the processing for that message. Send the messgae form your present session bean and let the MDB take care of the receiving and follow-up action in the other end. I think it will not harm your logic and you will be able to segregate the sending and receiving parts into two different beans.
Regards, Partha
> -- ---- -- > From: A mailing list for Java(tm) 2 Platform, Enterprise Edition[SMTP :J2EE-INTEREST@(protected)] on behalf of Singla, Munish K.[SMTP:MSingla@(protected) .COM] > Sent: Saturday, October 30, 2004 12:51 AM > To: J2EE-INTEREST@(protected) > Subject: Spam:Re: Using JMS in a session bean > > You might want to try out with a higher value for timeout in receive > call before assuming it is something else. > > -- --Original Message-- -- > From: John Lohr [mailto:johnlohr12@(protected)] > Sent: Friday, October 15, 2004 12:35 AM > To: J2EE-INTEREST@(protected) > Subject: Using JMS in a session bean > > Hello, > > Please would you know if I can send a message and then receive a > response message in one method from stateless session bean. Seems to me > that the messages that the bean is sending are placed on the queue when > the execution of the bean method is finished thus it can never receive > the response. If it is so how can that be resolved. Any pattern .. ? The > code below works fine in a servlet but in a session bean it always > timeouts. I am using Embeded messaging in WebSphere and there is a plain > Java receiver of messages from the bean and it is sending responses > back. > > Thank you, > John > > sessionBeanMethod() { > .... > .... > connection = factory.createQueueConnection(); > QueueSession session = connection.createQueueSession(false, > Session.AUTO_ACKNOWLEDGE); > QueueSender sender = session.createSender(requestQueue); > QueueReceiver receiver = session.createReceiver(responseQueue, > selector); > connection.start(); > TextMessage requestMessage = session.createTextMessage("message"); > requestMessage.setJMSCorrelationID(messageID); > sender.send(requestMessage); > Message responseMessage = receiver.receive(5000); > .... > } > > __ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ __ > On the road to retirement? Check out MSN Life Events for advice on how > to get there! http://lifeevents.msn.com/category.aspx?cid=Retirement > > ======================================================================== > === > To unsubscribe, send email to listserv@(protected) and include in the > body of the message "signoff J2EE-INTEREST". For general help, send > email to listserv@(protected) and include in the body of the message > "help". > > =========================================================================== > To unsubscribe, send email to listserv@(protected) and include in the body > of the message "signoff J2EE-INTEREST". For general help, send email to > listserv@(protected) and include in the body of the message "help". >
=========================================================================== To unsubscribe, send email to listserv@(protected) and include in the body of the message "signoff J2EE-INTEREST". For general help, send email to listserv@(protected) and include in the body of the message "help".
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"> <HTML> <HEAD> <TITLE>RE: Spam:Re: Using JMS in a session bean</TITLE> </HEAD> <BODY> <!-- Converted from text/rtf format -->
<P><FONT COLOR="#0000FF" SIZE=2>It is not right to have a synchronous approach for a solution that is designed to be asynchronous. Your session bean should not be made to wait as it is not designed for such a scenario. Session beans should used and immediatly released. The bean that fits your scenario is a message-driven bean approach where you receive the message in the onMessage() method of an MDB and do the processing for that message. Send the messgae form your present session bean and let the MDB take care of the receiving and follow -up action in the other end. I think it will not harm your logic and you will be able to segregate the sending and receiving parts into two different beans.< /FONT></P>
<P><FONT COLOR="#0000FF" SIZE=2>Regards,</FONT>
<BR><FONT COLOR="#0000FF" SIZE=2>Partha</FONT> </P> <UL> <P><FONT SIZE=1 FACE="MS Sans Serif">-- ---- --</FONT>
<BR><B><FONT SIZE=1 FACE="MS Sans Serif">From:</FONT></B> <FONT SIZE=1 FACE="MS Sans Serif">A mailing list for Java(tm) 2 Platform, Enterprise Edition [SMTP:J2EE-INTEREST@(protected)] on behalf of Singla, Munish K.[SMTP:MSingla @(protected)]</FONT></P>
<P><B><FONT SIZE=1 FACE="MS Sans Serif">Sent:</FONT></B> <FONT SIZE=1 FACE="MS Sans Serif">Saturday, October 30, 2004 12:51 AM</FONT>
<BR><B><FONT SIZE=1 FACE="MS Sans Serif">To:</FONT></B> <FONT SIZE=1 FACE="MS Sans Serif">J2EE-INTEREST@(protected)</FONT>
<BR><B><FONT SIZE=1 FACE="MS Sans Serif">Subject:</FONT></B> <FONT SIZE=1 FACE="MS Sans Serif">Spam:Re: Using JMS in a session bean</FONT> </P>
<P><FONT SIZE=2 FACE="Arial">You might want to try out with a higher value for timeout in receive</FONT>
<BR><FONT SIZE=2 FACE="Arial">call before assuming it is something else. </FONT> </P>
<P><FONT SIZE=2 FACE="Arial">-- --Original Message-- --</FONT>
<BR><FONT SIZE=2 FACE="Arial">From: John Lohr [<U></U></FONT><U><FONT COLOR=" #0000FF" SIZE=2 FACE="Arial"><A HREF="mailto:johnlohr12@(protected)">mailto :johnlohr12@(protected)</A></FONT></U><FONT SIZE=2 FACE="Arial">] </FONT>
<BR><FONT SIZE=2 FACE="Arial">Sent: Friday, October 15, 2004 12:35 AM</FONT>
<BR><FONT SIZE=2 FACE="Arial">To: J2EE-INTEREST@(protected)</FONT>
<BR><FONT SIZE=2 FACE="Arial">Subject: Using JMS in a session bean</FONT> </P>
<P><FONT SIZE=2 FACE="Arial">Hello,</FONT> </P>
<P><FONT SIZE=2 FACE="Arial">Please would you know if I can send a message and then receive a</FONT>
<BR><FONT SIZE=2 FACE="Arial">response message in one method from stateless session bean. Seems to me</FONT>
<BR><FONT SIZE=2 FACE="Arial">that the messages that the bean is sending are placed on the queue when</FONT>
<BR><FONT SIZE=2 FACE="Arial">the execution of the bean method is finished thus it can never receive</FONT>
<BR><FONT SIZE=2 FACE="Arial">the response. If it is so how can that be resolved. Any pattern .. ? The</FONT>
<BR><FONT SIZE=2 FACE="Arial">code below works fine in a servlet but in a session bean it always</FONT>
<BR><FONT SIZE=2 FACE="Arial">timeouts. I am using Embeded messaging in WebSphere and there is a plain</FONT>
<BR><FONT SIZE=2 FACE="Arial">Java receiver of messages from the bean and it is sending responses</FONT>
<BR><FONT SIZE=2 FACE="Arial">back.</FONT> </P>
<P><FONT SIZE=2 FACE="Arial">Thank you,</FONT>
<BR><FONT SIZE=2 FACE="Arial">John</FONT> </P>
<P><FONT SIZE=2 FACE="Arial">sessionBeanMethod() {</FONT>
<BR><FONT SIZE=2 FACE="Arial"> ....</FONT>
<BR><FONT SIZE=2 FACE="Arial"> ....</FONT>
<BR><FONT SIZE=2 FACE="Arial"> connection = factory .createQueueConnection();</FONT>
<BR><FONT SIZE=2 FACE="Arial"> QueueSession session = connection.createQueueSession(false,</FONT>
<BR><FONT SIZE=2 FACE="Arial">Session.AUTO_ACKNOWLEDGE);</FONT>
<BR><FONT SIZE=2 FACE="Arial"> QueueSender sender = session .createSender(requestQueue);</FONT>
<BR><FONT SIZE=2 FACE="Arial"> QueueReceiver receiver = session.createReceiver(responseQueue,</FONT>
<BR><FONT SIZE=2 FACE="Arial">selector);</FONT>
<BR><FONT SIZE=2 FACE="Arial"> connection.start();</FONT>
<BR><FONT SIZE=2 FACE="Arial"> TextMessage requestMessage = session.createTextMessage("message");</FONT>
<BR><FONT SIZE=2 FACE="Arial"> requestMessage .setJMSCorrelationID(messageID);</FONT>
<BR><FONT SIZE=2 FACE="Arial"> sender.send(requestMessage);< /FONT>
<BR><FONT SIZE=2 FACE="Arial"> Message responseMessage = receiver.receive(5000);</FONT>
<BR><FONT SIZE=2 FACE="Arial"> ....</FONT>
<BR><FONT SIZE=2 FACE="Arial">}</FONT> </P>
<P><FONT SIZE=2 FACE="Arial">__ ____ ____ ____ ____ ____ ____ ____ ____ ____ __ __ ____ ____ __</FONT>
<BR><FONT SIZE=2 FACE="Arial">On the road to retirement? Check out MSN Life Events for advice on how</FONT>
<BR><FONT SIZE=2 FACE="Arial">to get there!</FONT><U> <FONT COLOR="#0000FF" SIZE=2 FACE="Arial"><A HREF="http://lifeevents.msn.com/category.aspx?cid =Retirement">http://lifeevents.msn.com/category.aspx?cid=Retirement</A></FONT>< /U> </P>
<P><FONT SIZE=2 FACE="Arial">================================================== ======================</FONT>
<BR><FONT SIZE=2 FACE="Arial">===</FONT>
<BR><FONT SIZE=2 FACE="Arial">To unsubscribe, send email to listserv@(protected) .com and include in the</FONT>
<BR><FONT SIZE=2 FACE="Arial">body of the message "signoff J2EE-INTEREST ". For general help, send</FONT>
<BR><FONT SIZE=2 FACE="Arial">email to listserv@(protected) and include in the body of the message</FONT>
<BR><FONT SIZE=2 FACE="Arial">"help".</FONT> </P>
<P><FONT SIZE=2 FACE="Arial">================================================== =========================</FONT>
<BR><FONT SIZE=2 FACE="Arial">To unsubscribe, send email to listserv@(protected) .com and include in the body</FONT>
<BR><FONT SIZE=2 FACE="Arial">of the message "signoff J2EE-INTEREST". For general help, send email to</FONT>
<BR><FONT SIZE=2 FACE="Arial">listserv@(protected) and include in the body of the message "help".</FONT> </P> </UL> </BODY> </HTML> =========================================================================== To unsubscribe, send email to listserv@(protected) and include in the body of the message "signoff J2EE-INTEREST". For general help, send email to listserv@(protected) and include in the body of the message "help". <p>
|
|
 |