1 Reply Latest reply on Dec 22, 2010 8:34 PM by jombo wang

    should the StompSession be stoped when get a SUBSCRIBE command

    jombo wang Newbie

      hi all:

           i have checked the source code of org.hornetq.core.protocol.stomp.StompSession and i find that when the server gets the SUBSCRIBE command, it will get the exist session or create a new session (if not exist)and start it to make the comsumer to revieve message. the method "addSubscription" in StompSession:

            session.createConsumer(consumerID, queue, SimpleString.toSimpleString(selector), false);
            session.receiveConsumerCredits(consumerID, -1);
            StompSubscription subscription = new StompSubscription(subscriptionID, ack);
            subscriptions.put(consumerID, subscription);
            // FIXME not very smart: since we can't start the consumer, we start the session
            // every time to start the new consumer (and all previous consumers...)



      if every StompSession only allow once SUBSCRIBE command,it goes well. but suppose that if i continuely send SUBSCRIBE and UNSUBSCRIBE command in once Connect  , there is some problems. because the first geting SUBSCRIBE,  StompSession  starts the session and it dose not close the session until it recieve the DISCONNECT command.  So this may result that : the subsequent SUBSCRIBE command makes the new created Consumer immediately recieve messages after

        session.receiveConsumerCredits(consumerID, -1);


      when the message arrives, these codes

      subscriptions.put(consumerID, subscription);

      maybe not be executed . so when the method "sendMessage" maybe throw a NullPointException.


      so my quese tion is that :when server gets UNSUBSCRIBE command .should we stop the session first. is this a bug ?