Last active
October 16, 2016 14:49
-
-
Save danielwertheim/2f618ce8fd9a55f2656aa5841e653c02 to your computer and use it in GitHub Desktop.
Future sample usage of NatsConsumer
This file contains 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
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