9 Replies Latest reply on Oct 15, 2010 4:51 PM by clebert.suconic

    ClientSessionFactory questions

    karlicontrol

      Hi, I expect to have a high volume of message throughput from producers and have some questions about how sessions and connections are used.  If I create a session factory as follows:

       

      factory = new ClientSessionFactoryImpl(
                                                  new TransportConfiguration(
                                                      "org.hornetq.core.remoting.impl.netty.NettyConnectorFactory", connectionParams));

       

      Is this factory backed by a single connection to the broker?  Can I create multiple sessions simultaneously?

       

      ClientSession session1 = factory.createSession(true, false, false, false);
      ClientSession session2 = factory.createSession(true, false, false, false);

      ClientSession session3 = factory.createSession(true, false, false, false);

      ClientProducer producer = session1.createProducer(queue);

      ClientProducer producer = session2.createProducer(queue);

      ClientProducer producer = session3.createProducer(queue);

      //create messages and send for each producer

      //close sessions

       

      Writing it like this seems strange but I will have a multithreaded environment and need to know if the factories can be used in this manner.  I saw Tim reverted support for session multiplexing, so I don't know what exactly I can do in place of that.  Due to the nature of the messages, I cannot batch them up and send all at once.

       

      Please help me understand how a factory is backed -- by one connection, multiple connections, one session, multiple sessions, etc.  Thank you!

       

      Karl

        • 1. Re: ClientSessionFactory questions
          clebert.suconic

          That should be fine. You can use it any way you want. (as long as you keep each session in a thread)

           

          (forinstance don't create multiple consumers in a single session and have multiple sessions using it)

           

          But the way you describe is fine.

          • 2. Re: ClientSessionFactory questions
            karlicontrol

            Thank you Clebert.  Is the factory backed by a single connection?  I may want to create multiple factories in that case.  And just to clarify, I should keep it to a single producer/consumer per session, right?  Even if they are used only by the session that created them, I should not use multiple at the same time?

             

            I just ran into an issue using delayed redelivery on a queue.  I hoped someone could shed some light on it.

             

            I narrowed it to an easy-to-reproduce test:

            1) Successfully write a message to a queue

            2) Start a receiver

            3) Read the message but do not acknowledge (auto acknowledge is turned off)

            4) I have a breakpoint set here, so I can confirm that the message count in the queue is still 1, even though I have read the message (good)

            5) I start a second receiver in a separate JVM, leaving the first one stuck at that breakpoint

            6) I confirm that the message is not delivered to the second receiver, while it is still waiting on the first to acknowledge (good)

            7) Now the problem... I waited a while to emulate the case the first receiver is hung, and after a significant wait, another receiver picked up the message originally read by the first receiver.

             

            I am not using transactions, and I thought the redelivery settings applied only if you're using transactions.  I'm just trying to use acknowledgement to ensure that the receiver is able to process the messages before acknowledging them.  What settings should I use to control the redelivery delay in my case?

             

            If the system goes down after receiving but before acknowledging, I want to know (approximately) when it will be redelivered so it can be picked up by another node's receiver.

             

            Thanks again for the help!

            Karl

            • 3. Re: ClientSessionFactory questions
              clebert.suconic

              You really should really read the manual.

               

              Look at the time to live section. you will get answer on why the message was not redelivered yet.

               

              Each Connection factory is backed by single TCP Connection. That's covered on the manual also.

              • 4. Re: ClientSessionFactory questions
                clebert.suconic

                Since you held a breakpoint in a message, you broke the ping/pong...what made the server to fail the client.. and hence re-deliver the message.

                • 5. Re: ClientSessionFactory questions
                  karlicontrol

                  Thank you Clebert.  I am referencing the manual -- thanks for the pointer.

                   

                  Just to clarify, if my client session were partially hung for some reason but the ping/pong on the connection were still succeeding, can I do anything to have the message redelivered?  Thanks.

                  • 6. Re: ClientSessionFactory questions
                    clebert.suconic

                    you were holding a breakpoint on debug.

                     

                    The message will be redelivered as soon as the client failure was perceived/realized on the server

                    • 7. Re: ClientSessionFactory questions
                      karlicontrol

                      Hi Clebert,

                       

                      Yes, I actually did understand that the ping/pong failed because the breakpoint interrupted my JVM.  Even if ping/pong is not broken, is there a way to force redelivery?  Duplicates are okay in this case.  I imagine there is an in-between state where a client can be someone hung in processing a message but not to the point that the ping/pong will break.  Thanks for any help.

                       

                      Karl

                      • 8. Re: ClientSessionFactory questions
                        clebert.suconic

                        If the ping/pong is not broken.. the message will be held on the consumer as long as you're not acking that:

                         

                        http://hornetq.sourceforge.net/docs/hornetq-2.1.2.Final/user-manual/en/html/connection-ttl.html

                         

                         

                        Look also at no buffering at consumers (or slow consumers). Maybe you need to set consumer-size to 0 depending on how your consumer is doing. Maybe what you meant is the message is at the client's buffer while your consumer is not getting more messages.

                         

                        http://hornetq.sourceforge.net/docs/hornetq-2.1.2.Final/user-manual/en/html/examples.html#examples.no-consumer-buffering

                         

                        http://hornetq.sourceforge.net/docs/hornetq-2.1.2.Final/user-manual/en/html/flow-control.html#d0e3611

                        • 9. Re: ClientSessionFactory questions
                          clebert.suconic

                          >> Even if ping/pong is not broken, is there a way to force redelivery? <<

                           

                          I'm not sure what you're suggesting here...

                          Messaging systems are supposed to guarantee the delivery of a message only once.

                           

                          The message won't be redelivered as long as you still have your messaging pending. You could close the connection without acknowledging what will force the redelivery based on a possible failure.