0 Replies Latest reply on Mar 4, 2012 1:56 PM by Martin G

    Last Value Queue with negative message counter

    Martin G Newbie

      hi guys,

       

      I want to enusure that some items are only once in my queue so i set:

       

          <address-setting match="io.testq">  
              <last-value-queue>true</last-value-queue>
            </address-setting>
      

       

       

      when i'm adding two messages, and receive one one, but the message counter is always decremented by two:

       

      the following code

       

       ClientMessage message = session.createMessage(true);
          SimpleString myUniqueID = new SimpleString(objId);
          message.putStringProperty(Message.HDR_LAST_VALUE_NAME, myUniqueID);
          message.getBodyBuffer().writeString("test");
          producer.send(message);
          
          
          ClientRequestor requestor = new ClientRequestor(session,
              "jms.queue.hornetq.management");
          ClientMessage newMessage = session.createMessage(false);
          ManagementHelper.putAttribute(newMessage, ResourceNames.CORE_QUEUE
              + queueName, "messageCount");
          ClientMessage reply = requestor.request(newMessage);
          int count = Integer.parseInt(ManagementHelper.getResult(reply).toString());
          System.out.println("There are " + count + " messages in " + queueName);
      
          ClientMessage message2 = session.createMessage(true);
          message2.putStringProperty(Message.HDR_LAST_VALUE_NAME, myUniqueID);
          message2.getBodyBuffer().writeString("test2");
          producer.send(message2);
      
          reply = requestor.request(newMessage);
          count = Integer.parseInt(ManagementHelper.getResult(reply).toString());
          System.out.println("There are " + count + " messages in " + queueName);
      
          consumer = session.createConsumer(queueName);
          ClientMessage msgReceived = consumer.receive();
          System.out.println("message = " + msgReceived.getBodyBuffer().readString());
          msgReceived.acknowledge();
      
          reply = requestor.request(newMessage);
          count = Integer.parseInt(ManagementHelper.getResult(reply).toString());
          System.out.println("There are " + count + " messages in " + queueName);
      
      

       

       

      procuces the following output

       

      There are 1 messages in last_value_queue
      There are 1 messages in last_value_queue
      message = test2
      There are -1 messages in last_value_queue
      
      

       

      is that a correct behaviour?