Ejemplo n.º 1
0
        private void Subscribe <TService>(QuSpecAttribute quSpec, IEnumerable <TService> svcs, Func <string, IBasicProperties, IEnumerable <TService>, Task> processEvent)
            where TService : class
        {
            ListeningChannel.QueueDeclare(quSpec.Queue, quSpec.Durable, quSpec.Exclusive, quSpec.AutoDelete, null);
            var consumer = new AsyncEventingBasicConsumer(ListeningChannel);

            //consumer.Received += ConsumerReceived;
            consumer.Received += async(sender, e) =>
            {
                //e.BasicProperties.ReplyTo;
                //var eventName = e.RoutingKey;
                var msgText = Encoding.UTF8.GetString(e.Body);
                try
                {
                    await processEvent(msgText, e.BasicProperties, svcs).ConfigureAwait(false);
                }
                catch (Exception err)
                {
                    if (TheLogger != null)
                    {
                        TheLogger.LogError(err.Message);
                    }
                    throw;
                }
            };
            ListeningChannel.BasicConsume(quSpec.Queue, true, consumer);
        }