-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMessageHandlers.cs
35 lines (26 loc) · 1.27 KB
/
MessageHandlers.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
using DotNext.IO;
using DotNext.Net.Cluster.Messaging;
using DotNext.Runtime.Serialization;
namespace Raft3DockerClusterExample;
public class TryMeHandler : JsonMessageHandler<TestMessagingDto, TestMessagingDto, TryMeHandler>, INameOfMessageHandler
{
private readonly ILogger<TryMeHandler> _logger;
public TryMeHandler(ILogger<TryMeHandler> logger) => _logger = logger;
public override Task<TestMessagingDto> OnMessage(TestMessagingDto message, ISubscriber sender, object? _, CancellationToken token)
{
_logger.LogInformation($"Got {message.MyCustomValue}");
return Task.FromResult<TestMessagingDto>(new("jens:" + message.MyCustomValue));
}
public static string Name => nameof(TryMeHandler);
}
public class TryMeBroadcastHandler : JsonMessageHandler<TestMessagingDto, TryMeBroadcastHandler>, INameOfMessageHandler
{
private readonly ILogger<TryMeBroadcastHandler> _logger;
public TryMeBroadcastHandler(ILogger<TryMeBroadcastHandler> logger) => _logger = logger;
public override Task OnMessage(TestMessagingDto message, ISubscriber sender, object? _, CancellationToken token)
{
_logger.LogInformation($"Got Broadcast {message.MyCustomValue}");
return Task.CompletedTask;
}
public static string Name => nameof(TryMeBroadcastHandler);
}