2 Replies Latest reply on Jun 21, 2010 9:52 AM by PÃ¥l Evensen

    Last-value queue

    PÃ¥l Evensen Novice

      I'm trying to create a last-value queue, but am having trouble understanding how.

       

      I've created a config like it says in the documentation:

       

      hornetq-config.xml:

       

      <address-setting match="coupon.client.numcorrect.#">
                 <last-value-queue>true</last-value-queue>
      </address-setting>

       

      The queues themselves are created dynamically from within the code:

       

      stompServer.createQueue("coupon.client.numcorrect." + userId, false);

       

      /**
         * Creates a new queue if the specified queue doesn't exist
          * @param queueName
         */
        public void createQueue(String queueName, boolean persistent) throws HornetQException {
          ClientSession.QueueQuery result = session.queueQuery(new SimpleString(queueName));   

       

          if(!result.isExists())
            session.createQueue(queueName, queueName, persistent);
        }

       

      The message is created like this:

       

      /* (non-Javadoc)
         * @see eventmw.apps.couponmatcher.EventProcessor#processEvent(java.lang.Object)
         */
        @Override
        public void processEvent(NumCorrectEvent numCorrect) {
          System.out.println("numCorrect=" + numCorrect.getNumCorrect());
          try {
            ClientMessage clientMessage = stompServer.getClientSession().createMessage(true);
            clientMessage.getBodyBuffer().writeNullableSimpleString(new SimpleString(String.valueOf(numCorrect.getNumCorrect())));     
            stompServer.sendSimpleMessage("coupon.client.numcorrect."+numCorrect.getOwner(), clientMessage);
          } catch (Exception e) {
            e.printStackTrace();
          }
        }

       

      The documented example uses TextMessage and setStringProperty, but I'm using ClientMessage and getBodyBuffer().writeNullableSimpleString. Is a last-value queue possible to achieve using this interface?