Example #1
0
        public RabbitMQEventDispatcher(RabbitMQOptions options, IEventHandlerTypeStore eventHandlerTypeStore,
                                       IHandlerFactory handlerFactory) : base(eventHandlerTypeStore, handlerFactory)

        {
            _options   = options;
            _modelDict = new ConcurrentDictionary <string, IModel>();

            var connectionFactory = new ConnectionFactory
            {
                HostName = _options.HostName,

                DispatchConsumersAsync = true
            };

            if (_options.Port > 0)
            {
                connectionFactory.Port = _options.Port;
            }

            if (!string.IsNullOrWhiteSpace(_options.UserName))
            {
                connectionFactory.UserName = _options.UserName;
            }

            if (!string.IsNullOrWhiteSpace(_options.Password))
            {
                connectionFactory.Password = _options.Password;
            }

            _connection = connectionFactory.CreateConnection();
        }
Example #2
0
        public static MSFrameworkBuilder UseRabbitMQEventDispatcher(this MSFrameworkBuilder builder,
                                                                    Action <RabbitMQOptions> configure, params Type[] eventTypes)
        {
            var options = new RabbitMQOptions();

            configure?.Invoke(options);

            builder.UseRabbitMQEventDispatcher(options, eventTypes);
            return(builder);
        }
Example #3
0
        public static MSFrameworkBuilder UseRabbitMQEventDispatcher(this MSFrameworkBuilder builder,
                                                                    RabbitMQOptions options, params Type[] eventTypes)
        {
            var excludeAssembly = typeof(MSFrameworkBuilder).Assembly;

            if (eventTypes.Any(x => x.Assembly != excludeAssembly))
            {
                var list = new List <Type>(eventTypes)
                {
                    typeof(MSFrameworkBuilder)
                };
                builder.Services.AddEventDispatcher(list.ToArray());
            }
            else
            {
                builder.Services.AddEventDispatcher(eventTypes);
            }

            builder.Services.AddSingleton(options);
            builder.Services.AddScoped <IEventDispatcher, RabbitMQEventDispatcher>();
            return(builder);
        }