0 Replies Latest reply on Sep 20, 2002 6:05 PM by venkat

    JMS client acknowledgement

    venkat Newbie

      I am having hardtime with JBOSS JMS Client Acknowledgement option.

      My functionality is:

      1). A MDB from an application sends few Messages in AUTO_ACKNOWLEDGEMENT mode to JBOSS JMS.
      2). A standlone Java client reads these Messages in CLIENT_ACKNOWLEDGEMENT mode.
      3). Java client does some processing with the above read messages.
      4). If above processing is successful, Acknowledges all read messages. Else doesn't acknowledge.

      So according to theory, All messages should be available still in JMS at Step-4.
      but in practical as soon as I read messages at Step-2, they disappear from JMS queue.

      I tested same code with WebLogic6, its working as expected. And same Code doesnt work with any of JBOSS 2.4.7, 2.4.8, 2.4.9 or 3.0.2

      Code snippet I am using for this is:
      ---------------------------------------------------------- String text = "Foo Data";

      session = conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
      conn.start();
      QueueSender send = session.createSender(que);
      System.out.println("Created Sender");

      for (int i = 0; i < 5; i++) {
      TextMessage tm = session.createTextMessage();
      tm.setText(text+i);
      send.send(tm);
      }
      send.close();

      System.out.println("all messages are sent");

      try{
      Thread.sleep(3000);
      }catch(Exception ep){}



      session = conn.createQueueSession(false,
      QueueSession.CLIENT_ACKNOWLEDGE);
      QueueReceiver recv = session.createReceiver(que);
      System.out.println("Receiver created");

      Vector vec = new Vector();
      while(true) {
      TextMessage mesg = (TextMessage) recv.receive(10);
      if (mesg != null){
      vec.addElement(mesg);
      System.out.println("message recvd:" + mesg.getText());
      try{
      Thread.sleep(5000);
      }catch(Exception ep){}
      } else {
      System.out.println("no message found");
      break;
      }
      }

      if(vec.size()>0){
      for(int p=0;p<vec.size();p++){
      TextMessage mesg = (TextMessage) vec.elementAt(p);
      System.out.println("ACKNOWLEDG'ing message"+p);

      // here if i comment this statement messages should stay in JMS
      mesg.acknowledge();
      }
      }


      recv.close();
      ----------------------------------------------------------
      Please still if my question is not clear let me know.
      thanks
      Venkat