AckOpt are the options that can be passed when acknowledge a message.
()
| 688 | |
| 689 | // AckOpt are the options that can be passed when acknowledge a message. |
| 690 | func ExampleAckOpt() { |
| 691 | nc, err := nats.Connect("localhost") |
| 692 | if err != nil { |
| 693 | log.Fatal(err) |
| 694 | } |
| 695 | |
| 696 | // Create JetStream context to produce/consumer messages that will be persisted. |
| 697 | js, err := nc.JetStream() |
| 698 | if err != nil { |
| 699 | log.Fatal(err) |
| 700 | } |
| 701 | |
| 702 | // Create stream to persist messages published on 'foo'. |
| 703 | js.AddStream(&nats.StreamConfig{ |
| 704 | Name: "FOO", |
| 705 | Subjects: []string{"foo"}, |
| 706 | }) |
| 707 | |
| 708 | // Publish is synchronous by default, and waits for a PubAck response. |
| 709 | js.Publish("foo", []byte("Hello JS!")) |
| 710 | |
| 711 | sub, _ := js.SubscribeSync("foo") |
| 712 | msg, _ := sub.NextMsg(2 * time.Second) |
| 713 | |
| 714 | // Ack and wait for 2 seconds |
| 715 | msg.InProgress(nats.AckWait(2)) |
| 716 | |
| 717 | // Using a context. |
| 718 | ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second) |
| 719 | defer cancel() |
| 720 | msg.Ack(nats.Context(ctx)) |
| 721 | } |
| 722 | |
| 723 | func ExamplePullOpt() { |
| 724 | nc, err := nats.Connect("localhost") |
nothing calls this directly
no test coverage detected