Class AutorecoveringConnection
java.lang.Object
com.rabbitmq.client.impl.recovery.AutorecoveringConnection
- All Implemented Interfaces:
- Connection,- NetworkConnection,- Recoverable,- RecoverableConnection,- ShutdownNotifier,- Closeable,- AutoCloseable
public class AutorecoveringConnection
extends Object
implements RecoverableConnection, NetworkConnection
Connection implementation that performs automatic recovery when
 connection shutdown is not initiated by the application (e.g. due to
 an I/O exception).
 Topology (exchanges, queues, bindings, and consumers) can be (and by default is) recovered
 as well, in this order:
 
- Exchanges
- Queues
- Bindings (both queue and exchange-to-exchange)
- Consumers
- Since:
- 3.3.0
- See Also:
- 
Field SummaryFields
- 
Constructor SummaryConstructorsConstructorDescriptionAutorecoveringConnection(ConnectionParams params, FrameHandlerFactory f, AddressResolver addressResolver) AutorecoveringConnection(ConnectionParams params, FrameHandlerFactory f, AddressResolver addressResolver, MetricsCollector metricsCollector, ObservationCollector observationCollector) AutorecoveringConnection(ConnectionParams params, FrameHandlerFactory f, List<Address> addrs) 
- 
Method SummaryModifier and TypeMethodDescriptionvoidabort()Abort this connection and all its channels with theAMQP.REPLY_SUCCESSclose code and message 'OK'.voidabort(int timeout) Abort this connection and all its channels with theAMQP.REPLY_SUCCESSclose code and message 'OK'.voidAbort this connection and all its channels.voidAbort this connection and all its channels.addBlockedListener(BlockedCallback blockedCallback, UnblockedCallback unblockedCallback) Add a lambda-basedBlockedListener.voidaddBlockedListener(BlockedListener listener) Add aBlockedListener.voidNot part of the public API.voidNot part of the public API.voidaddRecoveryListener(RecoveryListener listener) Adds the recovery listenervoidaddShutdownListener(ShutdownListener listener) Add shutdown listener.voidRemove allBlockedListeners.voidclose()Close this connection and all its channels with theAMQP.REPLY_SUCCESSclose code and message 'OK'.voidclose(int timeout) Close this connection and all its channels with theAMQP.REPLY_SUCCESSclose code and message 'OK'.voidClose this connection and all its channels.voidClose this connection and all its channels.Create a new channel, using an internally allocated channel number.createChannel(int channelNumber) Create a new channel, using the specified channel number if possible.voidexcludeQueueFromRecovery(String queue, boolean ifUnused) Exclude the queue from the list of queues to recover after connection failure.Retrieve the host.intGet the negotiated maximum channel number.Get a copy of the map of client properties sent to the serverReturns client-provided connection name, if any.Get the shutdown reason objectNot supposed to be used outside of automated tests.Get the exception handler.intGet the negotiated maximum frame size.intGet the negotiated heartbeat interval.getId()Public API - Returns a unique ID for this connection.Retrieve the local host.intRetrieve the local port number.intgetPort()Retrieve the port number.Retrieve the server properties.voidinit()Private API.booleanisOpen()Determine whether the component is currently open.voidProtected API - notify the listeners attached to the componentvoidrecoverBinding(RecordedBinding b, boolean retry) voidrecoverChannel(AutorecoveringChannel channel) voidRecover a closed channel and all topology (i.e.voidrecoverConsumer(String tag, RecordedConsumer consumer, boolean retry) Recover the consumer.voidrecoverExchange(RecordedExchange x, boolean retry) voidrecoverQueue(String oldName, RecordedQueue q, boolean retry) Recover the queue.booleanremoveBlockedListener(BlockedListener listener) Remove aBlockedListener.voidvoidvoidremoveRecoveryListener(RecoveryListener listener) Removes the recovery listenervoidremoveShutdownListener(ShutdownListener listener) Remove shutdown listener for the component.voidPublic API - Sets a unique ID for this connection.protected booleantoString()Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface com.rabbitmq.client.ConnectionopenChannel, openChannel
- 
Field Details- 
DEFAULT_CONNECTION_RECOVERY_TRIGGERING_CONDITIONpublic static final Predicate<ShutdownSignalException> DEFAULT_CONNECTION_RECOVERY_TRIGGERING_CONDITION
 
- 
- 
Constructor Details- 
AutorecoveringConnectionpublic AutorecoveringConnection(ConnectionParams params, FrameHandlerFactory f, List<Address> addrs) 
- 
AutorecoveringConnectionpublic AutorecoveringConnection(ConnectionParams params, FrameHandlerFactory f, AddressResolver addressResolver) 
- 
AutorecoveringConnectionpublic AutorecoveringConnection(ConnectionParams params, FrameHandlerFactory f, AddressResolver addressResolver, MetricsCollector metricsCollector, ObservationCollector observationCollector) 
 
- 
- 
Method Details- 
initPrivate API.- Throws:
- IOException
- TimeoutException
- See Also:
 
- 
createChannelDescription copied from interface:ConnectionCreate a new channel, using an internally allocated channel number. If automatic connection recovery is enabled, the channel returned by this method will beRecoverable.Use Connection.openChannel()if you want to use anOptionalto deal with a value.- Specified by:
- createChannelin interface- Connection
- Returns:
- a new channel descriptor, or null if none is available
- Throws:
- IOException- if an I/O problem is encountered
- See Also:
 
- 
createChannelDescription copied from interface:ConnectionCreate a new channel, using the specified channel number if possible.Use Connection.openChannel(int)if you want to use anOptionalto deal with a value.- Specified by:
- createChannelin interface- Connection
- Parameters:
- channelNumber- the channel number to allocate
- Returns:
- a new channel descriptor, or null if this channel number is already in use
- Throws:
- IOException- if an I/O problem is encountered
- See Also:
 
- 
getServerPropertiesDescription copied from interface:ConnectionRetrieve the server properties.- Specified by:
- getServerPropertiesin interface- Connection
- Returns:
- a map of the server properties. This typically includes the product name and version of the server.
- See Also:
 
- 
getClientPropertiesDescription copied from interface:ConnectionGet a copy of the map of client properties sent to the server- Specified by:
- getClientPropertiesin interface- Connection
- Returns:
- a copy of the map of client properties
- See Also:
 
- 
getClientProvidedNameDescription copied from interface:ConnectionReturns client-provided connection name, if any. Note that the value returned does not uniquely identify a connection and cannot be used as a connection identifier in HTTP API requests.- Specified by:
- getClientProvidedNamein interface- Connection
- Returns:
- client-provided connection name, if any
- See Also:
 
- 
getFrameMaxpublic int getFrameMax()Description copied from interface:ConnectionGet the negotiated maximum frame size.- Specified by:
- getFrameMaxin interface- Connection
- Returns:
- the maximum frame size, in octets; zero if unlimited
- See Also:
 
- 
getHeartbeatpublic int getHeartbeat()Description copied from interface:ConnectionGet the negotiated heartbeat interval.- Specified by:
- getHeartbeatin interface- Connection
- Returns:
- the heartbeat interval, in seconds; zero if none
- See Also:
 
- 
getChannelMaxpublic int getChannelMax()Description copied from interface:ConnectionGet the negotiated maximum channel number. Usable channel numbers range from 1 to this number, inclusive.- Specified by:
- getChannelMaxin interface- Connection
- Returns:
- the maximum channel number permitted for this connection.
- See Also:
 
- 
isOpenpublic boolean isOpen()Description copied from interface:ShutdownNotifierDetermine whether the component is currently open. Will return false if we are currently closing. Checking this method should be only for information, because of the race conditions - state can change after the call. Instead just execute and try to catch ShutdownSignalException and IOException- Specified by:
- isOpenin interface- ShutdownNotifier
- Returns:
- true when component is open, false otherwise
- See Also:
 
- 
closeDescription copied from interface:ConnectionClose this connection and all its channels with theAMQP.REPLY_SUCCESSclose code and message 'OK'. Waits for all the close operations to complete.- Specified by:
- closein interface- AutoCloseable
- Specified by:
- closein interface- Closeable
- Specified by:
- closein interface- Connection
- Throws:
- IOException- if an I/O problem is encountered
- See Also:
 
- 
closeDescription copied from interface:ConnectionClose this connection and all its channels with theAMQP.REPLY_SUCCESSclose code and message 'OK'. This method behaves in a similar way asConnection.close(), with the only difference that it waits with a provided timeout for all the close operations to complete. When timeout is reached the socket is forced to close.- Specified by:
- closein interface- Connection
- Parameters:
- timeout- timeout (in milliseconds) for completing all the close-related operations, use -1 for infinity
- Throws:
- IOException- if an I/O problem is encountered
- See Also:
 
- 
closeDescription copied from interface:ConnectionClose this connection and all its channels. Waits with the given timeout for all the close operations to complete. When timeout is reached the socket is forced to close.- Specified by:
- closein interface- Connection
- Parameters:
- closeCode- the close code (See under "Reply Codes" in the AMQP specification)
- closeMessage- a message indicating the reason for closing the connection
- timeout- timeout (in milliseconds) for completing all the close-related operations, use -1 for infinity
- Throws:
- IOException- if an I/O problem is encountered
- See Also:
 
- 
abortpublic void abort()Description copied from interface:ConnectionAbort this connection and all its channels with theAMQP.REPLY_SUCCESSclose code and message 'OK'. Forces the connection to close. Any encountered exceptions in the close operations are silently discarded.- Specified by:
- abortin interface- Connection
- See Also:
 
- 
abortDescription copied from interface:ConnectionAbort this connection and all its channels. Forces the connection to close and waits with the given timeout for all the close operations to complete. When timeout is reached the socket is forced to close. Any encountered exceptions in the close operations are silently discarded.- Specified by:
- abortin interface- Connection
- Parameters:
- closeCode- the close code (See under "Reply Codes" in the AMQP specification)
- closeMessage- a message indicating the reason for closing the connection
- timeout- timeout (in milliseconds) for completing all the close-related operations, use -1 for infinity
- See Also:
 
- 
abortDescription copied from interface:ConnectionAbort this connection and all its channels. Forces the connection to close and waits for all the close operations to complete. Any encountered exceptions in the close operations are silently discarded.- Specified by:
- abortin interface- Connection
- Parameters:
- closeCode- the close code (See under "Reply Codes" in the AMQP specification)
- closeMessage- a message indicating the reason for closing the connection
- See Also:
 
- 
abortpublic void abort(int timeout) Description copied from interface:ConnectionAbort this connection and all its channels with theAMQP.REPLY_SUCCESSclose code and message 'OK'. This method behaves in a similar way asConnection.abort(), with the only difference that it waits with a provided timeout for all the close operations to complete. When timeout is reached the socket is forced to close.- Specified by:
- abortin interface- Connection
- Parameters:
- timeout- timeout (in milliseconds) for completing all the close-related operations, use -1 for infinity
- See Also:
 
- 
getDelegateNot supposed to be used outside of automated tests.
- 
getCloseReasonDescription copied from interface:ShutdownNotifierGet the shutdown reason object- Specified by:
- getCloseReasonin interface- ShutdownNotifier
- Returns:
- ShutdownSignalException if component is closed, null otherwise
- See Also:
 
- 
addBlockedListenerDescription copied from interface:ConnectionAdd aBlockedListener.- Specified by:
- addBlockedListenerin interface- Connection
- Parameters:
- listener- the listener to add
- See Also:
 
- 
addBlockedListenerpublic BlockedListener addBlockedListener(BlockedCallback blockedCallback, UnblockedCallback unblockedCallback) Description copied from interface:ConnectionAdd a lambda-basedBlockedListener.- Specified by:
- addBlockedListenerin interface- Connection
- Parameters:
- blockedCallback- the callback when the connection is blocked
- unblockedCallback- the callback when the connection is unblocked
- Returns:
- the listener that wraps the callback
- See Also:
 
- 
removeBlockedListenerDescription copied from interface:ConnectionRemove aBlockedListener.- Specified by:
- removeBlockedListenerin interface- Connection
- Parameters:
- listener- the listener to remove
- Returns:
- trueif the listener was found and removed,- falseotherwise
- See Also:
 
- 
clearBlockedListenerspublic void clearBlockedListeners()Description copied from interface:ConnectionRemove allBlockedListeners.- Specified by:
- clearBlockedListenersin interface- Connection
- See Also:
 
- 
closeDescription copied from interface:ConnectionClose this connection and all its channels. Waits for all the close operations to complete.- Specified by:
- closein interface- Connection
- Parameters:
- closeCode- the close code (See under "Reply Codes" in the AMQP specification)
- closeMessage- a message indicating the reason for closing the connection
- Throws:
- IOException- if an I/O problem is encountered
- See Also:
 
- 
addShutdownListenerDescription copied from interface:ShutdownNotifierAdd shutdown listener. If the component is already closed, handler is fired immediately- Specified by:
- addShutdownListenerin interface- ShutdownNotifier
- Parameters:
- listener-- ShutdownListenerto the component
- See Also:
 
- 
removeShutdownListenerDescription copied from interface:ShutdownNotifierRemove shutdown listener for the component.- Specified by:
- removeShutdownListenerin interface- ShutdownNotifier
- Parameters:
- listener-- ShutdownListenerto be removed
- See Also:
 
- 
notifyListenerspublic void notifyListeners()Description copied from interface:ShutdownNotifierProtected API - notify the listeners attached to the component- Specified by:
- notifyListenersin interface- ShutdownNotifier
- See Also:
 
- 
addRecoveryListenerAdds the recovery listener- Specified by:
- addRecoveryListenerin interface- Recoverable
- Parameters:
- listener-- RecoveryListenerto execute after this connection recovers from network failure
 
- 
removeRecoveryListenerRemoves the recovery listener- Specified by:
- removeRecoveryListenerin interface- Recoverable
- Parameters:
- listener-- RecoveryListenerto remove
 
- 
getExceptionHandlerDescription copied from interface:ConnectionGet the exception handler.- Specified by:
- getExceptionHandlerin interface- Connection
- See Also:
 
- 
getPortpublic int getPort()Description copied from interface:ConnectionRetrieve the port number.- Specified by:
- getPortin interface- Connection
- Specified by:
- getPortin interface- NetworkConnection
- Returns:
- the port number of the peer we're connected to.
- See Also:
 
- 
getAddressDescription copied from interface:ConnectionRetrieve the host.- Specified by:
- getAddressin interface- Connection
- Specified by:
- getAddressin interface- NetworkConnection
- Returns:
- the hostname of the peer we're connected to.
- See Also:
 
- 
getLocalAddressDescription copied from interface:NetworkConnectionRetrieve the local host.- Specified by:
- getLocalAddressin interface- NetworkConnection
- Returns:
- client socket address
 
- 
getLocalPortpublic int getLocalPort()Description copied from interface:NetworkConnectionRetrieve the local port number.- Specified by:
- getLocalPortin interface- NetworkConnection
- Returns:
- client socket port
 
- 
shouldTriggerConnectionRecovery
- 
addQueueRecoveryListenerNot part of the public API. Mean to be used by JVM RabbitMQ clients that build on top of the Java client and need to be notified when server-named queue name changes after recovery.- Parameters:
- listener- listener that observes queue name changes after recovery
 
- 
removeQueueRecoveryListener- Parameters:
- listener- listener to be removed
- See Also:
 
- 
addConsumerRecoveryListenerNot part of the public API. Mean to be used by JVM RabbitMQ clients that build on top of the Java client and need to be notified when consumer tag changes after recovery.- Parameters:
- listener- listener that observes consumer tag changes after recovery
 
- 
removeConsumerRecoveryListener- Parameters:
- listener- listener to be removed
- See Also:
 
- 
recoverChannel- Throws:
- IOException
 
- 
recoverChannelAndTopologyRecover a closed channel and all topology (i.e. RecordedEntities) associated to it. Any errors will be sent to thegetExceptionHandler().- Parameters:
- channel- channel to recover
- Throws:
- IllegalArgumentException- if this channel is not owned by this connection
 
- 
recoverExchange
- 
recoverQueueRecover the queue. Any exceptions during recovery will be delivered to the connection'sExceptionHandler.- Parameters:
- oldName- queue name
- q- recorded queue
- retry- whether to retry the recovery if an error occurs and a RetryHandler was configured on the connection
 
- 
recoverBinding
- 
recoverConsumerRecover the consumer. Any exceptions during recovery will be delivered to the connection'sExceptionHandler.- Parameters:
- tag- consumer tag
- consumer- recorded consumer
- retry- whether to retry the recovery if an error occurs and a RetryHandler was configured on the connection
 
- 
excludeQueueFromRecoveryExclude the queue from the list of queues to recover after connection failure. Intended to be used in scenarios where you want to remove the queue from this connection's recovery list but don't want to delete the queue from the server. For example, in tests.- Parameters:
- queue- queue name to exclude from recorded recovery queues
- ifUnused- if true, the RecordedQueue will only be excluded if no local consumers are using it.
 
- 
getRecordedQueues
- 
getRecordedExchanges
- 
getRecordedBindings
- 
getRecordedConsumers
- 
toString
- 
getIdPublic API - Returns a unique ID for this connection. This ID must be unique, otherwise some services like the metrics collector won't work properly. This ID doesn't have to be provided by the client, services that require it will be assigned automatically if not set.- Specified by:
- getIdin interface- Connection
- Returns:
- unique ID for this connection.
 
- 
setIdPublic API - Sets a unique ID for this connection. This ID must be unique, otherwise some services like the metrics collector won't work properly. This ID doesn't have to be provided by the client, services that require it will be assigned automatically if not set.- Specified by:
- setIdin interface- Connection
 
 
-