Пример #1
0
        private void Message_Received(object sender, BasicDeliverEventArgs e)
        {
            _logger.LogInformation(" [x] Message received: {0} to queue {1}.",
                                   e.RoutingKey, _queueName);

            var isSubscribedToEvent = _subsManager.HasSubscription(e.RoutingKey);

            //Bir string var, bu stringe göre bir class'ın bir methodunu çağırmak istiyoruz.
            var body    = e.Body.ToArray();
            var message = Encoding.UTF8.GetString(body);

            _logger.LogInformation(" \t [.] Content of most recently message: {0}",
                                   message);

            var integrationEvent =
                JsonConvert.DeserializeObject(message, _subsManager.GetEventType(e.RoutingKey));

            _logger.LogInformation(" [x] Deserialized integrationEvent: {0}", integrationEvent);

            Type type = _subsManager.GetHandlerType(e.RoutingKey);

            var scope = _autofac.BeginLifetimeScope();

            _logger.LogInformation(" [x] Scope: {0}", scope.GetType());
            var handler = scope.ResolveOptional(type);

            _logger.LogInformation(" [x] Handler: {0}", handler.GetType());
            type.GetMethod("Handle").Invoke(handler, new object[] { integrationEvent });


            //var concreteType = typeof(IIntegrationEventHandler<>).MakeGenericType(type);
        }