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

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  Connection doCreateConnection()
          Create a Connection.
 int getChannelCacheSize()
           
protected  void reset()
          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
createConnection, destroy, getHost, getPort, getVirtualHost, setHost, 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()

doCreateConnection

protected Connection doCreateConnection()
Description copied from class: SingleConnectionFactory
Create a Connection. This implementation just delegates to the underlying Rabbit ConnectionFactory. Subclasses typically will decorate the result to provide additional features.

Overrides:
doCreateConnection in class SingleConnectionFactory
Returns:
the new Connection

reset

protected void reset()
Reset the Channel cache and underlying shared Connection, to be reinitialized on next access.

Overrides:
reset in class SingleConnectionFactory

toString

public String toString()
Overrides:
toString in class SingleConnectionFactory

Spring AMQP

Copyright © 2011. All Rights Reserved.