/// <summary>
        /// Initializes a new instance of the <see cref="T:EasyCaching.Bus.RabbitMQ.DefaultRabbitMQBus"/> class.
        /// </summary>
        /// <param name="name">Unique name of the bus.</param>
        /// <param name="objectPolicy">Object policy.</param>
        /// <param name="rabbitMQOptions">RabbitMQ Options.</param>
        /// <param name="serializer">Serializer.</param>
        public DefaultRabbitMQBus(
            string name
            , IPooledObjectPolicy <IModel> objectPolicy
            , IOptions <RabbitMQBusOptions> rabbitMQOptions
            , IEasyCachingSerializer serializer)
        {
            BusName = name ?? throw new ArgumentNullException(nameof(name));;

            this._options    = rabbitMQOptions.Value;
            this._serializer = serializer;

            var factory = new ConnectionFactory
            {
                HostName    = _options.HostName,
                UserName    = _options.UserName,
                Port        = _options.Port,
                Password    = _options.Password,
                VirtualHost = _options.VirtualHost,
                RequestedConnectionTimeout = System.TimeSpan.FromMilliseconds(_options.RequestedConnectionTimeout),
                SocketReadTimeout          = System.TimeSpan.FromMilliseconds(_options.SocketReadTimeout),
                SocketWriteTimeout         = System.TimeSpan.FromMilliseconds(_options.SocketWriteTimeout)
            };

            _subConnection = factory.CreateConnection();

            _pubChannelPool = new DefaultObjectPool <IModel>(objectPolicy);

            _busId = Guid.NewGuid().ToString("N");
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="T:EasyCaching.Bus.RabbitMQ.DefaultRabbitMQBus"/> class.
        /// </summary>
        /// <param name="_objectPolicy">Object policy.</param>
        /// <param name="rabbitMQOptions">RabbitMQ Options.</param>
        /// <param name="serializer">Serializer.</param>
        public DefaultRabbitMQBus(
            IPooledObjectPolicy <IConnection> _objectPolicy
            , IOptions <RabbitMQBusOptions> rabbitMQOptions
            , IEasyCachingSerializer serializer)
        {
            this._options    = rabbitMQOptions.Value;
            this._serializer = serializer;

            var factory = new ConnectionFactory
            {
                HostName    = _options.HostName,
                UserName    = _options.UserName,
                Port        = _options.Port,
                Password    = _options.Password,
                VirtualHost = _options.VirtualHost,
                RequestedConnectionTimeout = _options.RequestedConnectionTimeout,
                SocketReadTimeout          = _options.SocketReadTimeout,
                SocketWriteTimeout         = _options.SocketWriteTimeout
            };

            _subConnection = factory.CreateConnection();

            _pubConnectionPool = new DefaultObjectPool <IConnection>(_objectPolicy);

            _busId = Guid.NewGuid().ToString("N");
        }
Beispiel #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:EasyCaching.Bus.RabbitMQ.DefaultRabbitMQBus"/> class.
        /// </summary>
        /// <param name="_objectPolicy">Object policy.</param>
        /// <param name="rabbitMQOptions">RabbitMQ Options.</param>
        /// <param name="serializer">Serializer.</param>
        public DefaultRabbitMQBus(
            IPooledObjectPolicy <IModel> _objectPolicy
            , IOptions <RabbitMQBusOptions> rabbitMQOptions
            , IEasyCachingSerializer serializer)
        {
            this._options    = rabbitMQOptions.Value;
            this._serializer = serializer;

            var factory = new ConnectionFactory
            {
                HostName    = _options.HostName,
                UserName    = _options.UserName,
                Port        = _options.Port,
                Password    = _options.Password,
                VirtualHost = _options.VirtualHost,
                RequestedConnectionTimeout = System.TimeSpan.FromMilliseconds(_options.RequestedConnectionTimeout),
                SocketReadTimeout          = System.TimeSpan.FromMilliseconds(_options.SocketReadTimeout),
                SocketWriteTimeout         = System.TimeSpan.FromMilliseconds(_options.SocketWriteTimeout),
                ClientProvidedName         = _options.ClientProvidedName
            };

            _subConnection = factory.CreateConnection();

            _pubChannelPool = new DefaultObjectPool <IModel>(_objectPolicy);

            _busId = Guid.NewGuid().ToString("N");

            BusName = "easycachingbus";
        }
Beispiel #4
0
        /// <summary>
        /// Withs the RabbitMQ Bus.
        /// </summary>
        /// <returns>The rabbit MQB us.</returns>
        /// <param name="options">Options.</param>
        /// <param name="configuration">Configuration.</param>
        /// <param name="sectionName">Section name.</param>
        public static EasyCachingOptions WithRabbitMQBus(this EasyCachingOptions options, IConfiguration configuration, string sectionName = "rabbitmqbus")
        {
            var dbConfig   = configuration.GetSection(sectionName);
            var busOptions = new RabbitMQBusOptions();

            dbConfig.Bind(busOptions);

            void configure(RabbitMQBusOptions x)
            {
                x.HostName                   = busOptions.HostName;
                x.Password                   = busOptions.Password;
                x.Port                       = busOptions.Port;
                x.QueueMessageExpires        = busOptions.QueueMessageExpires;
                x.RequestedConnectionTimeout = busOptions.RequestedConnectionTimeout;
                x.RouteKey                   = busOptions.RouteKey;
                x.SocketReadTimeout          = busOptions.SocketReadTimeout;
                x.SocketWriteTimeout         = busOptions.SocketWriteTimeout;
                x.TopicExchangeName          = busOptions.TopicExchangeName;
                x.UserName                   = busOptions.UserName;
                x.VirtualHost                = busOptions.VirtualHost;
                x.QueueName                  = busOptions.QueueName;
            }

            options.RegisterExtension(new RabbitMQBusOptionsExtension(configure));
            return(options);
        }
Beispiel #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:EasyCaching.Bus.RabbitMQ.DefaultRabbitMQBus"/> class.
 /// </summary>
 /// <param name="connectionChannelPool">Connection channel pool.</param>
 /// <param name="rabbitMQOptions">Rabbit MQO ptions.</param>
 /// <param name="serializer">Serializer.</param>
 /// <param name="localCachingProvider">Local caching provider.</param>
 public DefaultRabbitMQBus(
     IConnectionChannelPool connectionChannelPool,
     RabbitMQBusOptions rabbitMQOptions,
     IEasyCachingSerializer serializer,
     IEasyCachingProvider localCachingProvider)
 {
     this._rabbitMQBusOptions    = rabbitMQOptions;
     this._connectionChannelPool = connectionChannelPool;
     this._serializer            = serializer;
     this._localCachingProvider  = localCachingProvider;
 }
        /// <summary>
        /// Creates the connection.
        /// </summary>
        /// <returns>The connection.</returns>
        /// <param name="options">Options.</param>
        private static Func <IConnection> CreateConnection(RabbitMQBusOptions options)
        {
            var factory = new ConnectionFactory
            {
                HostName    = options.HostName,
                UserName    = options.UserName,
                Port        = options.Port,
                Password    = options.Password,
                VirtualHost = options.VirtualHost,
                RequestedConnectionTimeout = options.RequestedConnectionTimeout,
                SocketReadTimeout          = options.SocketReadTimeout,
                SocketWriteTimeout         = options.SocketWriteTimeout
            };

            return(() => factory.CreateConnection());
        }
Beispiel #7
0
        /// <summary>
        /// Adds the default rabbitMQ Bus.
        /// </summary>
        /// <returns>The default rabbit MQB us.</returns>
        /// <param name="services">Services.</param>
        /// <param name="optionsAction">Options action.</param>
        public static IServiceCollection AddDefaultRabbitMQBus(this IServiceCollection services, Action <RabbitMQBusOptions> optionsAction)
        {
            ArgumentCheck.NotNull(services, nameof(services));
            ArgumentCheck.NotNull(optionsAction, nameof(optionsAction));

            var options = new RabbitMQBusOptions();

            optionsAction?.Invoke(options);
            services.AddSingleton(options);

            services.TryAddSingleton <IEasyCachingSerializer, DefaultBinaryFormatterSerializer>();
            services.TryAddSingleton <IConnectionChannelPool, ConnectionChannelPool>();
            services.TryAddSingleton <IEasyCachingBus, DefaultRabbitMQBus>();
            services.TryAddSingleton <IEasyCachingSerializer, DefaultBinaryFormatterSerializer>();

            return(services);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="T:EasyCaching.Bus.RabbitMQ.ConnectionPooledObjectPolicy"/> class.
 /// </summary>
 /// <param name="optionsAccs">Options accs.</param>
 public ConnectionPooledObjectPolicy(IOptions <RabbitMQBusOptions> optionsAccs)
 {
     this._options = optionsAccs.Value;
 }
Beispiel #9
0
 public ModelPooledObjectPolicy(IOptions <RabbitMQBusOptions> optionsAccs)
 {
     _options    = optionsAccs.Value;
     _connection = GetConnection();
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="T:EasyCaching.Bus.RabbitMQ.ConnectionChannelPool"/> class.
        /// </summary>
        /// <param name="options">Options.</param>
        public ConnectionChannelPool(RabbitMQBusOptions options)
        {
            _maxSize = DefaultPoolSize;

            _connectionActivator = CreateConnection(options);
        }