Interface ErrorListener


  • public interface ErrorListener
    This library groups problems into three categories:
    Errors
    The server sent an error message using the -err protocol operation.
    Exceptions
    A Java exception occurred, and was handled by the library.
    Slow Consumers
    One of the connections consumers, Subscription or Dispatcher, is slow, and starting to drop messages.

    All of these problems are reported to the application code using the ErrorListener. The listener is configured in the Options at creation time.

    • Method Detail

      • errorOccurred

        void errorOccurred​(Connection conn,
                           java.lang.String error)
        NATs related errors that occur asynchronously in the client library are sent to an ErrorListener via errorOccurred. The ErrorListener can use the error text to decide what to do about the problem.

        The text for an error is described in the protocol doc at `https://nats.io/documentation/internals/nats-protocol`.

        In some cases the server will close the clients connection after sending one of these errors. In that case, the connections ConnectionListener will be notified.

        Parameters:
        conn - The connection associated with the error
        error - The text of error that has occurred, directly from the server
      • exceptionOccurred

        void exceptionOccurred​(Connection conn,
                               java.lang.Exception exp)
        Exceptions that occur in the "normal" course of operations are sent to the ErrorListener using exceptionOccurred. Examples include, application exceptions during Dispatcher callbacks, IOExceptions from the underlying socket, etc.. The library will try to handle these, via reconnect or catching them, but they are forwarded here in case the application code needs them for debugging purposes.
        Parameters:
        conn - The connection associated with the error
        exp - The exception that has occurred, and was handled by the library
      • slowConsumerDetected

        void slowConsumerDetected​(Connection conn,
                                  Consumer consumer)
        Called by the connection when a "slow" consumer is detected. This call is only made once until the consumer stops being slow. At which point it will be called again if the consumer starts being slow again.

        See Consumer.setPendingLimits for information on how to configure when this method is fired.

        Slow consumers will result in dropped messages each consumer provides a method for retrieving the count of dropped messages, see Consumer.getDroppedCount.

        Parameters:
        conn - The connection associated with the error
        consumer - The consumer that is being marked slow