Example #1
0
        public RabbitMQEventBus(IConnectionFactory connectionFactory,
                                ILogger <RabbitMQEventBus> logger,
                                IEventHandlerExecutionContext context,
                                string exchangeName,
                                string exchangeType = ExchangeType.Fanout,
                                string queueName    = null,
                                bool autoAck        = false)
            : base(context)
        {
            this.logger = logger;
            //1.实例化连接工厂
            this.connectionFactory = connectionFactory;
            //2.建立连接
            this.connection = this.connectionFactory.CreateConnection();
            //3.创建信道
            this.channel      = this.connection.CreateModel();
            this.exchangeType = exchangeType;
            this.exchangeName = exchangeName;
            this.autoAck      = autoAck;
            //4.创建 exchangeType 类型的交换机(exchange)
            this.channel.ExchangeDeclare(this.exchangeName, this.exchangeType);

            this.queueName = this.InitializeEventConsumer(queueName);

            logger.LogInformation($"RabbitMQEventBus构造函数调用完成。Hash Code:{this.GetHashCode()}.");
        }
        public RabbitMQEventBus(IConnectionFactory connectionFactory,
                                ILogger <RabbitMQEventBus> logger,
                                IEventHandlerExecutionContext context,
                                string exchangeName,
                                string exchangeType = ExchangeType.Fanout,
                                string queueName    = null,
                                bool autoAck        = false)
            : base(context)
        {
            this.connectionFactory = connectionFactory;
            this.logger            = logger;
            this.connection        = this.connectionFactory.CreateConnection();
            this.channel           = this.connection.CreateModel();
            this.exchangeType      = exchangeType;
            this.exchangeName      = exchangeName;
            this.autoAck           = autoAck;

            this.channel.ExchangeDeclare(this.exchangeName, this.exchangeType);

            props              = channel.CreateBasicProperties();
            props.ContentType  = "application/json";
            props.DeliveryMode = 2;

            this.queueName = this.InitializeEventConsumer(queueName);

            logger.LogInformation($"RabbitMQEventBus构造函数调用完成。Hash Code:{this.GetHashCode()}.");
        }
        //private readonly IEnumerable<IEventHandler> eventHandlers;



        public PassThroughEventBus(IEventHandlerExecutionContext context, ILogger <PassThroughEventBus> logger) : base(context)
        {
            this.logger = logger;

            logger.LogInformation($"PassThroughEventBus构造函数调用完成。Hash Code:{this.GetHashCode()}.");
            eventQueue.EventPushed += EventQueue_EventPushed;
        }
Example #4
0
        public RabbitMQEventBus(IEventHandlerExecutionContext ctx, IConfiguration configuration)
        {
            _ctx = ctx;
            var options = new RabbitMQOptions();

            configuration.GetSection(nameof(RabbitMQOptions)).Bind(options);
            _connectionFactory = new ConnectionFactory()
            {
                HostName    = options.HostName,
                Port        = options.Port,
                UserName    = options.UserName,
                Password    = options.Password,
                VirtualHost = options.VirtualHost,
            };
            _connection = _connectionFactory.CreateConnection();
            _channel    = _connection.CreateModel();

            _queueName = _channel.QueueDeclare().QueueName;
            var consumer = new EventingBasicConsumer(_channel);

            consumer.Received += async(sender, e) =>
            {
                var json   = Encoding.UTF8.GetString(e.Body);
                var @event = (IEvent)JsonConvert.DeserializeObject(json);
                await _ctx.HandleAsync(@event);
            };
            _channel.BasicConsume(_queueName, true, consumer);
        }
        public PassThroughEventBus(IEventHandlerExecutionContext context, ILogger <PassThroughEventBus> log)
            : base(context)
        {
            //_eventHandlers = eventHandlers;
            _context = context;
            _log     = log;

            eventQueue.EventPushed += EventQueue_EventPushed;
        }
Example #6
0
        public RabbitMQEventBus(IEventHandlerExecutionContext eventHandlerExecutionContext)
        {
            _mqHost     = ConfigurationManager.AppSetting("RabbitMQHost");
            _mqUser     = ConfigurationManager.AppSetting("RabbitMQUser");
            _mqPassword = ConfigurationManager.AppSetting("RabbitMQPassword");

            _eventQueue = new RabbitQueue(_mqHost, _mqUser, _mqPassword);

            _eventHandlerExecutionContext = eventHandlerExecutionContext;
        }
