transport

package
v1.26.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 8, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package transport implements the substrate used by microservices to communicate with each other.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Conn

type Conn struct {
	// contains filtered or unexported fields
}

Conn abstracts the connection to the transport.

func (*Conn) Close

func (c *Conn) Close() error

Close closes the transport. It closes the NATS connection, if appropriate.

func (*Conn) Latency added in v1.19.0

func (c *Conn) Latency() time.Duration

Latency returns an estimate of the max roundtrip time between any publisher and subscriber.

func (*Conn) MaxPayload

func (c *Conn) MaxPayload() int64

MaxPayload returns the size limit that a message payload can have. In NATS's case, this is set by the server configuration and delivered to the client upon connect.

func (*Conn) Open

func (c *Conn) Open(ctx context.Context, logger Logger) error

Open opens the transport. It optionally connects to the NATS cluster based on settings in the environment variables.

func (*Conn) Publish

func (c *Conn) Publish(subject string, httpReq *http.Request) (err error)

Publish sends data to a subject, allowing for multiple recipients.

func (*Conn) QueueSubscribe

func (c *Conn) QueueSubscribe(subject string, queue string, handler MsgHandler) (sub *Subscription, err error)

QueueSubscribe expresses interest in a subject, which may contain wildcards. All subscribers with the same queue name form the queue group and only one member of the group is selected to receive any given message. The asterisk wildcard matches a single segment of the subject, e.g. america.usa.* will match america.usa.ca but not america.usa.ca.sfo. The gt wildcard must come at the end of the subject and matches any number of segments, e.g. e.g. america.usa.> will match america.usa.ca and america.usa.ca.sfo.

func (*Conn) Request

func (c *Conn) Request(subject string, httpReq *http.Request) (err error)

Request sends data to a subject, targeting only a single recipient.

func (*Conn) Response

func (c *Conn) Response(subject string, httpRes *http.Response) (err error)

Response sends a response to a subject, targeting only a single recipient.

func (*Conn) Subscribe

func (c *Conn) Subscribe(subject string, handler MsgHandler) (sub *Subscription, err error)

Subscribe expresses interest in a subject, which may contain wildcards. All subscribers receive all messages. The asterisk wildcard matches a single segment of the subject, e.g. america.usa.* will match america.usa.ca but not america.usa.ca.sfo. The gt wildcard must come at the end of the subject and matches any number of segments, e.g. e.g. america.usa.> will match america.usa.ca and america.usa.ca.sfo.

func (*Conn) WaitForSub added in v1.17.0

func (c *Conn) WaitForSub()

WaitForSub gives a bit of time for the subscription to be registered with NATS. It is a no op if NATS is not enabled.

type Logger

type Logger interface {
	LogInfo(ctx context.Context, msg string, args ...any)
	LogError(ctx context.Context, msg string, args ...any)
}

Logger is used by the transport to log messages in the caller's context.

type Msg

type Msg struct {
	Data     []byte
	Request  *http.Request
	Response *http.Response
}

Msg is the data packet that is transmitted over the transport.

type MsgHandler

type MsgHandler = func(msg *Msg)

MsgHandler is a function that processes a message.

type Subscription

type Subscription struct {
	// contains filtered or unexported fields
}

Subscription is an expression of interest in a subject.

func (*Subscription) Unsubscribe

func (s *Subscription) Unsubscribe() (err error)

Unsubscribe removes interest in the subject of the subscription.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL