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); }
private void InMemoryEventBus_EventHandler(object sender, EventProcessedArgs e) { _ctx.HandleAsync(e.Event); }