MCPcopy
hub / github.com/nats-io/nats.go / ExampleAckWait

Function ExampleAckWait

example_test.go:624–644  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

622}
623
624func ExampleAckWait() {
625 nc, _ := nats.Connect("localhost")
626 js, _ := nc.JetStream()
627
628 // Set custom timeout for a JetStream API request.
629 js.AddStream(&nats.StreamConfig{
630 Name: "FOO",
631 Subjects: []string{"foo"},
632 })
633
634 // Wait for an ack response for 2 seconds.
635 js.Publish("foo", []byte("Hello JS!"), nats.AckWait(2*time.Second))
636
637 // Create consumer on 'foo' subject that waits for an ack for 10s,
638 // after which the message will be delivered.
639 sub, _ := js.SubscribeSync("foo", nats.AckWait(10*time.Second))
640 msg, _ := sub.NextMsg(2 * time.Second)
641
642 // Wait for ack of ack for 2s.
643 msg.AckSync(nats.AckWait(2 * time.Second))
644}
645
646func ExampleMsg_AckSync() {
647 nc, _ := nats.Connect("localhost")

Callers

nothing calls this directly

Calls 7

ConnectMethod · 0.80
JetStreamMethod · 0.80
NextMsgMethod · 0.80
AckSyncMethod · 0.80
AddStreamMethod · 0.65
PublishMethod · 0.65
SubscribeSyncMethod · 0.65

Tested by

no test coverage detected