public abstract class AbstractConnectionFactory extends Object implements ConnectionFactory, DisposableBean, BeanNameAware, ApplicationContextAware, ApplicationEventPublisherAware, ApplicationListener<ContextClosedEvent>, com.rabbitmq.client.ShutdownListener
Modifier and Type | Class and Description |
---|---|
static class |
AbstractConnectionFactory.AddressShuffleMode
The mode used to shuffle the addresses.
|
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_CLOSE_TIMEOUT |
protected Log |
logger |
Constructor and Description |
---|
AbstractConnectionFactory(com.rabbitmq.client.ConnectionFactory rabbitConnectionFactory)
Create a new AbstractConnectionFactory for the given target ConnectionFactory,
with no publisher connection factory.
|
Modifier and Type | Method and Description |
---|---|
void |
addChannelListener(ChannelListener listener) |
void |
addConnectionListener(ConnectionListener listener) |
void |
clearConnectionListeners() |
protected Connection |
createBareConnection() |
void |
destroy() |
protected void |
doSetPublisherConnectionFactory(AbstractConnectionFactory publisherConnectionFactory) |
protected ApplicationContext |
getApplicationContext() |
protected ApplicationEventPublisher |
getApplicationEventPublisher() |
protected String |
getBeanName()
Return a bean name of the component or null if not a bean.
|
protected ChannelListener |
getChannelListener()
A composite channel listener to be used by subclasses when creating and closing channels.
|
int |
getCloseTimeout() |
protected ConnectionListener |
getConnectionListener()
A composite connection listener to be used by subclasses when creating and closing connections.
|
protected ConnectionNameStrategy |
getConnectionNameStrategy() |
protected boolean |
getContextStopped() |
protected String |
getDefaultHostName() |
protected ExecutorService |
getExecutorService() |
String |
getHost() |
int |
getPort() |
ConnectionFactory |
getPublisherConnectionFactory()
Return a separate connection factory for publishers (if implemented).
|
com.rabbitmq.client.ConnectionFactory |
getRabbitConnectionFactory()
Return a reference to the underlying Rabbit Connection factory.
|
String |
getUsername()
Return the user name from the underlying rabbit connection factory.
|
String |
getVirtualHost() |
boolean |
hasPublisherConnectionFactory() |
void |
onApplicationEvent(ContextClosedEvent event) |
boolean |
removeConnectionListener(ConnectionListener listener) |
void |
setAddresses(String addresses)
Set addresses for clustering.
|
void |
setAddressResolver(com.rabbitmq.client.AddressResolver addressResolver)
Set an
AddressResolver to use when creating connections; overrides
setAddresses(String) , setHost(String) , and setPort(int) . |
void |
setAddressShuffleMode(AbstractConnectionFactory.AddressShuffleMode addressShuffleMode)
Set the mode for shuffling addresses.
|
void |
setApplicationContext(ApplicationContext applicationContext) |
void |
setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) |
void |
setBeanName(String name) |
void |
setChannelListeners(List<? extends ChannelListener> listeners) |
void |
setCloseExceptionLogger(ConditionalExceptionLogger closeExceptionLogger)
Set the strategy for logging close exceptions; by default, if a channel is closed due to a failed
passive queue declaration, it is logged at debug level.
|
void |
setCloseTimeout(int closeTimeout)
How long to wait (milliseconds) for a response to a connection close
operation from the broker; default 30000 (30 seconds).
|
void |
setConnectionListeners(List<? extends ConnectionListener> listeners) |
void |
setConnectionNameStrategy(ConnectionNameStrategy connectionNameStrategy)
Provide a
ConnectionNameStrategy to build the name for the target RabbitMQ connection. |
void |
setConnectionThreadFactory(ThreadFactory threadFactory)
Set the
ThreadFactory on the underlying rabbit connection factory. |
void |
setConnectionTimeout(int connectionTimeout) |
void |
setExecutor(Executor executor)
Provide an Executor for
use by the Rabbit ConnectionFactory when creating connections.
|
void |
setHost(String host) |
void |
setPassword(String password) |
void |
setPort(int port) |
void |
setPublisherConnectionFactory(AbstractConnectionFactory publisherConnectionFactory)
Set a custom publisher connection factory; the type does not need to be the same
as this factory.
|
void |
setRecoveryListener(com.rabbitmq.client.RecoveryListener recoveryListener)
Set a
RecoveryListener that will be added to each connection created. |
void |
setRequestedHeartBeat(int requestedHeartBeat) |
void |
setShuffleAddresses(boolean shuffleAddresses)
Deprecated.
since 2.3 in favor of
setAddressShuffleMode(AddressShuffleMode) . |
void |
setUri(String uri) |
void |
setUri(URI uri) |
void |
setUsername(String username) |
void |
setVirtualHost(String virtualHost) |
void |
shutdownCompleted(com.rabbitmq.client.ShutdownSignalException cause) |
String |
toString() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
createConnection, isPublisherConfirms, isPublisherReturns, isSimplePublisherConfirms
forPayload
public static final int DEFAULT_CLOSE_TIMEOUT
protected final Log logger
public AbstractConnectionFactory(com.rabbitmq.client.ConnectionFactory rabbitConnectionFactory)
rabbitConnectionFactory
- the target ConnectionFactorypublic void setPublisherConnectionFactory(@Nullable AbstractConnectionFactory publisherConnectionFactory)
publisherConnectionFactory
- the factory.protected final void doSetPublisherConnectionFactory(@Nullable AbstractConnectionFactory publisherConnectionFactory)
public void setApplicationContext(ApplicationContext applicationContext)
setApplicationContext
in interface ApplicationContextAware
protected ApplicationContext getApplicationContext()
public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher)
setApplicationEventPublisher
in interface ApplicationEventPublisherAware
protected ApplicationEventPublisher getApplicationEventPublisher()
public void onApplicationEvent(ContextClosedEvent event)
onApplicationEvent
in interface ApplicationListener<ContextClosedEvent>
protected boolean getContextStopped()
public com.rabbitmq.client.ConnectionFactory getRabbitConnectionFactory()
public String getUsername()
getUsername
in interface ConnectionFactory
public void setUsername(String username)
public void setPassword(String password)
public void setHost(String host)
public void setConnectionThreadFactory(ThreadFactory threadFactory)
ThreadFactory
on the underlying rabbit connection factory.threadFactory
- the thread factory.public void setAddressResolver(com.rabbitmq.client.AddressResolver addressResolver)
AddressResolver
to use when creating connections; overrides
setAddresses(String)
, setHost(String)
, and setPort(int)
.addressResolver
- the resolver.public void setUri(URI uri)
uri
- the URIConnectionFactory.setUri(URI)
public void setUri(String uri)
uri
- the URIConnectionFactory.setUri(String)
public String getHost()
getHost
in interface ConnectionFactory
public void setVirtualHost(String virtualHost)
public String getVirtualHost()
getVirtualHost
in interface ConnectionFactory
public void setPort(int port)
public void setRequestedHeartBeat(int requestedHeartBeat)
public void setConnectionTimeout(int connectionTimeout)
public int getPort()
getPort
in interface ConnectionFactory
public void setAddresses(String addresses)
addresses
- list of addresses with form "host[:port],..."protected ConnectionListener getConnectionListener()
protected ChannelListener getChannelListener()
public void setConnectionListeners(List<? extends ConnectionListener> listeners)
public void addConnectionListener(ConnectionListener listener)
addConnectionListener
in interface ConnectionFactory
public boolean removeConnectionListener(ConnectionListener listener)
removeConnectionListener
in interface ConnectionFactory
public void clearConnectionListeners()
clearConnectionListeners
in interface ConnectionFactory
public void setChannelListeners(List<? extends ChannelListener> listeners)
public void setRecoveryListener(com.rabbitmq.client.RecoveryListener recoveryListener)
RecoveryListener
that will be added to each connection created.recoveryListener
- the listener.public void addChannelListener(ChannelListener listener)
public void setExecutor(Executor executor)
executor
- The executor.@Nullable protected ExecutorService getExecutorService()
public void setCloseTimeout(int closeTimeout)
closeTimeout
- the closeTimeout to set.public int getCloseTimeout()
public void setConnectionNameStrategy(ConnectionNameStrategy connectionNameStrategy)
ConnectionNameStrategy
to build the name for the target RabbitMQ connection.
The beanName
together with a counter is used by default.connectionNameStrategy
- the ConnectionNameStrategy
to use.public void setCloseExceptionLogger(ConditionalExceptionLogger closeExceptionLogger)
closeExceptionLogger
- the ConditionalExceptionLogger
.protected ConnectionNameStrategy getConnectionNameStrategy()
public void setBeanName(String name)
setBeanName
in interface BeanNameAware
@Nullable protected String getBeanName()
@Deprecated public void setShuffleAddresses(boolean shuffleAddresses)
setAddressShuffleMode(AddressShuffleMode)
.addresses
are provided and there is more than
one, set to true to shuffle the list before opening a new connection so that the
connection to the broker will be attempted in random order.shuffleAddresses
- true to shuffle the list.Collections.shuffle(List)
public void setAddressShuffleMode(AbstractConnectionFactory.AddressShuffleMode addressShuffleMode)
addressShuffleMode
- the address shuffle mode.Collections.shuffle(List)
public boolean hasPublisherConnectionFactory()
public ConnectionFactory getPublisherConnectionFactory()
ConnectionFactory
getPublisherConnectionFactory
in interface ConnectionFactory
protected final Connection createBareConnection()
protected final String getDefaultHostName()
public void shutdownCompleted(com.rabbitmq.client.ShutdownSignalException cause)
shutdownCompleted
in interface com.rabbitmq.client.ShutdownListener
public void destroy()
destroy
in interface DisposableBean