public static async Task Main(string[] args) { var cnInfo = new ConnectionInfo("localhost"); _client = new NatsClient(cnInfo); await _client.ConnectAsync(); _client.Sub("getTemp", stream => stream.Subscribe(msg => { var parts = msg.GetPayloadAsString().Split('@'); _client.Pub(msg.ReplyTo, $"Temp is {TempService.Get(parts[0], parts[1])}C"); })); while (true) { Console.WriteLine("Query? (y=yes;n=no)"); if (Console.ReadKey().KeyChar == 'n') { break; } Console.WriteLine(); Console.WriteLine($"Got reply: {_client.RequestAsync("getTemp", "STOCKHOLM@SWEDEN").Result.GetPayloadAsString()}"); } _client.Disconnect(); }
public void Dispose() { if (_natsClient.IsConnected) { _natsClient.Disconnect(); } }