6 Replies Latest reply on Apr 23, 2010 8:03 AM by Nico Nico

    ExceptionListener in HornetQ

    Nico Nico Newbie

      Hi mates! I'm looking how to configure HorentQ to reconnect in case of connection failures. Looking at the docs (and also in this issue https://jira.jboss.org/jira/browse/HORNETQ-121) it's not clear to me if I have to define an ExceptionListener or not to make the reconnection possible.

       

      In section 34.3 of the docs state that

       

      If your client does manage to reconnect but the session is no longer available on the server, for instance if the server has been restarted or it has timed out, then the client won't be able to re-attach, and any ExceptionListener or FailureListener instances registered on the connection or session will be called.

       

      So I undestand that an ExceptionListener should be needed in this case. But then in section 34.4 I read that

       

      Please note, that when a client reconnects or re-attaches, any registered JMS ExceptionListener or core API SessionFailureListener will be called.

       

      It seems to me that if I put code to manual reconnect in the ExceptionListener (to solve the problem in 34.3), but an automatic reconnection occurs and the ExceptionListener is also called, the connection will be destroyed and recreated twice.

       

      Do I undestand wrong? How can I bypass this situation?

       

      By the way, I'm using HornetQ with JMS Service in Jboss 4.2.3, so I'm planning to add the reconnect configuration in the connection factory directly (hornetq-jms.xml).

       

      Thanks in advance,

        • 1. Re: ExceptionListener in HornetQ
          Leos Bitto Novice

          Let me quote part of the chapter 4.3.8 of the JMS 1.1 specification for you: "If a JMS provider detects a problem with a connection, it will inform the
          connection’s ExceptionListener, if one has been registered. ... A JMS provider should attempt to resolve connection problems itself prior to notifying the client of them.". The javadoc at http://java.sun.com/j2ee/1.4/docs/api/javax/jms/ExceptionListener.html states the same. So I would think that if the JMS provider is able to resolve the problem itself (like a successful transparent reconnecting to the server, for example), the ExceptionListener should not be called.

          • 2. Re: ExceptionListener in HornetQ
            Andy Taylor Master

            It wouldnt make sense to do both, you either do the reconnect yourself or configure HornetQ to do it transparently.

            • 3. Re: ExceptionListener in HornetQ
              Leos Bitto Novice

              Andy Taylor wrote:

               

              It wouldnt make sense to do both, you either do the reconnect yourself or configure HornetQ to do it transparently.

               

              The main remaining question is: if HornetQ does successful transparent reconnect, would it call the ExceptionListener or not? And the less important question would be: if HornetQ is configured to do the transparent reconnect, but it is unable to do so (for example because no server is available), would it call the ExceptionListener? And one more question if the answer to the previous two questions would be true: how is the ExceptionListener able to distinguish between those two cases?

              • 4. Re: ExceptionListener in HornetQ
                Andy Taylor Master

                Leos Bitto wrote:

                 

                Andy Taylor wrote:

                 

                It wouldnt make sense to do both, you either do the reconnect yourself or configure HornetQ to do it transparently.

                 

                The main remaining question is: if HornetQ does successful transparent reconnect, would it call the ExceptionListener or not? And the less important question would be: if HornetQ is configured to do the transparent reconnect, but it is unable to do so (for example because no server is available), would it call the ExceptionListener? And one more question if the answer to the previous two questions would be true: how is the ExceptionListener able to distinguish between those two cases?

                if hornetq reconnects then the exception listeners won't get called, in effect as far as the client is concerned there has been no problem. depending on what reconnect attempts is set to, -1 is infinite i think, if the client cant reconnect then the exception listeners will be called.

                 

                also make sure u understand the difference between reconnect and reattach, this is explained in the manual.

                • 5. Re: ExceptionListener in HornetQ
                  Leos Bitto Novice

                  Andy Taylor wrote:

                   

                  Leos Bitto wrote:

                   

                   

                  The main remaining question is: if HornetQ does successful transparent reconnect, would it call the ExceptionListener or not? And the less important question would be: if HornetQ is configured to do the transparent reconnect, but it is unable to do so (for example because no server is available), would it call the ExceptionListener? And one more question if the answer to the previous two questions would be true: how is the ExceptionListener able to distinguish between those two cases?

                  if hornetq reconnects then the exception listeners won't get called, in effect as far as the client is concerned there has been no problem. depending on what reconnect attempts is set to, -1 is infinite i think, if the client cant reconnect then the exception listeners will be called.

                   

                  also make sure u understand the difference between reconnect and reattach, this is explained in the manual.

                   

                  Thanks for the answers. Would you please answer the same questions with reattach instead of reconnect?

                  • 6. Re: ExceptionListener in HornetQ
                    Nico Nico Newbie

                    Hi Andy! Thanks for your help.

                     

                    What your are saying is exactly what I think it should behave, but that isn't what I undestand by two things, first one comment of Tim Fox in the JIRA that post before

                    Since you're doing manual reconnection - i.e. you've coded your own reconnection code in your ExceptionListener, you should have reconnectAttempts set to zero (which is the default).
                    ReconnectAttempts determines how many times it will automatically try to reconnect after failure.
                    Having it automatically reconnect, only for you to then manually close and recreate again the connections does not make sense.

                     

                    And also because the pharse in section 34.4 of the manual

                    Please note, that when a client reconnects or re-attaches, any registered JMS ExceptionListener or core API SessionFailureListener will be called.

                     

                    What I understand here is that if HornetQ succesfull reconnect or reattach, it will also call the ExceptionListener after that.

                     

                    Of course I don't saying your are lying! I relly appreciate your help and I only want to undestand exactly whats the expected behave