Class PooledChannelConnectionFactory
java.lang.Object
org.springframework.amqp.rabbit.connection.AbstractConnectionFactory
org.springframework.amqp.rabbit.connection.PooledChannelConnectionFactory
- All Implemented Interfaces:
com.rabbitmq.client.ShutdownListener
,EventListener
,ConnectionFactory
,Aware
,BeanNameAware
,DisposableBean
,ApplicationContextAware
,ApplicationEventPublisherAware
,ApplicationListener<ContextClosedEvent>
,Lifecycle
,Phased
,SmartLifecycle
public class PooledChannelConnectionFactory
extends AbstractConnectionFactory
implements com.rabbitmq.client.ShutdownListener, SmartLifecycle
A very simple connection factory that caches channels using Apache Pool2
GenericObjectPool
s (one for transactional and one for non-transactional
channels). The pools have default configuration but they can be configured using
a callback.- Since:
- 2.3
- Author:
- Gary Russell, Leonardo Ferreira, Christian Tzolov, Ngoc Nhan
-
Nested Class Summary
Nested classes/interfaces inherited from class org.springframework.amqp.rabbit.connection.AbstractConnectionFactory
AbstractConnectionFactory.AddressShuffleMode, AbstractConnectionFactory.DefaultChannelCloseLogger
-
Field Summary
Fields inherited from class org.springframework.amqp.rabbit.connection.AbstractConnectionFactory
DEFAULT_CLOSE_TIMEOUT, logger
Fields inherited from interface org.springframework.context.SmartLifecycle
DEFAULT_PHASE
-
Constructor Summary
ConstructorDescriptionPooledChannelConnectionFactory
(com.rabbitmq.client.ConnectionFactory rabbitConnectionFactory) Construct an instance. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addConnectionListener
(ConnectionListener listener) void
destroy()
int
getPhase()
boolean
boolean
Return true if simple publisher confirms are enabled.void
Close the connection(s).void
setPoolConfigurer
(BiConsumer<org.apache.commons.pool2.impl.GenericObjectPool<com.rabbitmq.client.Channel>, Boolean> poolConfigurer) Add a consumer to configure the object pool.void
setPublisherConnectionFactory
(AbstractConnectionFactory publisherConnectionFactory) Set a custom publisher connection factory; the type does not need to be the same as this factory.void
setSimplePublisherConfirms
(boolean simplePublisherConfirms) Enable simple publisher confirms.void
start()
void
stop()
Methods inherited from class org.springframework.amqp.rabbit.connection.AbstractConnectionFactory
addChannelListener, clearConnectionListeners, createBareConnection, doSetPublisherConnectionFactory, getAddresses, getApplicationContext, getApplicationEventPublisher, getBeanName, getChannelListener, getCloseTimeout, getConnectionListener, getConnectionNameStrategy, getContextStopped, getDefaultHostName, getExecutorService, getHost, getPort, getPublisherConnectionFactory, getRabbitConnectionFactory, getUsername, getVirtualHost, hasPublisherConnectionFactory, onApplicationEvent, removeConnectionListener, setAddresses, setAddressResolver, setAddressShuffleMode, setApplicationContext, setApplicationEventPublisher, setBeanName, setChannelListeners, setCloseExceptionLogger, setCloseTimeout, setConnectionCreatingBackOff, setConnectionListeners, setConnectionNameStrategy, setConnectionThreadFactory, setConnectionTimeout, setExecutor, setHost, setPassword, setPort, setRecoveryListener, setRequestedHeartBeat, setUri, setUri, setUsername, setVirtualHost, shutdownCompleted, toString
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.springframework.context.ApplicationListener
supportsAsyncExecution
Methods inherited from interface org.springframework.amqp.rabbit.connection.ConnectionFactory
isPublisherConfirms, isPublisherReturns
Methods inherited from interface com.rabbitmq.client.ShutdownListener
shutdownCompleted
Methods inherited from interface org.springframework.context.SmartLifecycle
isAutoStartup, stop
-
Constructor Details
-
PooledChannelConnectionFactory
public PooledChannelConnectionFactory(com.rabbitmq.client.ConnectionFactory rabbitConnectionFactory) Construct an instance.- Parameters:
rabbitConnectionFactory
- the rabbitmq connection factory.
-
-
Method Details
-
setPublisherConnectionFactory
public void setPublisherConnectionFactory(@Nullable AbstractConnectionFactory publisherConnectionFactory) Description copied from class:AbstractConnectionFactory
Set a custom publisher connection factory; the type does not need to be the same as this factory.- Overrides:
setPublisherConnectionFactory
in classAbstractConnectionFactory
- Parameters:
publisherConnectionFactory
- the factory.
-
setPoolConfigurer
public void setPoolConfigurer(BiConsumer<org.apache.commons.pool2.impl.GenericObjectPool<com.rabbitmq.client.Channel>, Boolean> poolConfigurer) Add a consumer to configure the object pool. The second argument is true when called with the transactional pool.- Parameters:
poolConfigurer
- the configurer.
-
isSimplePublisherConfirms
public boolean isSimplePublisherConfirms()Description copied from interface:ConnectionFactory
Return true if simple publisher confirms are enabled.- Specified by:
isSimplePublisherConfirms
in interfaceConnectionFactory
- Returns:
- simplePublisherConfirms
-
setSimplePublisherConfirms
public void setSimplePublisherConfirms(boolean simplePublisherConfirms) Enable simple publisher confirms.- Parameters:
simplePublisherConfirms
- true to enable.
-
addConnectionListener
- Specified by:
addConnectionListener
in interfaceConnectionFactory
- Overrides:
addConnectionListener
in classAbstractConnectionFactory
-
getPhase
public int getPhase()- Specified by:
getPhase
in interfacePhased
- Specified by:
getPhase
in interfaceSmartLifecycle
-
start
public void start() -
stop
public void stop() -
isRunning
public boolean isRunning() -
createConnection
- Specified by:
createConnection
in interfaceConnectionFactory
- Throws:
AmqpException
-
resetConnection
public void resetConnection()Close the connection(s). This will impact any in-process operations. New connection(s) will be created on demand after this method returns. This might be used to force a reconnect to the primary broker after failing over to a secondary broker.- Specified by:
resetConnection
in interfaceConnectionFactory
-
destroy
public void destroy()- Specified by:
destroy
in interfaceDisposableBean
- Overrides:
destroy
in classAbstractConnectionFactory
-