New returns a new JetStream instance. It uses default API prefix ($JS.API) for JetStream API requests. If a custom API prefix is required, use [NewWithAPIPrefix] or [NewWithDomain]. Available options: - [WithClientTrace] - enables request/response tracing. - [WithPublishAsyncErrHandler] - sets erro
(nc *nats.Conn, opts ...JetStreamOpt)
| 468 | // - [WithPublishAsyncMaxPending] - sets the maximum outstanding async publishes |
| 469 | // that can be inflight at one time. |
| 470 | func New(nc *nats.Conn, opts ...JetStreamOpt) (JetStream, error) { |
| 471 | jsOpts := JetStreamOptions{ |
| 472 | apiPrefix: DefaultAPIPrefix, |
| 473 | publisherOpts: asyncPublisherOpts{ |
| 474 | maxpa: defaultAsyncPubAckInflight, |
| 475 | }, |
| 476 | DefaultTimeout: defaultAPITimeout, |
| 477 | } |
| 478 | setReplyPrefix(nc, &jsOpts) |
| 479 | for _, opt := range opts { |
| 480 | if err := opt(&jsOpts); err != nil { |
| 481 | return nil, err |
| 482 | } |
| 483 | } |
| 484 | js := &jetStream{ |
| 485 | conn: nc, |
| 486 | opts: jsOpts, |
| 487 | publisher: &jetStreamClient{asyncPublisherOpts: jsOpts.publisherOpts}, |
| 488 | } |
| 489 | |
| 490 | return js, nil |
| 491 | } |
| 492 | |
| 493 | const ( |
| 494 | // defaultAsyncPubAckInflight is the number of async pub acks inflight. |