Skip to content

Instantly share code, notes, and snippets.

@neuecc
Created June 21, 2022 09:29
Show Gist options
  • Save neuecc/d754f246b3cd5e075239d1d3b364dacb to your computer and use it in GitHub Desktop.
Save neuecc/d754f246b3cd5e075239d1d3b364dacb to your computer and use it in GitHub Desktop.
// 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