Class AutorecoveringConnection
- java.lang.Object
-
- com.rabbitmq.client.impl.recovery.AutorecoveringConnection
-
- All Implemented Interfaces:
Connection
,NetworkConnection
,Recoverable
,RecoverableConnection
,ShutdownNotifier
,java.io.Closeable
,java.lang.AutoCloseable
public class AutorecoveringConnection extends java.lang.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
-
-
Field Summary
-
Constructor Summary
Constructors Constructor Description AutorecoveringConnection(ConnectionParams params, FrameHandlerFactory f, AddressResolver addressResolver)
AutorecoveringConnection(ConnectionParams params, FrameHandlerFactory f, AddressResolver addressResolver, MetricsCollector metricsCollector, ObservationCollector observationCollector)
AutorecoveringConnection(ConnectionParams params, FrameHandlerFactory f, java.util.List<Address> addrs)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
abort()
Abort this connection and all its channels with theAMQP.REPLY_SUCCESS
close code and message 'OK'.void
abort(int timeout)
Abort this connection and all its channels with theAMQP.REPLY_SUCCESS
close code and message 'OK'.void
abort(int closeCode, java.lang.String closeMessage)
Abort this connection and all its channels.void
abort(int closeCode, java.lang.String closeMessage, int timeout)
Abort this connection and all its channels.private void
addAutomaticRecoveryListener(RecoveryAwareAMQConnection newConn)
BlockedListener
addBlockedListener(BlockedCallback blockedCallback, UnblockedCallback unblockedCallback)
Add a lambda-basedBlockedListener
.void
addBlockedListener(BlockedListener listener)
Add aBlockedListener
.void
addConsumerRecoveryListener(ConsumerRecoveryListener listener)
Not part of the public API.void
addQueueRecoveryListener(QueueRecoveryListener listener)
Not part of the public API.void
addRecoveryListener(RecoveryListener listener)
Adds the recovery listenervoid
addShutdownListener(ShutdownListener listener)
Add shutdown listener.private void
beginAutomaticRecovery()
void
clearBlockedListeners()
Remove allBlockedListener
s.void
close()
Close this connection and all its channels with theAMQP.REPLY_SUCCESS
close code and message 'OK'.void
close(int timeout)
Close this connection and all its channels with theAMQP.REPLY_SUCCESS
close code and message 'OK'.void
close(int closeCode, java.lang.String closeMessage)
Close this connection and all its channels.void
close(int closeCode, java.lang.String closeMessage, int timeout)
Close this connection and all its channels.Channel
createChannel()
Create a new channel, using an internally allocated channel number.Channel
createChannel(int channelNumber)
Create a new channel, using the specified channel number if possible.(package private) RecordedConsumer
deleteRecordedConsumer(java.lang.String consumerTag)
(package private) void
deleteRecordedExchange(java.lang.String exchange)
(package private) boolean
deleteRecordedExchangeBinding(AutorecoveringChannel ch, java.lang.String destination, java.lang.String source, java.lang.String routingKey, java.util.Map<java.lang.String,java.lang.Object> arguments)
(package private) void
deleteRecordedQueue(java.lang.String queue)
(package private) boolean
deleteRecordedQueueBinding(AutorecoveringChannel ch, java.lang.String queue, java.lang.String exchange, java.lang.String routingKey, java.util.Map<java.lang.String,java.lang.Object> arguments)
void
excludeQueueFromRecovery(java.lang.String queue, boolean ifUnused)
Exclude the queue from the list of queues to recover after connection failure.java.net.InetAddress
getAddress()
Retrieve the host.int
getChannelMax()
Get the negotiated maximum channel number.java.util.Map<java.lang.String,java.lang.Object>
getClientProperties()
Get a copy of the map of client properties sent to the serverjava.lang.String
getClientProvidedName()
Returns client-provided connection name, if any.ShutdownSignalException
getCloseReason()
Get the shutdown reason objectAMQConnection
getDelegate()
Not supposed to be used outside of automated tests.ExceptionHandler
getExceptionHandler()
Get the exception handler.int
getFrameMax()
Get the negotiated maximum frame size.int
getHeartbeat()
Get the negotiated heartbeat interval.java.lang.String
getId()
Public API - Returns a unique ID for this connection.java.net.InetAddress
getLocalAddress()
Retrieve the local host.int
getLocalPort()
Retrieve the local port number.int
getPort()
Retrieve the port number.java.util.List<RecordedBinding>
getRecordedBindings()
java.util.Map<java.lang.String,RecordedConsumer>
getRecordedConsumers()
java.util.Map<java.lang.String,RecordedExchange>
getRecordedExchanges()
java.util.Map<java.lang.String,RecordedQueue>
getRecordedQueues()
(package private) RecoveredQueueNameSupplier
getRecoveredQueueNameSupplier()
java.util.Map<java.lang.String,java.lang.Object>
getServerProperties()
Retrieve the server properties.private <E extends RecordedEntity>
java.util.List<java.util.concurrent.Callable<java.lang.Object>>groupEntitiesByChannel(java.util.Collection<E> entities)
(package private) boolean
hasMoreConsumersOnQueue(java.util.Collection<RecordedConsumer> consumers, java.lang.String queue)
(package private) boolean
hasMoreDestinationsBoundToExchange(java.util.List<RecordedBinding> bindings, java.lang.String exchange)
void
init()
Private API.private void
internalRecoverConsumer(java.lang.String tag, RecordedConsumer consumer, boolean retry)
private void
internalRecoverQueue(java.lang.String oldName, RecordedQueue q, boolean retry)
boolean
isOpen()
Determine whether the component is currently open.private static TopologyRecoveryFilter
letAllPassFilter()
(package private) void
maybeDeleteRecordedAutoDeleteExchange(java.lang.String exchange)
(package private) void
maybeDeleteRecordedAutoDeleteQueue(java.lang.String queue)
void
notifyListeners()
Protected API - notify the listeners attached to the componentprivate void
notifyRecoveryListenersComplete()
private void
notifyRecoveryListenersStarted()
private void
notifyTopologyRecoveryListenersStarted()
private void
propagateQueueNameChangeToBindings(java.lang.String oldName, java.lang.String newName)
private void
propagateQueueNameChangeToConsumers(java.lang.String oldName, java.lang.String newName)
(package private) void
recordConsumer(java.lang.String result, RecordedConsumer consumer)
(package private) void
recordExchange(java.lang.String exchange, RecordedExchange x)
(package private) void
recordExchangeBinding(AutorecoveringChannel ch, java.lang.String destination, java.lang.String source, java.lang.String routingKey, java.util.Map<java.lang.String,java.lang.Object> arguments)
(package private) void
recordQueue(AMQP.Queue.DeclareOk ok, RecordedQueue q)
(package private) void
recordQueue(java.lang.String queue, RecordedQueue meta)
(package private) void
recordQueueBinding(AutorecoveringChannel ch, java.lang.String queue, java.lang.String exchange, java.lang.String routingKey, java.util.Map<java.lang.String,java.lang.Object> arguments)
void
recoverBinding(RecordedBinding b, boolean retry)
private void
recoverBlockedListeners(RecoveryAwareAMQConnection newConn)
void
recoverChannel(AutorecoveringChannel channel)
void
recoverChannelAndTopology(AutorecoveringChannel channel)
Recover a closed channel and all topology (i.e.private void
recoverChannels(RecoveryAwareAMQConnection newConn)
private RecoveryAwareAMQConnection
recoverConnection()
(package private) void
recoverConsumer(java.lang.String tag, RecordedConsumer consumer)
Recover the consumer.void
recoverConsumer(java.lang.String tag, RecordedConsumer consumer, boolean retry)
Recover the consumer.private void
recoverEntitiesAsynchronously(java.util.concurrent.ExecutorService executor, java.util.Collection<? extends RecordedEntity> recordedEntities)
void
recoverExchange(RecordedExchange x, boolean retry)
(package private) void
recoverQueue(java.lang.String oldName, RecordedQueue q)
Recover the queue.void
recoverQueue(java.lang.String oldName, RecordedQueue q, boolean retry)
Recover the queue.private void
recoverShutdownListeners(RecoveryAwareAMQConnection newConn)
private void
recoverTopology(java.util.concurrent.ExecutorService executor)
(package private) void
registerChannel(AutorecoveringChannel channel)
(package private) java.util.Set<RecordedBinding>
removeBindingsWithDestination(java.lang.String s)
boolean
removeBlockedListener(BlockedListener listener)
Remove aBlockedListener
.void
removeConsumerRecoveryListener(ConsumerRecoveryListener listener)
void
removeQueueRecoveryListener(QueueRecoveryListener listener)
void
removeRecoveryListener(RecoveryListener listener)
Removes the recovery listenervoid
removeShutdownListener(ShutdownListener listener)
Remove shutdown listener for the component.void
setId(java.lang.String id)
Public API - Sets a unique ID for this connection.private void
setupErrorOnWriteListenerForPotentialRecovery()
protected boolean
shouldTriggerConnectionRecovery(ShutdownSignalException cause)
java.lang.String
toString()
(package private) void
unregisterChannel(AutorecoveringChannel channel)
private Channel
wrapChannel(RecoveryAwareChannelN delegateChannel)
Creates a recovering channel from a regular channel and registers it.private <T> RetryResult
wrapRetryIfNecessary(RecordedEntity entity, java.util.concurrent.Callable<T> recoveryAction)
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.rabbitmq.client.Connection
openChannel, openChannel
-
-
-
-
Field Detail
-
DEFAULT_CONNECTION_RECOVERY_TRIGGERING_CONDITION
public static final java.util.function.Predicate<ShutdownSignalException> DEFAULT_CONNECTION_RECOVERY_TRIGGERING_CONDITION
-
LOGGER
private static final org.slf4j.Logger LOGGER
-
cf
private final RecoveryAwareAMQConnectionFactory cf
-
channels
private final java.util.Map<java.lang.Integer,AutorecoveringChannel> channels
-
params
private final ConnectionParams params
-
delegate
private volatile RecoveryAwareAMQConnection delegate
-
shutdownHooks
private final java.util.List<ShutdownListener> shutdownHooks
-
recoveryListeners
private final java.util.List<RecoveryListener> recoveryListeners
-
blockedListeners
private final java.util.List<BlockedListener> blockedListeners
-
recordedQueues
private final java.util.Map<java.lang.String,RecordedQueue> recordedQueues
-
recordedBindings
private final java.util.List<RecordedBinding> recordedBindings
-
recordedExchanges
private final java.util.Map<java.lang.String,RecordedExchange> recordedExchanges
-
consumers
private final java.util.Map<java.lang.String,RecordedConsumer> consumers
-
consumerRecoveryListeners
private final java.util.List<ConsumerRecoveryListener> consumerRecoveryListeners
-
queueRecoveryListeners
private final java.util.List<QueueRecoveryListener> queueRecoveryListeners
-
topologyRecoveryFilter
private final TopologyRecoveryFilter topologyRecoveryFilter
-
manuallyClosed
private volatile boolean manuallyClosed
-
recoveryLock
private final java.lang.Object recoveryLock
-
connectionRecoveryTriggeringCondition
private final java.util.function.Predicate<ShutdownSignalException> connectionRecoveryTriggeringCondition
-
retryHandler
private final RetryHandler retryHandler
-
recoveredQueueNameSupplier
private final RecoveredQueueNameSupplier recoveredQueueNameSupplier
-
-
Constructor Detail
-
AutorecoveringConnection
public AutorecoveringConnection(ConnectionParams params, FrameHandlerFactory f, java.util.List<Address> addrs)
-
AutorecoveringConnection
public AutorecoveringConnection(ConnectionParams params, FrameHandlerFactory f, AddressResolver addressResolver)
-
AutorecoveringConnection
public AutorecoveringConnection(ConnectionParams params, FrameHandlerFactory f, AddressResolver addressResolver, MetricsCollector metricsCollector, ObservationCollector observationCollector)
-
-
Method Detail
-
setupErrorOnWriteListenerForPotentialRecovery
private void setupErrorOnWriteListenerForPotentialRecovery()
-
letAllPassFilter
private static TopologyRecoveryFilter letAllPassFilter()
-
init
public void init() throws java.io.IOException, java.util.concurrent.TimeoutException
Private API.- Throws:
java.io.IOException
java.util.concurrent.TimeoutException
- See Also:
ConnectionFactory.newConnection(java.util.concurrent.ExecutorService)
-
createChannel
public Channel createChannel() throws java.io.IOException
Description copied from interface:Connection
Create 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 anOptional
to deal with a value.- Specified by:
createChannel
in interfaceConnection
- Returns:
- a new channel descriptor, or null if none is available
- Throws:
java.io.IOException
- if an I/O problem is encountered- See Also:
Connection.createChannel()
-
createChannel
public Channel createChannel(int channelNumber) throws java.io.IOException
Description copied from interface:Connection
Create a new channel, using the specified channel number if possible.Use
Connection.openChannel(int)
if you want to use anOptional
to deal with a value.- Specified by:
createChannel
in interfaceConnection
- Parameters:
channelNumber
- the channel number to allocate- Returns:
- a new channel descriptor, or null if this channel number is already in use
- Throws:
java.io.IOException
- if an I/O problem is encountered- See Also:
Connection.createChannel(int)
-
wrapChannel
private Channel wrapChannel(RecoveryAwareChannelN delegateChannel)
Creates a recovering channel from a regular channel and registers it. If the regular channel cannot be created (e.g. too many channels are open already), returns null.- Parameters:
delegateChannel
- Channel to wrap.- Returns:
- Recovering channel.
-
registerChannel
void registerChannel(AutorecoveringChannel channel)
-
unregisterChannel
void unregisterChannel(AutorecoveringChannel channel)
-
getServerProperties
public java.util.Map<java.lang.String,java.lang.Object> getServerProperties()
Description copied from interface:Connection
Retrieve the server properties.- Specified by:
getServerProperties
in interfaceConnection
- Returns:
- a map of the server properties. This typically includes the product name and version of the server.
- See Also:
Connection.getServerProperties()
-
getClientProperties
public java.util.Map<java.lang.String,java.lang.Object> getClientProperties()
Description copied from interface:Connection
Get a copy of the map of client properties sent to the server- Specified by:
getClientProperties
in interfaceConnection
- Returns:
- a copy of the map of client properties
- See Also:
Connection.getClientProperties()
-
getClientProvidedName
public java.lang.String getClientProvidedName()
Description copied from interface:Connection
Returns 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:
getClientProvidedName
in interfaceConnection
- Returns:
- client-provided connection name, if any
- See Also:
Connection.getClientProvidedName()
,ConnectionFactory.newConnection(Address[], String)
,ConnectionFactory.newConnection(ExecutorService, Address[], String)
-
getFrameMax
public int getFrameMax()
Description copied from interface:Connection
Get the negotiated maximum frame size.- Specified by:
getFrameMax
in interfaceConnection
- Returns:
- the maximum frame size, in octets; zero if unlimited
- See Also:
Connection.getFrameMax()
-
getHeartbeat
public int getHeartbeat()
Description copied from interface:Connection
Get the negotiated heartbeat interval.- Specified by:
getHeartbeat
in interfaceConnection
- Returns:
- the heartbeat interval, in seconds; zero if none
- See Also:
Connection.getHeartbeat()
-
getChannelMax
public int getChannelMax()
Description copied from interface:Connection
Get the negotiated maximum channel number. Usable channel numbers range from 1 to this number, inclusive.- Specified by:
getChannelMax
in interfaceConnection
- Returns:
- the maximum channel number permitted for this connection.
- See Also:
Connection.getChannelMax()
-
isOpen
public boolean isOpen()
Description copied from interface:ShutdownNotifier
Determine 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:
isOpen
in interfaceShutdownNotifier
- Returns:
- true when component is open, false otherwise
- See Also:
ShutdownNotifier.isOpen()
-
close
public void close() throws java.io.IOException
Description copied from interface:Connection
Close this connection and all its channels with theAMQP.REPLY_SUCCESS
close code and message 'OK'. Waits for all the close operations to complete.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Specified by:
close
in interfaceConnection
- Throws:
java.io.IOException
- if an I/O problem is encountered- See Also:
Connection.close()
-
close
public void close(int timeout) throws java.io.IOException
Description copied from interface:Connection
Close this connection and all its channels with theAMQP.REPLY_SUCCESS
close 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:
close
in interfaceConnection
- Parameters:
timeout
- timeout (in milliseconds) for completing all the close-related operations, use -1 for infinity- Throws:
java.io.IOException
- if an I/O problem is encountered- See Also:
Connection.close(int)
-
close
public void close(int closeCode, java.lang.String closeMessage, int timeout) throws java.io.IOException
Description copied from interface:Connection
Close 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:
close
in interfaceConnection
- Parameters:
closeCode
- the close code (See under "Reply Codes" in the AMQP specification)closeMessage
- a message indicating the reason for closing the connectiontimeout
- timeout (in milliseconds) for completing all the close-related operations, use -1 for infinity- Throws:
java.io.IOException
- if an I/O problem is encountered- See Also:
Connection.close(int, String, int)
-
abort
public void abort()
Description copied from interface:Connection
Abort this connection and all its channels with theAMQP.REPLY_SUCCESS
close code and message 'OK'. Forces the connection to close. Any encountered exceptions in the close operations are silently discarded.- Specified by:
abort
in interfaceConnection
- See Also:
Connection.abort()
-
abort
public void abort(int closeCode, java.lang.String closeMessage, int timeout)
Description copied from interface:Connection
Abort 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:
abort
in interfaceConnection
- Parameters:
closeCode
- the close code (See under "Reply Codes" in the AMQP specification)closeMessage
- a message indicating the reason for closing the connectiontimeout
- timeout (in milliseconds) for completing all the close-related operations, use -1 for infinity- See Also:
Connection.abort(int, String, int)
-
abort
public void abort(int closeCode, java.lang.String closeMessage)
Description copied from interface:Connection
Abort 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:
abort
in interfaceConnection
- 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:
Connection.abort(int, String)
-
abort
public void abort(int timeout)
Description copied from interface:Connection
Abort this connection and all its channels with theAMQP.REPLY_SUCCESS
close 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:
abort
in interfaceConnection
- Parameters:
timeout
- timeout (in milliseconds) for completing all the close-related operations, use -1 for infinity- See Also:
Connection.abort(int)
-
getDelegate
public AMQConnection getDelegate()
Not supposed to be used outside of automated tests.
-
getCloseReason
public ShutdownSignalException getCloseReason()
Description copied from interface:ShutdownNotifier
Get the shutdown reason object- Specified by:
getCloseReason
in interfaceShutdownNotifier
- Returns:
- ShutdownSignalException if component is closed, null otherwise
- See Also:
ShutdownNotifier.getCloseReason()
-
addBlockedListener
public void addBlockedListener(BlockedListener listener)
Description copied from interface:Connection
Add aBlockedListener
.- Specified by:
addBlockedListener
in interfaceConnection
- Parameters:
listener
- the listener to add- See Also:
ShutdownNotifier.addShutdownListener(com.rabbitmq.client.ShutdownListener)
-
addBlockedListener
public BlockedListener addBlockedListener(BlockedCallback blockedCallback, UnblockedCallback unblockedCallback)
Description copied from interface:Connection
Add a lambda-basedBlockedListener
.- Specified by:
addBlockedListener
in interfaceConnection
- Parameters:
blockedCallback
- the callback when the connection is blockedunblockedCallback
- the callback when the connection is unblocked- Returns:
- the listener that wraps the callback
- See Also:
BlockedListener
,BlockedCallback
,UnblockedCallback
-
removeBlockedListener
public boolean removeBlockedListener(BlockedListener listener)
Description copied from interface:Connection
Remove aBlockedListener
.- Specified by:
removeBlockedListener
in interfaceConnection
- Parameters:
listener
- the listener to remove- Returns:
true
if the listener was found and removed,false
otherwise- See Also:
Connection.removeBlockedListener(com.rabbitmq.client.BlockedListener)
-
clearBlockedListeners
public void clearBlockedListeners()
Description copied from interface:Connection
Remove allBlockedListener
s.- Specified by:
clearBlockedListeners
in interfaceConnection
- See Also:
Connection.clearBlockedListeners()
-
close
public void close(int closeCode, java.lang.String closeMessage) throws java.io.IOException
Description copied from interface:Connection
Close this connection and all its channels. Waits for all the close operations to complete.- Specified by:
close
in interfaceConnection
- Parameters:
closeCode
- the close code (See under "Reply Codes" in the AMQP specification)closeMessage
- a message indicating the reason for closing the connection- Throws:
java.io.IOException
- if an I/O problem is encountered- See Also:
Connection.close(int, String)
-
addShutdownListener
public void addShutdownListener(ShutdownListener listener)
Description copied from interface:ShutdownNotifier
Add shutdown listener. If the component is already closed, handler is fired immediately- Specified by:
addShutdownListener
in interfaceShutdownNotifier
- Parameters:
listener
-ShutdownListener
to the component- See Also:
ShutdownNotifier.addShutdownListener(com.rabbitmq.client.ShutdownListener)
-
removeShutdownListener
public void removeShutdownListener(ShutdownListener listener)
Description copied from interface:ShutdownNotifier
Remove shutdown listener for the component.- Specified by:
removeShutdownListener
in interfaceShutdownNotifier
- Parameters:
listener
-ShutdownListener
to be removed- See Also:
ShutdownNotifier.removeShutdownListener(com.rabbitmq.client.ShutdownListener)
-
notifyListeners
public void notifyListeners()
Description copied from interface:ShutdownNotifier
Protected API - notify the listeners attached to the component- Specified by:
notifyListeners
in interfaceShutdownNotifier
- See Also:
ShutdownNotifier.notifyListeners()
-
addRecoveryListener
public void addRecoveryListener(RecoveryListener listener)
Adds the recovery listener- Specified by:
addRecoveryListener
in interfaceRecoverable
- Parameters:
listener
-RecoveryListener
to execute after this connection recovers from network failure
-
removeRecoveryListener
public void removeRecoveryListener(RecoveryListener listener)
Removes the recovery listener- Specified by:
removeRecoveryListener
in interfaceRecoverable
- Parameters:
listener
-RecoveryListener
to remove
-
getExceptionHandler
public ExceptionHandler getExceptionHandler()
Description copied from interface:Connection
Get the exception handler.- Specified by:
getExceptionHandler
in interfaceConnection
- See Also:
AMQConnection.getExceptionHandler()
-
getPort
public int getPort()
Description copied from interface:Connection
Retrieve the port number.- Specified by:
getPort
in interfaceConnection
- Specified by:
getPort
in interfaceNetworkConnection
- Returns:
- the port number of the peer we're connected to.
- See Also:
Connection.getPort()
-
getAddress
public java.net.InetAddress getAddress()
Description copied from interface:Connection
Retrieve the host.- Specified by:
getAddress
in interfaceConnection
- Specified by:
getAddress
in interfaceNetworkConnection
- Returns:
- the hostname of the peer we're connected to.
- See Also:
Connection.getAddress()
-
getLocalAddress
public java.net.InetAddress getLocalAddress()
Description copied from interface:NetworkConnection
Retrieve the local host.- Specified by:
getLocalAddress
in interfaceNetworkConnection
- Returns:
- client socket address
-
getLocalPort
public int getLocalPort()
Description copied from interface:NetworkConnection
Retrieve the local port number.- Specified by:
getLocalPort
in interfaceNetworkConnection
- Returns:
- client socket port
-
addAutomaticRecoveryListener
private void addAutomaticRecoveryListener(RecoveryAwareAMQConnection newConn)
-
shouldTriggerConnectionRecovery
protected boolean shouldTriggerConnectionRecovery(ShutdownSignalException cause)
-
addQueueRecoveryListener
public void addQueueRecoveryListener(QueueRecoveryListener listener)
Not 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
public void removeQueueRecoveryListener(QueueRecoveryListener listener)
- Parameters:
listener
- listener to be removed- See Also:
addQueueRecoveryListener(com.rabbitmq.client.impl.recovery.QueueRecoveryListener)
-
addConsumerRecoveryListener
public void addConsumerRecoveryListener(ConsumerRecoveryListener listener)
Not 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
public void removeConsumerRecoveryListener(ConsumerRecoveryListener listener)
- Parameters:
listener
- listener to be removed- See Also:
addConsumerRecoveryListener(ConsumerRecoveryListener)
-
getRecoveredQueueNameSupplier
RecoveredQueueNameSupplier getRecoveredQueueNameSupplier()
-
beginAutomaticRecovery
private void beginAutomaticRecovery() throws java.lang.InterruptedException
- Throws:
java.lang.InterruptedException
-
recoverShutdownListeners
private void recoverShutdownListeners(RecoveryAwareAMQConnection newConn)
-
recoverBlockedListeners
private void recoverBlockedListeners(RecoveryAwareAMQConnection newConn)
-
recoverConnection
private RecoveryAwareAMQConnection recoverConnection() throws java.lang.InterruptedException
- Throws:
java.lang.InterruptedException
-
recoverChannels
private void recoverChannels(RecoveryAwareAMQConnection newConn)
-
recoverChannel
public void recoverChannel(AutorecoveringChannel channel) throws java.io.IOException
- Throws:
java.io.IOException
-
notifyRecoveryListenersComplete
private void notifyRecoveryListenersComplete()
-
notifyRecoveryListenersStarted
private void notifyRecoveryListenersStarted()
-
notifyTopologyRecoveryListenersStarted
private void notifyTopologyRecoveryListenersStarted()
-
recoverChannelAndTopology
public void recoverChannelAndTopology(AutorecoveringChannel channel)
Recover 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:
java.lang.IllegalArgumentException
- if this channel is not owned by this connection
-
recoverTopology
private void recoverTopology(java.util.concurrent.ExecutorService executor)
-
recoverExchange
public void recoverExchange(RecordedExchange x, boolean retry)
-
recoverQueue
public void recoverQueue(java.lang.String oldName, RecordedQueue q, boolean retry)
Recover the queue. Any exceptions during recovery will be delivered to the connection'sExceptionHandler
.- Parameters:
oldName
- queue nameq
- recorded queueretry
- whether to retry the recovery if an error occurs and a RetryHandler was configured on the connection
-
recoverQueue
void recoverQueue(java.lang.String oldName, RecordedQueue q) throws java.lang.Exception
Recover the queue. Errors are not retried and not delivered to the connection'sExceptionHandler
- Parameters:
oldName
- queue nameq
- recorded queue- Throws:
java.lang.Exception
- if an error occurs recovering the queue
-
internalRecoverQueue
private void internalRecoverQueue(java.lang.String oldName, RecordedQueue q, boolean retry) throws java.lang.Exception
- Throws:
java.lang.Exception
-
recoverBinding
public void recoverBinding(RecordedBinding b, boolean retry)
-
recoverConsumer
public void recoverConsumer(java.lang.String tag, RecordedConsumer consumer, boolean retry)
Recover the consumer. Any exceptions during recovery will be delivered to the connection'sExceptionHandler
.- Parameters:
tag
- consumer tagconsumer
- recorded consumerretry
- whether to retry the recovery if an error occurs and a RetryHandler was configured on the connection
-
recoverConsumer
void recoverConsumer(java.lang.String tag, RecordedConsumer consumer) throws java.lang.Exception
Recover the consumer. Errors are not retried and not delivered to the connection'sExceptionHandler
- Parameters:
tag
- consumer tagconsumer
- recorded consumer- Throws:
java.lang.Exception
- if an error occurs recovering the consumer
-
internalRecoverConsumer
private void internalRecoverConsumer(java.lang.String tag, RecordedConsumer consumer, boolean retry) throws java.lang.Exception
- Throws:
java.lang.Exception
-
wrapRetryIfNecessary
private <T> RetryResult wrapRetryIfNecessary(RecordedEntity entity, java.util.concurrent.Callable<T> recoveryAction) throws java.lang.Exception
- Throws:
java.lang.Exception
-
propagateQueueNameChangeToBindings
private void propagateQueueNameChangeToBindings(java.lang.String oldName, java.lang.String newName)
-
propagateQueueNameChangeToConsumers
private void propagateQueueNameChangeToConsumers(java.lang.String oldName, java.lang.String newName)
-
recoverEntitiesAsynchronously
private void recoverEntitiesAsynchronously(java.util.concurrent.ExecutorService executor, java.util.Collection<? extends RecordedEntity> recordedEntities) throws java.lang.InterruptedException
- Throws:
java.lang.InterruptedException
-
groupEntitiesByChannel
private <E extends RecordedEntity> java.util.List<java.util.concurrent.Callable<java.lang.Object>> groupEntitiesByChannel(java.util.Collection<E> entities)
-
recordQueueBinding
void recordQueueBinding(AutorecoveringChannel ch, java.lang.String queue, java.lang.String exchange, java.lang.String routingKey, java.util.Map<java.lang.String,java.lang.Object> arguments)
-
deleteRecordedQueueBinding
boolean deleteRecordedQueueBinding(AutorecoveringChannel ch, java.lang.String queue, java.lang.String exchange, java.lang.String routingKey, java.util.Map<java.lang.String,java.lang.Object> arguments)
-
recordExchangeBinding
void recordExchangeBinding(AutorecoveringChannel ch, java.lang.String destination, java.lang.String source, java.lang.String routingKey, java.util.Map<java.lang.String,java.lang.Object> arguments)
-
deleteRecordedExchangeBinding
boolean deleteRecordedExchangeBinding(AutorecoveringChannel ch, java.lang.String destination, java.lang.String source, java.lang.String routingKey, java.util.Map<java.lang.String,java.lang.Object> arguments)
-
recordQueue
void recordQueue(AMQP.Queue.DeclareOk ok, RecordedQueue q)
-
recordQueue
void recordQueue(java.lang.String queue, RecordedQueue meta)
-
deleteRecordedQueue
void deleteRecordedQueue(java.lang.String queue)
-
excludeQueueFromRecovery
public void excludeQueueFromRecovery(java.lang.String queue, boolean ifUnused)
Exclude the queue from the list of queues to recover after connection failure. Intended to be used in usecases where you want to remove the queue from this connection's recovery list but don't want to delete the queue from the server.- Parameters:
queue
- queue name to exclude from recorded recovery queuesifUnused
- if true, the RecordedQueue will only be excluded if no local consumers are using it.
-
recordExchange
void recordExchange(java.lang.String exchange, RecordedExchange x)
-
deleteRecordedExchange
void deleteRecordedExchange(java.lang.String exchange)
-
recordConsumer
void recordConsumer(java.lang.String result, RecordedConsumer consumer)
-
deleteRecordedConsumer
RecordedConsumer deleteRecordedConsumer(java.lang.String consumerTag)
-
maybeDeleteRecordedAutoDeleteQueue
void maybeDeleteRecordedAutoDeleteQueue(java.lang.String queue)
-
maybeDeleteRecordedAutoDeleteExchange
void maybeDeleteRecordedAutoDeleteExchange(java.lang.String exchange)
-
hasMoreDestinationsBoundToExchange
boolean hasMoreDestinationsBoundToExchange(java.util.List<RecordedBinding> bindings, java.lang.String exchange)
-
hasMoreConsumersOnQueue
boolean hasMoreConsumersOnQueue(java.util.Collection<RecordedConsumer> consumers, java.lang.String queue)
-
removeBindingsWithDestination
java.util.Set<RecordedBinding> removeBindingsWithDestination(java.lang.String s)
-
getRecordedQueues
public java.util.Map<java.lang.String,RecordedQueue> getRecordedQueues()
-
getRecordedExchanges
public java.util.Map<java.lang.String,RecordedExchange> getRecordedExchanges()
-
getRecordedBindings
public java.util.List<RecordedBinding> getRecordedBindings()
-
getRecordedConsumers
public java.util.Map<java.lang.String,RecordedConsumer> getRecordedConsumers()
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
getId
public java.lang.String getId()
Public 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:
getId
in interfaceConnection
- Returns:
- unique ID for this connection.
-
setId
public void setId(java.lang.String id)
Public 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:
setId
in interfaceConnection
-
-