2 Replies Latest reply on Jun 21, 2010 9:52 AM by diktatoren

    Last-value queue

    diktatoren

      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?

        • 1. Re: Last-value queue
          jmesnil

          You don't use Last-value queue like you should.

          See the doc http://hornetq.sourceforge.net/docs/hornetq-2.1.0.Final/user-manual/en/html/last-value-queues.html.

          You must pass a string property value for the Last-Value property "_HQ_LVQ_NAME"

          If you are using HornetQ Core API, you must use message.putStringProperty(String, String) to have it work. If you use the message body, HornetQ will not find the last-value queue property.

          Tell me how it goes,

          jeff

          • 2. Re: Last-value queue
            diktatoren

            Hi Jeff,

             

            I got it to work by assigning a value to the StringProperty marked as last value:

             

            ClientMessage clientMessage = stompServer.getClientSession().createMessage(true);
            clientMessage.putStringProperty("_HQ_LVQ_NAME", "ANTALLRETTE");
            clientMessage.putStringProperty("ANTALLRETTE", String.valueOf(numCorrect.getNumCorrect()));

             

            In order for the perl STOMP client to be able to access the content, I still have to put the same value in the message body, but it's a workaround I'm able to live with. Thanks again!

             

            Pål