Created
June 21, 2022 09:29
-
-
Save neuecc/d754f246b3cd5e075239d1d3b364dacb to your computer and use it in GitHub Desktop.
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
// create connection(default, connect to nats://localhost:4222) | |
await using var conn = new NatsConnection(); | |
// for subscriber. await register to NATS server(not means await complete) | |
var subscription = await conn.SubscribeAsync<Person>("foo", x => | |
{ | |
Console.WriteLine($"Received {x}"); | |
}); | |
// for publisher. | |
await conn.PublishAsync("foo", new Person(30, "bar")); | |
// unsubscribe | |
subscription.Dipose(); | |
// --- | |
public record Person(int Age, string Name); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment