public async Task Consume(ConsumeContext <UserRegisteredEvent> context)
        {
            using (var scope = TracingExtension.StartServerSpan(_tracer, context.Message.TracingKeys, "user-activation-link-sender-consumer"))
            {
                //some user activation link send business logics

                await System.Console.Out.WriteLineAsync($"Activation link sent for {context.Message.Email}");
            }
        }
        public void Start()
        {
            var retryOnStartupPolicy = Policy
                                       .Handle <Exception>()
                                       .WaitAndRetry(9, retryAttempt =>
                                                     TimeSpan.FromSeconds(Math.Pow(2, retryAttempt))
                                                     );

            retryOnStartupPolicy.Execute(() =>
            {
                con   = this._client.GetConnection();
                model = this._client.GetModel(con);

                EventingBasicConsumer consumer = new EventingBasicConsumer(model);
                consumer.Received += async(m, ea) =>
                {
                    System.Console.WriteLine("Processando item da fila.");
                    this._sharedTracing.CorrelationId = JsonConvert.DeserializeObject <IDictionary <string, string> >(Encoding.UTF8.GetString((byte[])ea.BasicProperties.Headers["tracing"]));

                    using (var scope = TracingExtension.StartServerSpan(_tracer, this._sharedTracing.CorrelationId, "Tracing RabbitMQ"))
                    {
                        scope.Span.Log("Consumindo a fila");
                        T oEvent = JsonConvert.DeserializeObject <T>(Encoding.UTF8.GetString(ea.Body.ToArray()));
                        try
                        {
                            await this._action(oEvent);
                            model.BasicAck(deliveryTag: ea.DeliveryTag, multiple: false);
                            System.Console.WriteLine("Processado item da fila.");
                        }
                        catch (Exception e)
                        {
                            System.Console.WriteLine("Erro ao processar item da fila. - " + e.Message);
                            model.BasicNack(deliveryTag: ea.DeliveryTag, multiple: false, requeue: true);
                        }
                    }
                };

                model.BasicConsume(queue: this._client.GetQueueName(),
                                   autoAck: false,
                                   consumer: consumer);
            });
        }
Beispiel #3
0
 public void Intercept(IInvocation invocation)
 {
     using (IScope scope = this._sharedTracing.CorrelationId == null ? this._tracer.BuildSpan("TraceInterceptor").StartActive(true) : TracingExtension.StartServerSpan(_tracer, this._sharedTracing.CorrelationId, "TraceInterceptor"))
     {
         try
         {
             scope.Span.SetTag("arguments", JsonConvert.SerializeObject(invocation.Arguments));
             scope.Span.Log($"Classe {invocation.TargetType.FullName} executando o metodo {invocation.Method.Name}.");
             invocation.Proceed();
             scope.Span.Log($"Classe {invocation.TargetType.FullName} executado o metodo {invocation.Method.Name}.");
         }
         catch (Exception)
         {
             scope.Span.Log($"Erro com a classe {invocation.TargetType.FullName} executado o metodo {invocation.Method.Name}.");
             throw;
         }
     }
 }