コード例 #1
0
        public void ProcessMessage(object sender, BasicDeliverEventArgs e)
        {
            var mi = MessageInfo(e);

            try
            {
                _logger.LogInformation($@"Got message {mi}");

                TSrc src;
                using (var ms = new MemoryStream(e.Body))
                {
                    src = ProtoBuf.Serializer.Deserialize <TSrc>(ms);
                    _logger.LogInformation($@"Message {mi}
JSON view: {JsonConvert.SerializeObject(src, Formatting.Indented)}");
                }
                var dst = _transformer.Transform(src);
                _writer.WriteAsync(dst).Wait();
                _channel.BasicAck(e.DeliveryTag, false);
                OnProcessed?.Invoke(this, new MessageProcessedEventArgs <TSrc>(src));
                _logger.LogInformation($"Message processed {mi}");
            }
            catch (Exception ex)
            {
                _logger.LogError($@"Error message process {mi}
Requeue after {_rabbitConfig.RequeueOnErrorAfter}
Error {ex.Message}. {ex}");
                OnProcessError?.Invoke(this, new MessageProcessErrorEventArgs(ex));
                Task.Run(async() =>
                {
                    await Task.Delay(_rabbitConfig.RequeueOnErrorAfter);

                    _channel?.BasicNack(e.DeliveryTag, false, true);
                    _logger.LogInformation($@"Reqeue message {mi}");
                });
            }
        }
コード例 #2
0
 /// <summary>
 /// Fires the process error output event.
 /// </summary>
 /// <param name="content">The content.</param>
 private void FireProcessErrorEvent(string content) => OnProcessError?.Invoke(this, new ProcessEventArgs(content));
コード例 #3
0
 /// <summary>
 /// Fires the process error output event.
 /// </summary>
 /// <param name="content">The content.</param>
 private void FireProcessErrorEvent(string content)
 {
     //  Get the event and fire it.
     OnProcessError?.Invoke(this, new ProcessEventArgs(content));
 }