Skip to content

Instantly share code, notes, and snippets.

@danielwertheim
Last active October 16, 2016 14:49
Show Gist options
  • Save danielwertheim/2f618ce8fd9a55f2656aa5841e653c02 to your computer and use it in GitHub Desktop.
Save danielwertheim/2f618ce8fd9a55f2656aa5841e653c02 to your computer and use it in GitHub Desktop.
Future sample usage of NatsConsumer
public Task Alternative1() {
var consumer = new NatsConsumer(client);
var subscription = await consumer.SubscribeAsync("mySubject", msg => {
//do something with the message
});
//time goes by
subscription.Dispose(); //issues client.Unsub(subject) against NATS broker as well as removes handler
consumer.Dispose(); //for any non disposed subscriptions, it issues client.Unsub(subject) against NATS broker as well as removes handler
}
public Task Alternative2() {
var consumer = new NatsConsumer(client);
var subscriptionId = await consumer.SubscribeAsync("mySubject", msg => {
//do something with the message
});
//time goes by
await consumer.UnsubscribeAsync(subscriptionId); //issues client.Unsub(subject) against NATS broker as well as removes handler
consumer.Dispose(); //for any non unsubscribed subscriptions, it issues client.Unsub(subject) against NATS broker as well as removes handler
}
public Task Alternative3() {
var consumer = new NatsConsumer(client);
var subscription = await consumer.SubscribeAsync("mySubject", msg => {
//do something with the message
});
//time goes by
subscription.Release(); //issues client.Unsub(subject) against NATS broker as well as removes handler
consumer.Dispose(); //for any non unsubscribed subscriptions, it issues client.Unsub(subject) against NATS broker as well as removes handler
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment