Spring AMQP

org.springframework.amqp.rabbit.connection
Class CachingConnectionFactory

java.lang.Object
  extended by org.springframework.amqp.rabbit.connection.SingleConnectionFactory
      extended by 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, Dave Syer

Field Summary
 
Fields inherited from class org.springframework.amqp.rabbit.connection.SingleConnectionFactory
logger
 
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.
 
Method Summary
protected  ChannelProxy getCachedChannelProxy(Connection connection, LinkedList<ChannelProxy> channelList, boolean transactional)
           
protected  com.rabbitmq.client.Channel getChannel(Connection connection, boolean transactional)
           
 int getChannelCacheSize()
           
 void resetConnection()
          Reset the Channel cache and underlying shared Connection, to be reinitialized on next access.
 void setChannelCacheSize(int sessionCacheSize)
           
 String toString()
           
 
Methods inherited from class org.springframework.amqp.rabbit.connection.SingleConnectionFactory
closeConnection, createConnection, destroy, doCreateConnection, getHost, getPort, getSharedConnectionProxy, getVirtualHost, initConnection, prepareConnection, setPassword, setPort, setUsername, setVirtualHost
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.springframework.beans.factory.DisposableBean
destroy
 

Constructor Detail

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 ConnectionFactory
Method Detail

setChannelCacheSize

public void setChannelCacheSize(int sessionCacheSize)

getChannelCacheSize

public int getChannelCacheSize()

getChannel

protected com.rabbitmq.client.Channel getChannel(Connection connection,
                                                 boolean transactional)
                                          throws IOException
Overrides:
getChannel in class SingleConnectionFactory
Throws:
IOException

getCachedChannelProxy

protected ChannelProxy getCachedChannelProxy(Connection connection,
                                             LinkedList<ChannelProxy> channelList,
                                             boolean transactional)

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

Spring AMQP

Copyright © 2010. All Rights Reserved.