org.springframework.amqp.rabbit.connection
Class CachingConnectionFactory
java.lang.Object
org.springframework.amqp.rabbit.connection.SingleConnectionFactory
org.springframework.amqp.rabbit.connection.CachingConnectionFactory
- All Implemented Interfaces:
- ConnectionFactory, DisposableBean
public class CachingConnectionFactory
- extends SingleConnectionFactory
- implements DisposableBean
NOTE: this ConnectionFactory implementation is considered experimental at this stage.
There are concerns to be addressed in relation to the statefulness of channels. Therefore, we
recommend using SingleConnectionFactory for now.
A ConnectionFactory implementation that returns the same Connections from all
SingleConnectionFactory.createConnection() calls, and ignores calls to Connection.close() and
caches Channel.
By default, only one single Session will be cached, with further requested Channels being created and
disposed on demand. Consider raising the "channelCacheSize" value in case of a
high-concurrency environment.
NOTE: This ConnectionFactory requires explicit closing of all Channels obtained form its
shared Connection. This is the usual recommendation for native Rabbit access code anyway.
However, with this ConnectionFactory, its use is mandatory in order to actually allow for Channel reuse.
- Author:
- Mark Pollack, Mark Fisher
|
Constructor Summary |
CachingConnectionFactory()
Create a new CachingConnectionFactory initializing the hostname to be the
value returned from InetAddress.getLocalHost(), or "localhost" if getLocalHost() throws
an exception. |
CachingConnectionFactory(com.rabbitmq.client.ConnectionFactory rabbitConnectionFactory)
Create a new CachingConnectionFactory for the given target
ConnectionFactory. |
CachingConnectionFactory(String hostName)
Create a new CachingConnectionFactory given a host name. |
| Methods inherited from class org.springframework.amqp.rabbit.connection.SingleConnectionFactory |
closeConnection, createConnection, destroy, doCreateConnection, getHost, getPort, getSharedConnectionProxy, getVirtualHost, initConnection, prepareConnection, setPassword, setPort, setUsername |
CachingConnectionFactory
public CachingConnectionFactory()
- Create a new CachingConnectionFactory initializing the hostname to be the
value returned from InetAddress.getLocalHost(), or "localhost" if getLocalHost() throws
an exception.
CachingConnectionFactory
public CachingConnectionFactory(String hostName)
- Create a new CachingConnectionFactory given a host name.
- Parameters:
hostName - the host name to connect to
CachingConnectionFactory
public CachingConnectionFactory(com.rabbitmq.client.ConnectionFactory rabbitConnectionFactory)
- Create a new CachingConnectionFactory for the given target
ConnectionFactory.
- Parameters:
rabbitConnectionFactory - the target ConnectionFactoryhostName - the host name to connect to
setChannelCacheSize
public void setChannelCacheSize(int sessionCacheSize)
getChannelCacheSize
public int getChannelCacheSize()
getChannel
protected com.rabbitmq.client.Channel getChannel(com.rabbitmq.client.Connection connection)
throws Exception
- Overrides:
getChannel in class SingleConnectionFactory
- Throws:
Exception
getCachedChannelProxy
protected com.rabbitmq.client.Channel getCachedChannelProxy(com.rabbitmq.client.Channel target,
LinkedList<com.rabbitmq.client.Channel> channelList)
resetConnection
public void resetConnection()
- Reset the Channel cache and underlying shared Connection, to be reinitialized on next access.
- Overrides:
resetConnection in class SingleConnectionFactory
toString
public String toString()
- Overrides:
toString in class SingleConnectionFactory
Copyright © 2010. All Rights Reserved.