Skip to content

Instantly share code, notes, and snippets.

@alexandrebl
Created February 3, 2022 22:27
Show Gist options
  • Select an option

  • Save alexandrebl/c410828ff852241ce5a64983c3b94fec to your computer and use it in GitHub Desktop.

Select an option

Save alexandrebl/c410828ff852241ce5a64983c3b94fec to your computer and use it in GitHub Desktop.
NATS.io Subscriber C# .Net Core
using NATS.Client;
using System;
using System.Text;
namespace NatsSubscriber
{
internal class Program
{
static void Main(string[] args)
{
//conexão
var cf = new ConnectionFactory();
var c = cf.CreateConnection();
//Subscrição
EventHandler<MsgHandlerEventArgs> h = (sender, args) =>
{
Console.WriteLine($"{DateTime.Now:F} - Received: {args.Message}");
};
var sAsync = c.SubscribeAsync("foo");
sAsync.MessageHandler += h;
sAsync.Start();
Console.ReadLine();
// Desconectando
sAsync.Unsubscribe();
c.Drain();
c.Close();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment