Created
February 3, 2022 22:27
-
-
Save alexandrebl/c410828ff852241ce5a64983c3b94fec to your computer and use it in GitHub Desktop.
NATS.io Subscriber C# .Net Core
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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