-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRequestCommand.cs
More file actions
30 lines (28 loc) · 897 Bytes
/
RequestCommand.cs
File metadata and controls
30 lines (28 loc) · 897 Bytes
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
using System;
using System.Text;
using NATS.Client;
using NLog;
namespace nats_tools
{
public class RequestCommand : AbstractSendCommand<RequestOptions>
{
private new static Logger Logger { get; } = LogManager.GetCurrentClassLogger();
public RequestCommand() : base(Logger)
{
}
protected override void DoWork(string msgTxt, byte[] data)
{
Logger.Info($"Request: {Options.Subject} => {data.Length} bytes");
try
{
var msgReply = Options.Connection.Request(Options.Subject, data, Options.Timeout);
var replyTxt = Encoding.Default.GetString(msgReply.Data);
Logger.Info($"Reply: '{replyTxt}' - {data.Length} bytes");
}
catch (NATSTimeoutException e)
{
Logger.Error(e.Message);
}
}
}
}