mirror of
https://github.com/taigrr/nats.docs
synced 2025-01-18 04:03:23 -08:00
updating docs
This commit is contained in:
@@ -34,7 +34,7 @@
|
||||
|
||||
|
||||
<div class="tab__content">
|
||||
<pre id="drain_sub_go_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/go-nats-examples/blob/master/api-examples/drain_sub/main.go#L13-67"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-go">
|
||||
<pre id="drain_sub_go_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/go-nats-examples/blob/master/api-examples/drain_sub/main.go#L13-70"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-go">
|
||||
nc, err := nats.Connect("demo.nats.io")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
@@ -49,8 +49,11 @@
|
||||
|
||||
msgAfterDrain := "not this one"
|
||||
|
||||
// Just to not collide using the demo server with other users.
|
||||
subject := nats.NewInbox()
|
||||
|
||||
// This callback will process each message slowly
|
||||
sub, err := nc.Subscribe("updates", func(m *nats.Msg) {
|
||||
sub, err := nc.Subscribe(subject, func(m *nats.Msg) {
|
||||
if string(m.Data) == msgAfterDrain {
|
||||
errCh <- fmt.Errorf("Should not have received this message")
|
||||
return
|
||||
@@ -64,7 +67,7 @@
|
||||
|
||||
// Send 2 messages
|
||||
for i := 0; i < 2; i++ {
|
||||
nc.Publish("updates", []byte("hello"))
|
||||
nc.Publish(subject, []byte("hello"))
|
||||
}
|
||||
|
||||
// Call Drain on the subscription. It unsubscribes but
|
||||
@@ -74,7 +77,7 @@
|
||||
}
|
||||
|
||||
// Send one more message, this message should not be received
|
||||
nc.Publish("updates", []byte(msgAfterDrain))
|
||||
nc.Publish(subject, []byte(msgAfterDrain))
|
||||
|
||||
// Wait for the subscription to have processed the 2 messages.
|
||||
done.Wait()
|
||||
|
||||
Reference in New Issue
Block a user