4 Replies Latest reply on Jul 26, 2007 11:46 AM by Adrian Brock

    MDB sending a message

    Hannes Schulz Newbie

      hi i have a maybe newbie question.

      i was trying to make a synchronous jms call. the class MessageProducer sends a request and to a MDB wich in return sends a message back to a temporary queue.

      everything seems to work untill the message should be recievedform the temporary queue.

      @Name("helloworld")
      public class MessageProducer {
      
       QueueConnection qConnection = null;
       QueueSession qSession = null;
       QueueSender qSender = null;
       QueueRequestor qRequestor = null;
      
       @Logger Log log;
      
       public void test(){
       try{
      
       InitialContext iniCtx = new InitialContext();
       Object tmp = iniCtx.lookup("ConnectionFactory");
       QueueConnectionFactory qcFactory = (QueueConnectionFactory) tmp;
      
       qConnection = qcFactory.createQueueConnection();
       Queue queue = (Queue) iniCtx.lookup("queue/quickstart_helloworld_Request");
      
       qConnection = qcFactory.createQueueConnection();
      
       qSession = qConnection.createQueueSession(false,
       Session.AUTO_ACKNOWLEDGE);
      
       qSender = qSession.createSender(queue);
      
       String msg = "Hello Queue!";
       Message message = qSession.createTextMessage(msg);
      
       log.info("Request message");
      
       TemporaryQueue tempQueue = qSession.createTemporaryQueue();
       message.setJMSReplyTo(tempQueue);
       qSender.send(message);
       QueueReceiver receiver = qSession.createReceiver(tempQueue);
       log.info("Receiver listens on: #0",receiver.getQueue().getQueueName());
      
       Message answer = receiver.receive();
       log.info("message recieved:");
      
       //qRequestor = new QueueRequestor(qSession,queue);
      
       //TextMessage answer = (TextMessage) qRequestor.request(message);
       //log.info("answer::#0",answer.getText());
       }
       catch (Exception e) {
       ...
       }
       }
      }


      and the mdb:

      ...
      try {
       TextMessage response = qSession.createTextMessage("Hello TempQueue!");
       System.out.println("try to get JMPReplyTo");
       Queue replyQueue = (Queue) recvMsg.getJMSReplyTo();
       System.out.println("replyQueue:" + replyQueue.getQueueName());
       QueueSender replySender = qSession.createSender(replyQueue);
       System.out.println("send response");
       replySender.send(replyQueue,response);
       replySender.close();
       }
       catch(Exception e){
       e.printStackTrace();
       }[
      ...


      after executing test() nothing happens, the console JBoss AS console says:

      16:31:05,328 INFO [MessageProducer] Request message
      16:31:05,328 INFO [MessageProducer] Receiver listens on: JMS_TQ8
      16:31:05,375 INFO [STDOUT] Received Message: Hello Queue!
      16:31:05,375 INFO [STDOUT] try to get JMPReplyTo
      16:31:05,375 INFO [STDOUT] replyQueue:JMS_TQ8
      16:31:05,375 INFO [STDOUT] send response


      and in the log file i get a few SocketManager exceptions which are not displayed in the console

      is it possible what i am trying to do? can someone tell me why this doesnt work? help would be appreciated.

      thanks,
      hasc

        • 1. Re: MDB sending a message
          Hannes Schulz Newbie

          i am getting the following error in the log file.

          2007-04-10 11:21:07,921 INFO [STDOUT] replyQueue:JMS_TQ5
          2007-04-10 11:21:07,921 INFO [STDOUT] send response
          2007-04-10 11:21:07,921 DEBUG [org.jboss.mq.il.uil2.SocketManager] Failed to handle: org.jboss.mq.il.uil2.msgs.CloseMsg2471808[msgType: m_connectionClosing, msgID: -2147482592, error: null]
          java.io.IOException: Client is not connected
           at org.jboss.mq.il.uil2.SocketManager.internalSendMessage(SocketManager.java:264)
           at org.jboss.mq.il.uil2.SocketManager.sendReply(SocketManager.java:238)
           at org.jboss.mq.il.uil2.ServerSocketManagerHandler.handleMsg(ServerSocketManagerHandler.java:131)
           at org.jboss.mq.il.uil2.SocketManager$ReadTask.handleMsg(SocketManager.java:395)
           at org.jboss.mq.il.uil2.msgs.BaseMsg.run(BaseMsg.java:398)
           at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(PooledExecutor.java:748)
           at java.lang.Thread.run(Thread.java:595)
          2007-04-10 11:21:07,921 DEBUG [org.jboss.mq.il.uil2.SocketManager] Failed to send error reply
          java.io.IOException: Client is not connected
           at org.jboss.mq.il.uil2.SocketManager.internalSendMessage(SocketManager.java:264)
           at org.jboss.mq.il.uil2.SocketManager.access$800(SocketManager.java:53)
           at org.jboss.mq.il.uil2.SocketManager$ReadTask.handleMsg(SocketManager.java:408)
           at org.jboss.mq.il.uil2.msgs.BaseMsg.run(BaseMsg.java:398)
           at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(PooledExecutor.java:748)
           at java.lang.Thread.run(Thread.java:595)
          2007-04-10 11:21:07,921 DEBUG [org.jboss.mq.il.uil2.SocketManager] End ReadTask.run
          2007-04-10 11:21:07,921 DEBUG [org.jboss.mq.il.uil2.SocketManager] End WriteTask.run
          2007-04-10 11:21:07,921 DEBUG [org.jboss.mq.il.uil2.UILClientILService] Stopping
          2007-04-10 11:21:07,937 DEBUG [org.jboss.mq.il.uil2.ServerSocketManagerHandler] Exiting on IOE
          java.net.SocketException: socket closed
           at java.net.SocketInputStream.socketRead0(Native Method)
           at java.net.SocketInputStream.read(SocketInputStream.java:129)
           at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
           at java.io.BufferedInputStream.read(BufferedInputStream.java:235)
           at org.jboss.util.stream.NotifyingBufferedInputStream.read(NotifyingBufferedInputStream.java:79)
           at java.io.ObjectInputStream$PeekInputStream.peek(ObjectInputStream.java:2196)
           at java.io.ObjectInputStream$BlockDataInputStream.readBlockHeader(ObjectInputStream.java:2376)
           at java.io.ObjectInputStream$BlockDataInputStream.refill(ObjectInputStream.java:2443)
           at java.io.ObjectInputStream$BlockDataInputStream.read(ObjectInputStream.java:2515)
           at java.io.ObjectInputStream$BlockDataInputStream.readByte(ObjectInputStream.java:2664)
           at java.io.ObjectInputStream.readByte(ObjectInputStream.java:875)
           at org.jboss.mq.il.uil2.SocketManager$ReadTask.run(SocketManager.java:316)
           at java.lang.Thread.run(Thread.java:595)
          2007-04-10 11:21:07,937 DEBUG [org.jboss.mq.il.uil2.SocketManager] End ReadTask.run
          2007-04-10 11:21:07,937 DEBUG [org.jboss.mq.il.uil2.SocketManager] End WriteTask.run


          • 2. Re: MDB sending a message
            Hannes Schulz Newbie

            solved.

            the command qConnection.start() was missing...

            • 3. Re: MDB sending a message
              Amjad farajallah Newbie

              I use this method to start XAConnection connection:

              public void startAsync(StartProcessCommand command) {

              if (log.isDebugEnabled()) log.debug("startAsync()");

              try {

              Destination taskProcessorQueue = (Destination)ctx.lookup("queue/ProcessManager");
              if (log.isDebugEnabled()) log.debug("Destination is: "+taskProcessorQueue+".");

              XAConnectionFactory factory = (XAConnectionFactory) ctx.lookup("XAConnectionFactory");
              final XAConnection cnn = factory.createXAConnection();
              final XASession session = cnn.createXASession();
              if (log.isDebugEnabled()) log.debug("Session is transacted: "+session.getTransacted()+".");

              cnn.start();

              MessageProducer producer = session.createProducer(taskProcessorQueue);

              Message aMessage = session.createObjectMessage(command);
              producer.send(aMessage);
              cnn.stop();
              cnn.close();

              }
              catch (JMSException e) {
              if (log.isErrorEnabled()) log.error("Error while talking to the ProcessManager:",e);
              // TODO do something
              }
              }


              when I run it I get sometimes an Error:

              2007-07-23 12:13:54,126 DEBUG [org.hibernate.jdbc.ConnectionManager]
              aggressively releasing JDBC connection
              --------------------------------------------------------------
              2007-07-23 12:13:54,127 DEBUG [org.jboss.mq.il.uil2.SocketManager]
              Failed to handle: org.jboss.mq.il.uil2.msgs.CloseMsg28691191
              [msgType: m_connectionClosing, msgID: -2147393866, error: null]
              java.io.IOException: Client is not connected
              at org.jboss.mq.il.uil2.SocketManager.internalSendMessage(SocketManager.java:264)
              at org.jboss.mq.il.uil2.SocketManager.sendReply(SocketManager.java:238)
              at org.jboss.mq.il.uil2.ServerSocketManagerHandler.handleMsg (ServerSocketManagerHandler.java:131)
              at org.jboss.mq.il.uil2.SocketManager$ReadTask.handleMsg(SocketManager.java:395)
              at org.jboss.mq.il.uil2.msgs.BaseMsg.run(BaseMsg.java:398)
              at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run (PooledExecutor.java:748)
              at java.lang.Thread.run(Thread.java:595)
              2007-07-23 12:13:54,127 DEBUG [org.jboss.mq.il.uil2.SocketManager]
              Failed to send error reply


              Can any one help me why is this happen

              • 4. Re: MDB sending a message
                Adrian Brock Master

                FAQ and HIJACK.