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

Function NewWithDomain

jetstream/jetstream.go:554–578  ·  view source on GitHub ↗

NewWithDomain returns a new JetStream instance and sets the domain name token used when sending JetStream requests. The domain name token will be used in API requests to JetStream, e.g. $JS.<domain>.API.STREAM.INFO.<stream>. Available options: - [WithClientTrace] - enables request/response tracing.

(nc *nats.Conn, domain string, opts ...JetStreamOpt)

Source from the content-addressed store, hash-verified

552// - [WithPublishAsyncMaxPending] - sets the maximum outstanding async publishes
553// that can be inflight at one time.
554func NewWithDomain(nc *nats.Conn, domain string, opts ...JetStreamOpt) (JetStream, error) {
555 jsOpts := JetStreamOptions{
556 publisherOpts: asyncPublisherOpts{
557 maxpa: defaultAsyncPubAckInflight,
558 },
559 Domain: domain,
560 DefaultTimeout: defaultAPITimeout,
561 }
562 setReplyPrefix(nc, &jsOpts)
563 for _, opt := range opts {
564 if err := opt(&jsOpts); err != nil {
565 return nil, err
566 }
567 }
568 if domain == "" {
569 return nil, errors.New("domain cannot be empty")
570 }
571 jsOpts.apiPrefix = fmt.Sprintf(jsDomainT, domain)
572 js := &jetStream{
573 conn: nc,
574 opts: jsOpts,
575 publisher: &jetStreamClient{asyncPublisherOpts: jsOpts.publisherOpts},
576 }
577 return js, nil
578}
579
580// Conn returns the underlying NATS connection.
581func (js *jetStream) Conn() *nats.Conn {

Callers 4

TestNewWithAPIPrefixFunction · 0.92
TestNewWithDomainFunction · 0.92

Calls 1

setReplyPrefixFunction · 0.85

Tested by 4

TestNewWithAPIPrefixFunction · 0.74
TestNewWithDomainFunction · 0.74