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

Function ExampleMaxWait

example_test.go:598–622  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

596}
597
598func ExampleMaxWait() {
599 nc, _ := nats.Connect("localhost")
600
601 // Set default timeout for JetStream API requests,
602 // following requests will inherit this timeout.
603 js, _ := nc.JetStream(nats.MaxWait(3 * time.Second))
604
605 // Set custom timeout for a JetStream API request.
606 js.AddStream(&nats.StreamConfig{
607 Name: "FOO",
608 Subjects: []string{"foo"},
609 }, nats.MaxWait(2*time.Second))
610
611 sub, _ := js.PullSubscribe("foo", "my-durable-name")
612
613 // Fetch using the default timeout of 3 seconds.
614 msgs, _ := sub.Fetch(1)
615
616 // Set custom timeout for a pull batch request.
617 msgs, _ = sub.Fetch(1, nats.MaxWait(2*time.Second))
618
619 for _, msg := range msgs {
620 msg.Ack()
621 }
622}
623
624func ExampleAckWait() {
625 nc, _ := nats.Connect("localhost")

Callers

nothing calls this directly

Calls 6

ConnectMethod · 0.80
JetStreamMethod · 0.80
AddStreamMethod · 0.65
PullSubscribeMethod · 0.65
FetchMethod · 0.65
AckMethod · 0.65

Tested by

no test coverage detected