Documentation ¶
Overview ¶
Package stan is a Go client for the NATS Streaming messaging system (https://nats.io).
Package stan is a Go client for the NATS Streaming messaging system (https://nats.io).
Index ¶
- Constants
- Variables
- type AckHandler
- type Conn
- type Msg
- type MsgHandler
- type Option
- type Options
- type Subscription
- type SubscriptionOption
- func AckWait(t time.Duration) SubscriptionOption
- func DeliverAllAvailable() SubscriptionOption
- func DurableName(name string) SubscriptionOption
- func MaxInflight(m int) SubscriptionOption
- func SetManualAckMode() SubscriptionOption
- func StartAt(sp pb.StartPosition) SubscriptionOption
- func StartAtSequence(seq uint64) SubscriptionOption
- func StartAtTime(start time.Time) SubscriptionOption
- func StartAtTimeDelta(ago time.Duration) SubscriptionOption
- func StartWithLastReceived() SubscriptionOption
- type SubscriptionOptions
Constants ¶
const ( // DefaultNatsURL is the default URL the client connects to DefaultNatsURL = "nats://localhost:4222" // DefaultConnectWait is the default timeout used for the connect operation DefaultConnectWait = 2 * time.Second // DefaultDiscoverPrefix is the prefix subject used to connect to the NATS Streaming server DefaultDiscoverPrefix = "_STAN.discover" // DefaultACKPrefix is the prefix subject used to send ACKs to the NATS Streaming server DefaultACKPrefix = "_STAN.acks" // DefaultMaxPubAcksInflight is the default maximum number of published messages // without outstanding ACKs from the server DefaultMaxPubAcksInflight = 16384 )
const ( // DefaultAckWait indicates how long the server should wait for an ACK before resending a message DefaultAckWait = 30 * time.Second // DefaultMaxInflight indicates how many messages with outstanding ACKs the server can send DefaultMaxInflight = 1024 )
const Version = "0.2.0"
Version is the NATS Streaming Go Client version
Variables ¶
var ( ErrConnectReqTimeout = errors.New("stan: connect request timeout") ErrCloseReqTimeout = errors.New("stan: close request timeout") ErrConnectionClosed = errors.New("stan: connection closed") ErrTimeout = errors.New("stan: publish ack timeout") ErrBadAck = errors.New("stan: malformed ack") ErrBadSubscription = errors.New("stan: invalid subscription") ErrBadConnection = errors.New("stan: invalid connection") ErrManualAck = errors.New("stan: cannot manually ack in auto-ack mode") ErrNilMsg = errors.New("stan: nil message") )
Errors
var DefaultOptions = Options{ NatsURL: DefaultNatsURL, ConnectTimeout: DefaultConnectWait, AckTimeout: DefaultAckWait, DiscoverPrefix: DefaultDiscoverPrefix, MaxPubAcksInflight: DefaultMaxPubAcksInflight, }
DefaultOptions are the NATS Streaming client's default options
var DefaultSubscriptionOptions = SubscriptionOptions{ MaxInflight: DefaultMaxInflight, AckWait: DefaultAckWait, }
DefaultSubscriptionOptions are the default subscriptions' options
Functions ¶
This section is empty.
Types ¶
type AckHandler ¶
AckHandler is used for Async Publishing to provide status of the ack. The func will be passed teh GUID and any error state. No error means the message was successfully received by NATS Streaming.
type Conn ¶
type Conn interface { // Publish Publish(subject string, data []byte) error PublishAsync(subject string, data []byte, ah AckHandler) (string, error) // Publish with Reply PublishWithReply(subject, reply string, data []byte) error PublishAsyncWithReply(subject, reply string, data []byte, ah AckHandler) (string, error) // Subscribe Subscribe(subject string, cb MsgHandler, opts ...SubscriptionOption) (Subscription, error) // QueueSubscribe QueueSubscribe(subject, qgroup string, cb MsgHandler, opts ...SubscriptionOption) (Subscription, error) // Close Close() error // NatsConn returns the underlying NATS conn. Use this with care. For // example, closing the wrapped NATS conn will put the NATS Streaming Conn // in an invalid state. NatsConn() *nats.Conn }
Conn represents a connection to the NATS Streaming subsystem. It can Publish and Subscribe to messages within the NATS Streaming cluster.
type Msg ¶
type Msg struct { pb.MsgProto // MsgProto: Seq, Subject, Reply[opt], Data, Timestamp, CRC32[opt] Sub Subscription }
Msg is the client defined message, which includes proto, then back link to subscription.
type MsgHandler ¶
type MsgHandler func(msg *Msg)
MsgHandler is a callback function that processes messages delivered to asynchronous subscribers.
type Option ¶
Option is a function on the options for a connection.
func ConnectWait ¶
ConnectWait is an Option to set the timeout for establishing a connection.
func MaxPubAcksInflight ¶ added in v0.2.0
MaxPubAcksInflight is an Option to set the maximum number of published messages without outstanding ACKs from the server.
func NatsConn ¶
NatsConn is an Option to set the underlying NATS connection to be used by a NATS Streaming Conn object.
func PubAckWait ¶
PubAckWait is an Option to set the timeout for waiting for an ACK for a published message.
type Options ¶
type Options struct { NatsURL string NatsConn *nats.Conn ConnectTimeout time.Duration AckTimeout time.Duration DiscoverPrefix string MaxPubAcksInflight int }
Options can be used to a create a customized connection.
type Subscription ¶
type Subscription interface {
Unsubscribe() error
}
Subscription represents a subscription within the NATS Streaming cluster. Subscriptions will be rate matched and follow at-least delivery semantics.
type SubscriptionOption ¶
type SubscriptionOption func(*SubscriptionOptions) error
SubscriptionOption is a function on the options for a subscription.
func AckWait ¶
func AckWait(t time.Duration) SubscriptionOption
AckWait is an Option to set the timeout for waiting for an ACK from the cluster's point of view for delivered messages.
func DeliverAllAvailable ¶
func DeliverAllAvailable() SubscriptionOption
DeliverAllAvailable will deliver all messages available.
func DurableName ¶
func DurableName(name string) SubscriptionOption
DurableName sets the DurableName for the subcriber.
func MaxInflight ¶
func MaxInflight(m int) SubscriptionOption
MaxInflight is an Option to set the maximum number of messages the cluster will send without an ACK.
func SetManualAckMode ¶
func SetManualAckMode() SubscriptionOption
SetManualAckMode will allow clients to control their own acks to delivered messages.
func StartAt ¶
func StartAt(sp pb.StartPosition) SubscriptionOption
StartAt sets the desired start position for the message stream.
func StartAtSequence ¶
func StartAtSequence(seq uint64) SubscriptionOption
StartAtSequence sets the desired start sequence position and state.
func StartAtTime ¶
func StartAtTime(start time.Time) SubscriptionOption
StartAtTime sets the desired start time position and state.
func StartAtTimeDelta ¶
func StartAtTimeDelta(ago time.Duration) SubscriptionOption
StartAtTimeDelta sets the desired start time position and state using the delta.
func StartWithLastReceived ¶
func StartWithLastReceived() SubscriptionOption
StartWithLastReceived is a helper function to set start position to last received.
type SubscriptionOptions ¶
type SubscriptionOptions struct { // DurableName, if set will survive client restarts. DurableName string // Controls the number of messages the cluster will have inflight without an ACK. MaxInflight int // Controls the time the cluster will wait for an ACK for a given message. AckWait time.Duration // StartPosition enum from proto. StartAt pb.StartPosition // Optional start sequence number. StartSequence uint64 // Optional start time. StartTime time.Time // Option to do Manual Acks ManualAcks bool }
SubscriptionOptions are used to control the Subscription's behavior.