0 Replies Latest reply on Sep 29, 2011 6:16 AM by Kshitiz Garg

    Storing and deleting App specific meta data on hornetQ

    Kshitiz Garg Newbie

      Hi,

       

      For our use cases, we need to store some app specfic meta-data on the hornetQ server. To do that, we are pushing this meta data with some string properties in our meta data queues.

       

      Code snippets:

       

      JVM1 (Meta data creator)

      Create session:

      serverLocator = HornetQClient.createServerLocatorWithoutHA(getTransportConfig());

      serverLocator.setConnectionTTL(3600000);

      clientSessionForPersistence = clientSessionFactory.createSession(userName, password, false, true, true, false, 1);

      clientSessionForPersistence.start();

       

      Create meta data queue:

       

      try {

                clientSessionForPersistence.createQueue(METADATA_QUEUE_NAME, METADATA_QUEUE_NAME, true);

      }

      catch (HornetQException e1) {

                if(e1.getCode() != HornetQException.QUEUE_EXISTS){

                          throw new CPESException(e1);

                }

      }

       

      Persisting meta data

       

      ClientMessage clientMessage = clientSessionForPersistence.createMessage(true);

      clientMessage.setExpiration(System.currentTimeMillis()+Integer.MAX_VALUE);

      clientMessage.putStringProperty(META_DATA_KEY, META_DATA_KEY_VALUE);

      clientMessage.setDeliveryCount(-1);

      messageProducer.send(getSimpleString(METADATA_QUEUE_NAME), clientMessage);

       

       

      JVM2 (Meta data reader)


      Create session:

       

      serverLocatorForMetaDataRead = HornetQClient.createServerLocatorWithoutHA(getTransportConfig());

      // have to set window size because I was not able to get messages again without restarting hornetQ. Could not understand that how did it start working after //the below change?

      serverLocatorForMetaDataRead.setConsumerWindowSize(0);

      clientSessionFactoryForMetaDataRead = serverLocatorForMetaDataRead.createSessionFactory();

      clientSessionForMetaDataRead = clientSessionFactoryForMetaDataRead.createSession(userName, password, false, false, false, false, 1);

      clientSessionForMetaDataRead.start();

       

      Receiving meta data


      ClientConsumer csmr = clientSessionForMetaDataRead.createConsumer(METADATA_QUEUE_NAME);

      QueueQuery q = clientSessionForMetaDataRead.queueQuery(new SimpleString(METADATA_QUEUE_NAME));

      long totalMessages = q.getMessageCount();

      System.out.println(totalMessages);

      for(int j =0; j <= totalMessages; j++){

                ClientMessage cm = csmr.receive(60000);

                if (cm!=null) {

                          System.out.println("Subscriber Id:" + cm.getProperty(META_DATA_KEY);

        }

      }

       

       

       

      The above code works (some things not pretty clear to me yet ). Anyway, now a new requirement is to delete some specific messages say having META_DATA_KEY='xyz'. I am not able to delete this message from JVM2 somehow. I have tried using cm.acknowledge() and cm.setExpiration(-1) but still messages are there in META_DATA_QUEUE. Can you please guide me for that?