Class CachingConnectionFactory

    • 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​(@Nullable
                                        java.lang.String hostname)
        Create a new CachingConnectionFactory given a host name.
        Parameters:
        hostname - the host name to connect to
      • CachingConnectionFactory

        public CachingConnectionFactory​(int port)
        Create a new CachingConnectionFactory given a port on the hostname returned from InetAddress.getLocalHost(), or "localhost" if getLocalHost() throws an exception.
        Parameters:
        port - the port number
      • CachingConnectionFactory

        public CachingConnectionFactory​(@Nullable
                                        java.lang.String hostNameArg,
                                        int port)
        Create a new CachingConnectionFactory given a host name and port.
        Parameters:
        hostNameArg - the host name to connect to
        port - the port number
      • CachingConnectionFactory

        public CachingConnectionFactory​(java.net.URI uri)
        Create a new CachingConnectionFactory given a URI.
        Parameters:
        uri - the amqp uri configuring the connection
        Since:
        1.5
      • 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)
        The number of channels to maintain in the cache. By default, channels are allocated on demand (unbounded) and this represents the maximum cache size. To limit the available channels, see setChannelCheckoutTimeout(long).
        Parameters:
        sessionCacheSize - the channel cache size.
        See Also:
        setChannelCheckoutTimeout(long)
      • getChannelCacheSize

        public int getChannelCacheSize()
      • getConnectionCacheSize

        public int getConnectionCacheSize()
      • setConnectionCacheSize

        public void setConnectionCacheSize​(int connectionCacheSize)
      • setConnectionLimit

        public void setConnectionLimit​(int connectionLimit)
        Set the connection limit when using cache mode CONNECTION. When the limit is reached and there are no idle connections, the channelCheckoutTimeLimit is used to wait for a connection to become idle.
        Parameters:
        connectionLimit - the limit.
        Since:
        1.5.5
      • setPublisherReturns

        public void setPublisherReturns​(boolean publisherReturns)
      • setPublisherConfirms

        @Deprecated
        public void setPublisherConfirms​(boolean publisherConfirms)
        Deprecated.
        Use full (correlated) publisher confirms, with correlation data and a callback for each message.
        Parameters:
        publisherConfirms - true for full publisher returns,
        Since:
        1.1
        See Also:
        setSimplePublisherConfirms(boolean)
      • setSimplePublisherConfirms

        @Deprecated
        public void setSimplePublisherConfirms​(boolean simplePublisherConfirms)
        Deprecated.
        Use simple publisher confirms where the template simply waits for completion.
        Parameters:
        simplePublisherConfirms - true for confirms.
        Since:
        2.1
        See Also:
        setPublisherConfirms(boolean)
      • setChannelCheckoutTimeout

        public void setChannelCheckoutTimeout​(long channelCheckoutTimeout)
        Sets the channel checkout timeout. When greater than 0, enables channel limiting in that the channelCacheSize becomes the total number of available channels per connection rather than a simple cache size. Note that changing the channelCacheSize does not affect the limit on existing connection(s), invoke destroy() to cause a new connection to be created with the new limit.

        Since 1.5.5, also applies to getting a connection when the cache mode is CONNECTION.

        Parameters:
        channelCheckoutTimeout - the timeout in milliseconds; default 0 (channel limiting not enabled).
        Since:
        1.4.2
        See Also:
        setConnectionLimit(int)
      • destroy

        public final void destroy()
        Close the underlying shared connection. Use resetConnection() to close the connection while the application is still running.

        As this bean implements DisposableBean, a bean factory will automatically invoke this on destruction of its cached singletons.

        If called after the context is closed, the connection factory can no longer server up connections.

        Specified by:
        destroy in interface DisposableBean
        Overrides:
        destroy in class AbstractConnectionFactory
      • 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 interface ConnectionFactory
      • reset

        protected void reset​(java.util.List<ChannelProxy> channels,
                             java.util.List<ChannelProxy> txChannels,
                             java.util.Map<com.rabbitmq.client.Channel,​ChannelProxy> channelsAwaitingAcks)
      • closeAndClear

        protected void closeAndClear​(java.util.Collection<ChannelProxy> theChannels)
      • closeChannels

        protected void closeChannels​(java.util.Collection<ChannelProxy> theChannels)
      • getCacheProperties

        @ManagedAttribute
        public java.util.Properties getCacheProperties()
      • getPublisherConnectionFactoryCacheProperties

        @ManagedAttribute
        public java.util.Properties getPublisherConnectionFactoryCacheProperties()
        Return the cache properties from the underlying publisher sub-factory.
        Returns:
        the properties.
        Since:
        2.0.2
      • getChannelsExecutor

        protected java.util.concurrent.ExecutorService getChannelsExecutor()
        Determine the executor service used for target channels.
        Returns:
        specified executor service otherwise the default one is created and returned.
        Since:
        1.7.9