CreateFromConnectionFactory() public static method

Create a ManagedConnectionFactory from a known ConnectionFactory
public static CreateFromConnectionFactory ( ConnectionFactory connectionFactory ) : ManagedConnectionFactory
connectionFactory RabbitMQ.Client.ConnectionFactory
return ManagedConnectionFactory
Beispiel #1
0
        /// <summary>
        /// Initialize a <see cref="DurableConnection"/> object
        /// </summary>
        /// <param name="retryPolicy"></param>
        /// <param name="watcher"></param>
        /// <param name="connectionFactory"></param>
        public DurableConnection(IRetryPolicy retryPolicy, IRabbitWatcher watcher, ConnectionFactory connectionFactory)
        {
            if (retryPolicy == null)
            {
                throw new ArgumentNullException("retryPolicy");
            }
            if (watcher == null)
            {
                throw new ArgumentNullException("watcher");
            }
            if (connectionFactory == null)
            {
                throw new ArgumentNullException("connectionFactory");
            }

            _retryPolicy       = retryPolicy;
            _watcher           = watcher;
            _connectionFactory = ManagedConnectionFactory.CreateFromConnectionFactory(connectionFactory);
        }
        /// <summary>
        /// Initialize a <see cref="DurableConnection"/> object
        /// </summary>
        /// <param name="retryPolicy"></param>
        /// <param name="watcher"></param>
        /// <param name="connectionFactory"></param>
        public DurableConnection(IRetryPolicy retryPolicy, IRabbitWatcher watcher, ConnectionFactory connectionFactory)
            : this(retryPolicy, watcher)
        {
            if (connectionFactory == null)
            {
                throw new ArgumentNullException(nameof(connectionFactory));
            }


            _connectionFactory = ManagedConnectionFactory.CreateFromConnectionFactory(connectionFactory);
            ConnectionEstablished handler = (endpoint, virtualHost) =>
            {
                if (_connectionFactory.Endpoint + _connectionFactory.VirtualHost == endpoint + virtualHost)
                {
                    //NOTE: Fire connected event whenever a new connection to 1 of the servers in the cluster is made
                    FireConnectedEvent();
                }
            };

            ManagedConnectionFactory.ConnectionEstablished += handler;
            _unsubscribeEvents = () => { ManagedConnectionFactory.ConnectionEstablished -= handler; };
        }