Example #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        /// <param name="allAssemblyFinder"></param>
        /// <param name="logger"></param>
        public PassThroughEventBus(IEventHandlerExecutionContext context, IAllAssemblyFinder allAssemblyFinder,
                                   ILogger <PassThroughEventBus> logger)
        {
            this.context            = context;
            this.logger             = logger;
            this._allAssemblyFinder = allAssemblyFinder;
            logger.LogInformation($"PassThroughEventBus构造函数调用完成。Hash Code:{this.GetHashCode()}.");

            eventQueue.EventPushed += EventQueue_EventPushed;
        }
Example #8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="InMemoryEventBus"/> class.
        /// </summary>
        /// <param name="eventHandlerExecutionContext"></param>
        /// <param name="logger"></param>
        public InMemoryEventBus(
            IEventHandlerExecutionContext eventHandlerExecutionContext
#if DEBUG
            , ILogger <InMemoryEventBus> logger
#endif
            )
        {
            _ctx = eventHandlerExecutionContext;
#if DEBUG
            _logger = logger ?? throw new ArgumentNullException(nameof(logger));

            _logger.LogCritical("Event bus 初始化...(无线电)");
#endif

            EventHandler += InMemoryEventBus_EventHandler;
        }
Example #9
0
        public RabbitMqEventBus(IEventHandlerExecutionContext eventHandlerExecutionContext,
                                ILogger <RabbitMqEventBus> logger,
                                IConnectionFactory connectionFactory, RabbitMQConfig config) : base(
                eventHandlerExecutionContext)
        {
            _logger       = logger;
            _connection   = connectionFactory.CreateConnection();
            _channel      = _connection.CreateModel();
            _exchangeName = config.RmqExchange;
            var exchangeType = config.RmqExchangeType;

            _queueName = InitializeQueue(config.RmqQueue);
            _autoAck   = config.AutoAck;

            _channel.ExchangeDeclare(_exchangeName, exchangeType);
            _logger.LogInformation("RabbitMQEvents构造完成");
        }
Example #10
0
        public RabbitMQEventBus(IEventHandlerExecutionContext _eventHandlerExecutionContext,
                                ILogger <RabbitMQEventBus> _logger,
                                IConnectionFactory _connectionFactory,
                                string _exchangeName,
                                string _exchangeType = ExchangeType.Fanout,
                                string _queueName    = null,
                                bool _autoAck        = false
                                )
            : base(_eventHandlerExecutionContext)
        {
            connectionFactory = _connectionFactory;
            logger            = _logger;
            connection        = connectionFactory.CreateConnection();
            channel           = connection.CreateModel();
            exchangeType      = _exchangeType;
            exchangeName      = _exchangeName;
            autoAck           = _autoAck;

            channel.ExchangeDeclare(exchangeName, exchangeType);
            queueName = InitializeEventConsumer(_queueName);

            logger.LogInformation($"RabbitMQEventBus 构造函数调用完成* Hash Code:{this.GetHashCode()}.");
        }
Example #11
0
 protected BaseEventBus(IEventHandlerExecutionContext _eventHandlerExecutionContext)
 {
     eventHandlerExecutionContext = _eventHandlerExecutionContext;
 }
Example #12
0
 protected BaseEventBus(IEventHandlerExecutionContext eventHandlerExecutionContext)
 {
     this.eventHandlerExecutionContext = eventHandlerExecutionContext;
 }
Example #13
0
 public BaseEventBus(IEventHandlerExecutionContext eventHandlerExecutionContext)
 {
     this.eventHandlerExecutionContext = eventHandlerExecutionContext;
 }
Example #14
0
 public SimpleEventBus(IEventHandlerExecutionContext eventHandlerExecutionContext,
                       ILogger <SimpleEventBus> logger) : base(eventHandlerExecutionContext)
 {
     _logger = logger;
     _eventQueue.EventPushed += EventQueue_EventPushed;
 }
Example #15
0
 public InMemoryEventBus(IEventHandlerExecutionContext ctx)
 {
     _ctx         = ctx;
     EventPushed += InMemoryEventBus_EventPushed;
 }