Exemple #1
0
        /// <summary>
        ///     Обработка вернувшихся сообщений
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private void OnMessageReturned(object sender, EasyNetQ.MessageReturnedEventArgs args)
        {
            var stringDictionary      = args.MessageProperties.Headers.ToDictionary(x => x.Key, x => Encoding.UTF8.GetString((byte[])x.Value));
            var textMapExtractAdapter = new TextMapExtractAdapter(stringDictionary);
            var spanContext           = _tracer.Extract(BuiltinFormats.HttpHeaders, textMapExtractAdapter);

            using (_tracer.BuildSpan(nameof(OnMessageReturned)).AddReference(References.ChildOf, spanContext).StartActive(true))
                using (_logger.BeginScope(new[] { new KeyValuePair <string, object>(nameof(_tracer.ActiveSpan.Context.TraceId), _tracer.ActiveSpan.Context.TraceId) }))
                {
                    _tracer.ActiveSpan.SetTag(Tags.Error, true);

                    if (args.MessageProperties.Headers.TryGetValue(MessageKeyHeader, out var bytes) && bytes is byte[] value)
                    {
                        var key = Encoding.UTF8.GetString(value);

                        _logger.LogError("Message returned {Exchange} {RoutingKey} reason {ReturnReason} {Key}",
                                         args.MessageReturnedInfo.Exchange,
                                         args.MessageReturnedInfo.RoutingKey,
                                         args.MessageReturnedInfo.ReturnReason,
                                         key);

                        MessageReturned?.Invoke(new MessageReturnedEventArgs(key));
                    }
                    else
                    {
                        _logger.LogError("Can not get error message filename");
                    }
                }
        }
Exemple #2
0
 private void OnMessageReturned(ReturnedMessageEvent @event)
 {
     MessageReturned?.Invoke(this, new MessageReturnedEventArgs(@event.Body, @event.Properties, @event.Info));
 }
Exemple #3
0
 protected void OnMessageReturned(ReturnedMessageEvent args) => MessageReturned?.Invoke(this, new MessageReturnedEventArgs(args.Body, args.Properties, args.Info));