Line data Source code
1 : using System;
2 : using System.Collections.Generic;
3 : using Akka.Actor;
4 : using Akka.Event;
5 : using cdmdotnet.Logging;
6 :
7 : namespace Cqrs.Akka.Domain
8 : {
9 : /// <summary>
10 : /// Proxy deadletters to <see cref="ILogger"/>.
11 : /// </summary>
12 : public class DeadletterToLoggerProxy : ReceiveActor
13 1 : {
14 : private ILogger Logger { get; set; }
15 :
16 : /// <summary>
17 : /// Instantiates a new instance of <see cref="DeadletterToLoggerProxy"/>
18 : /// </summary>
19 1 : public DeadletterToLoggerProxy(ILogger logger)
20 : {
21 : Logger = logger;
22 : Receive<DeadLetter>(dl => HandleDeadletter(dl));
23 : }
24 :
25 : private void HandleDeadletter(DeadLetter dl)
26 : {
27 : string message = dl.Message.ToString();
28 : bool value;
29 : if (bool.TryParse(message, out value) && value)
30 : return;
31 : Logger.LogWarning("Akka delivery failed", dl.Recipient.Path.ToString(), new Exception(dl.Message.ToString()), metaData: new Dictionary<string, object>{{"Sender", dl.Sender}});
32 : }
33 : }
34 : }
|