Documentation
¶
Overview ¶
Package transport implements the substrate used by microservices to communicate with each other.
Index ¶
- type Conn
- func (c *Conn) Close() error
- func (c *Conn) Latency() time.Duration
- func (c *Conn) MaxPayload() int64
- func (c *Conn) Open(ctx context.Context, logger Logger) error
- func (c *Conn) Publish(subject string, httpReq *http.Request) (err error)
- func (c *Conn) QueueSubscribe(subject string, queue string, handler MsgHandler) (sub *Subscription, err error)
- func (c *Conn) Request(subject string, httpReq *http.Request) (err error)
- func (c *Conn) Response(subject string, httpRes *http.Response) (err error)
- func (c *Conn) Subscribe(subject string, handler MsgHandler) (sub *Subscription, err error)
- func (c *Conn) WaitForSub()
- type Logger
- type Msg
- type MsgHandler
- type Subscription
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) Latency ¶ added in v1.19.0
Latency returns an estimate of the max roundtrip time between any publisher and subscriber.
func (*Conn) MaxPayload ¶
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 ¶
Open opens the transport. It optionally connects to the NATS cluster based on settings in the environment variables.
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) 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 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.