users@glassfish.java.net

Re: Not getting any out put from in a MDB

From: Aleksandar Valchev <admin_at_hppsoft.com>
Date: Sun, 24 Feb 2008 02:07:17 +0200

Hi,
I'm not sure but, why you don't try to add connection.start():

  System.out.println("Sending " + text);
               connection = newMessageFactory.createConnection();
               session = connection.createSession(false,
Session.AUTO_ACKNOWLEDGE);
               TemporaryQueue replyQ = session.createTemporaryQueue();

               MessageProducer messageProducer = session.createProducer
(newMessage);
               TextMessage tm = session.createTextMessage();
               tm.setText(text);
               tm.setJMSReplyTo(replyQ);
               messageProducer.send(tm);
               System.out.println("Sent " + text);
               MessageConsumer recv = session.createConsumer(replyQ);

               connection.start();

               Message m = recv.receive();
               tm = (TextMessage)m;
               System.out.println(tm.getText());

I've worked with TIBCO EMS and this was the way you receive messages.

On 2/24/08, glassfish_at_javadesktop.org <glassfish_at_javadesktop.org> wrote:
>
> I'm having the same problem. My MDB gets the message, but when I send back
> to the client via the JMSReplyTo, my client doesn't seem to get it back.
>
> The test client is a servlet, the destination is an MDB, both in the same
> EAR.
>
> Client code:
> [code]
> public class NewServlet extends HttpServlet {
>
> @Resource(mappedName = "jms/NewMessageFactory")
> private ConnectionFactory newMessageFactory;
>
> @Resource(mappedName = "jms/NewMessage")
> private Queue newMessage;
>
>
> protected void processRequest(HttpServletRequest request,
> HttpServletResponse response)
> throws ServletException, IOException {
> sendMessage("World");
> response.sendRedirect("index.jsp");
> }
>
> private String sendMessage(String text) {
> Connection connection = null;
> Session session = null;
> try {
> try {
> System.out.println("Sending " + text);
> connection = newMessageFactory.createConnection();
> session = connection.createSession(false,
> Session.AUTO_ACKNOWLEDGE);
> TemporaryQueue replyQ = session.createTemporaryQueue();
>
> MessageProducer messageProducer = session.createProducer
> (newMessage);
> TextMessage tm = session.createTextMessage();
> tm.setText(text);
> tm.setJMSReplyTo(replyQ);
> messageProducer.send(tm);
> System.out.println("Sent " + text);
> MessageConsumer recv = session.createConsumer(replyQ);
> Message m = recv.receive();
> tm = (TextMessage)m;
> System.out.println(tm.getText());
> } finally {
> if (session != null) {
> session.close();
> }
> if (connection != null) {
> connection.close();
> }
> }
> } catch (JMSException ex) {
> ex.printStackTrace();
> }
> return null;
> }
> }
> [/code]
>
> MDB Code:
> [code]
> public void onMessage(Message message) {
> TextMessage tm = (TextMessage)message;
> Connection connection = null;
> Session session = null;
> try {
> try {
> System.out.println("Got " + tm.getText());
> connection = newMessageFactory.createConnection();
> session = connection.createSession(false,
> Session.AUTO_ACKNOWLEDGE);
> MessageProducer messageProducer = session.createProducer(
> tm.getJMSReplyTo());
> String result = "hello " + tm.getText();
> TextMessage newtm = session.createTextMessage();
> newtm.setText(result);
> newtm.setJMSCorrelationID(tm.getJMSMessageID());
> messageProducer.send(newtm);
> System.out.println("Sent " + result);
> } finally {
> if (session != null) {
> session.close();
> }
> if (connection != null) {
> connection.close();
> }
> }
> } catch (JMSException ex) {
> ex.printStackTrace();
> }
> }
>
> [/code]
>
> In my log, I see these from the printlns:
>
> Sent World
> Got World
> Sent hello World
>
> That tells me the servlet sent the message, the MDB got the message, and
> the MDB sent the reply.
>
> At that point my client is stuck waiting for the message.
>
> Any hints appreciated.
> [Message sent by forum member 'whartung' (whartung)]
>
> http://forums.java.net/jive/thread.jspa?messageID=260597
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
>