jsm

package module
v0.0.18 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2020 License: Apache-2.0 Imports: 20 Imported by: 60

README

Overview

This is a library for managing and interacting with JetStream.

This library provides API access to all the JetStream related abilities of the nats CLI utility.

NOTE For general access to JetStream no special libraries are needed, the standard language specific NATS client can be used. These are optional helpers.

Stability

This package is under development, while JetStream is in Preview we make no promises about the API stability of this package.

NATS Connection

Streams, Consumers and Templates need their own NATS connection to manage their communication with the network these are set using jsm.StreamConnection() and jsm.ConsumerConnection() which allows you to set a pre configured NATS connection, a timeout and a context using jsm.RequestOptions. These are also accepted by many functions allowing you to override timeouts etc

Streams

Creating Streams

Before anything you have to create a stream, the basic pattern is:

nc, _ := nats.Connect(servers)
stream, _ := jsm.NewStream("ORDERS", jsm.Subjects("ORDERS.*"), jsm.StreamConnection(jsm.WithConnection(nc)), jsm.MaxAge(24*365*time.Hour), jsm.FileStorage())

This can get quite verbose so you might have a template configuration of your own choosing to create many similar Streams.

template, _ := jsm.NewStreamConfiguration(jsm.DefaultStream, jsm.StreamConnection(jsm.WithConnection(nc)), jsm.MaxAge(24 * 365 * time.Hour), jsm.FileStorage())

orders, _ := jsm.NewStreamFromDefault("ORDERS", template, jsm.StreamConnection(jsm.WithConnection(nc)), jsm.Subjects("ORDERS.*"))
archive, _ := jsm.NewStreamFromDefault("ARCHIVE", template, jsm.StreamConnection(jsm.WithConnection(nc)), jsm.Subjects("ARCHIVE"), jsm.MaxAge(5*template.MaxAge))

The jsm.NewStream uses jsm.DefaultStream as starting defaults. We also have jsm.DefaultWorkQueue to help you with a sane starting point.

You can even copy Stream configurations this way (not content, just configuration), this creates STAGING using ORDERS config with a different set of subjects:

orders, err := jsm.NewStream("ORDERS", jsm.Subjects("ORDERS.*"), jsm.StreamConnection(jsm.WithConnection(nc)), jsm.MaxAge(24*365*time.Hour), jsm.FileStorage())
staging, err := jsm.NewStreamFromDefault("STAGING", orders.Configuration(), jsm.StreamConnection(jsm.WithConnection(nc)), jsm.Subjects("STAGINGORDERS.*"))

Loading references to existing streams

Once a Stream exist you can load it later:

orders, err := jsm.LoadStream("ORDERS", jsm.WithConnection(nc))

This will fail if the stream does not exist, create and load can be combined:

orders, err := jsm.LoadOrNewFromDefault("ORDERS", template, jsm.Subjects("ORDERS.*"), jsm.WithConnection(nc))

This will create the Stream if it doesn't exist, else load the existing one - though no effort is made to ensure the loaded one matches the desired configuration in that case.

Associated Consumers

With a stream handle you can get lists of known Consumers using stream.ConsumerNames(), or create new Consumers within the stream using stream.NewConsumer and stream.NewConsumerFromDefault. Consumers can also be loaded using stream.LoadConsumer and you can combine load and create using stream.LoadOrNewConsumer and stream.LoadOrNewConsumerFromDefault.

These methods just proxy to the Consumer specific ones which will be discussed below. When creating new Consumer instances this way the connection information from the Stream is passed into the Consumer.

Other actions

There are a number of other functions allowing you to purge messages, read individual messages, get statistics and access the configuration. Review the godoc for details.

Consumers

Creating

Above you saw that once you have a handle to a stream you can create and load consumers, you can access the consumer directly though, lets create one:

consumer, err := jsm.NewConsumer("ORDERS", "NEW", jsm.ConsumerConnection(jsm.WithConnection(nc)), jsm.FilterSubject("ORDERS.received"), jsm.SampleFrequency("100"))

Like with Streams we have NewConsumerFromDefault, LoadOrNewConsumer and LoadOrNewConsumerFromDefault and we supply 2 default default configurations to help you DefaultConsumer and SampledDefaultConsumer.

When using LoadOrNewConsumer and LoadOrNewConsumerFromDefault if a durable name is given then that has to match the name supplied.

Many options exist to set starting points, durability and more - everything that you will find in the jsm utility, review the godoc for full details.

Consuming

Push-based Consumers are accessed using the normal NATS subscribe dynamics, we have a few helpers:

sub, err := consumer.Subscribe(func(m *nats.Msg) {
   // handle the message
})

We have all the usual Subscribe, ChanSubscribe, ChanQueueSubscribe, SubscribeSync, QueueSubscribe, QueueSubscribeSync and QueueSubscribeSyncWithChan, these just proxy to the standard go library functions of the same name but it helps you with the topic names etc.

For Pull-based Consumers we have:

// 1 message
msg, err := consumer.NextMsg()

// 10 messages
msgs, err := consumer.NextMsgs(10)

When consuming these messages they have metadata attached that you can parse:

msg, _ := consumer.NextMsg(jsm.WithTimeout(60*time.Second))
meta, _ := jsm.ParseJSMsgMetadata(msg)

At this point you have access to meta.Stream, meta.Consumer for the names and meta.StreamSequence, meta.ConsumerSequence to determine which exact message and meta.Delivered for how many times it was redelivered.

Other Actions

There are a number of other functions to help you determine if its Pull or Push, is it Durable, Sampled and to access the full configuration.

Documentation

Overview

Package jsm provides client helpers for managing and interacting with NATS JetStream

Index

Constants

This section is empty.

Variables

View Source
var DefaultConsumer = api.ConsumerConfig{
	DeliverPolicy: api.DeliverAll,
	AckPolicy:     api.AckExplicit,
	AckWait:       30 * time.Second,
	ReplayPolicy:  api.ReplayInstant,
}

DefaultConsumer is the configuration that will be used to create new Consumers in NewConsumer

View Source
var DefaultStream = api.StreamConfig{
	Retention:    api.LimitsPolicy,
	Discard:      api.DiscardOld,
	MaxConsumers: -1,
	MaxMsgs:      -1,
	MaxBytes:     -1,
	MaxAge:       24 * 365 * time.Hour,
	MaxMsgSize:   -1,
	Replicas:     1,
	NoAck:        false,
}

DefaultStream is a template configuration with StreamPolicy retention and 1 years maximum age. No storage type or subjects are set

View Source
var DefaultStreamConfiguration = DefaultStream

DefaultStreamConfiguration is the configuration that will be used to create new Streams in NewStream

View Source
var DefaultWorkQueue = api.StreamConfig{
	Retention:    api.WorkQueuePolicy,
	Discard:      api.DiscardOld,
	MaxConsumers: -1,
	MaxMsgs:      -1,
	MaxBytes:     -1,
	MaxAge:       24 * 365 * time.Hour,
	MaxMsgSize:   -1,
	Replicas:     1,
	NoAck:        false,
}

DefaultWorkQueue is a template configuration with WorkQueuePolicy retention and 1 years maximum age. No storage type or subjects are set

View Source
var SampledDefaultConsumer = api.ConsumerConfig{
	DeliverPolicy:   api.DeliverAll,
	AckPolicy:       api.AckExplicit,
	AckWait:         30 * time.Second,
	ReplayPolicy:    api.ReplayInstant,
	SampleFrequency: "100%",
}

SampledDefaultConsumer is the configuration that will be used to create new Consumers in NewConsumer

Functions

func BackupJetStreamConfiguration

func BackupJetStreamConfiguration(backupDir string, data bool) error

BackupJetStreamConfiguration creates a backup of all configuration for Streams, Consumers and Stream Templates.

Stream data can optionally be backed up

func Connect

func Connect(servers string, opts ...nats.Option) (err error)

Connect connects to NATS and configures it to use the connection in future interactions with JetStream Deprecated: Use Request Options to supply the connection

func Connection

func Connection() *nats.Conn

Connection is the active NATS connection being used Deprecated: Use Request Options to supply the connection

func ConsumerNames

func ConsumerNames(stream string, opts ...RequestOption) (names []string, err error)

StreamNames is a sorted list of all known consumers within a stream

func EachStream

func EachStream(cb func(*Stream), opts ...RequestOption) (err error)

EachStream iterates over all known Streams

func EachStreamTemplate

func EachStreamTemplate(cb func(*StreamTemplate), opts ...RequestOption) (err error)

EachStreamTemplate iterates over all known Stream Templates

func Flush

func Flush() error

Flush flushes the underlying NATS connection Deprecated: Use Request Options to supply the connection

func IsErrorResponse

func IsErrorResponse(m *nats.Msg) bool

IsErrorResponse checks if the message holds a standard JetStream error TODO: parse for error response

func IsJetStreamEnabled

func IsJetStreamEnabled(opts ...RequestOption) bool

IsJetStreamEnabled determines if JetStream is enabled for the current account

func IsKnownConsumer

func IsKnownConsumer(stream string, consumer string, opts ...RequestOption) (bool, error)

IsKnownConsumer determines if a Consumer is known for a specific Stream

func IsKnownStream

func IsKnownStream(stream string, opts ...RequestOption) (bool, error)

IsKnownStream determines if a Stream is known

func IsKnownStreamTemplate

func IsKnownStreamTemplate(template string, opts ...RequestOption) (bool, error)

IsKnownStreamTemplate determines if a StreamTemplate is known

func IsOKResponse

func IsOKResponse(m *nats.Msg) bool

IsOKResponse checks if the message holds a standard JetStream error TODO: parse json responses

func IsValidName added in v0.0.18

func IsValidName(n string) bool

IsValidName verifies if n is a valid stream, template or consumer name

func JetStreamAccountInfo

func JetStreamAccountInfo(opts ...RequestOption) (info *api.JetStreamAccountStats, err error)

JetStreamAccountInfo retrieves information about the current account limits and more

func NextMsg

func NextMsg(stream string, consumer string, opts ...RequestOption) (msgs *nats.Msg, err error)

func NextSubject

func NextSubject(stream string, consumer string) (string, error)

NextSubject returns the subject used to retrieve the next message for pull-based Consumers, empty when not a pull-base consumer

func NoTrace

func NoTrace()

NoTrace disables Trace()

func NoValidate

func NoValidate()

NoValidate disables Validate()

func ParseErrorResponse

func ParseErrorResponse(m *nats.Msg) error

ParseErrorResponse parses the JetStream response, if it's an error returns an error instance holding the message else nil TODO: parse json error response

func ParseEvent

func ParseEvent(e []byte) (schema string, event interface{}, err error)

ParseMessage parses event e and returns event as for example *api.ConsumerAckMetric, all unknown event schemas will be of type *UnknownMessage

func RestoreJetStreamConfiguration

func RestoreJetStreamConfiguration(backupDir string, update bool) error

RestoreJetStreamConfiguration restores the configuration from a backup made by BackupJetStreamConfiguration

func RestoreJetStreamConfigurationFile

func RestoreJetStreamConfigurationFile(path string, update bool) error

RestoreJetStreamConfigurationFile restores a single file from a backup made by BackupJetStreamConfiguration

func SetConnection

func SetConnection(c *nats.Conn)

SetConnection sets the connection used to perform requests. Will force using old style requests. Deprecated: Use Request Options to supply the connection

func SetTimeout

func SetTimeout(t time.Duration)

SetTimeout sets the timeout for requests to JetStream Deprecated: Use Request Options to supply the timeout

func StreamNames

func StreamNames(opts ...RequestOption) (names []string, err error)

StreamNames is a sorted list of all known Streams

func StreamTemplateNames

func StreamTemplateNames(opts ...RequestOption) (templates []string, err error)

StreamTemplateNames is a sorted list of all known StreamTemplates

func Trace

func Trace()

Trace produce logs for all interactions with the server

func Validate

func Validate()

Validate enables JSON Schema validation of all responses from the Server

Types

type BackupData

type BackupData struct {
	Type          string `json:"type"`
	Time          string `json:"time"`
	Configuration []byte `json:"configuration"`
	Checksum      string `json:"checksum"`
}

type Consumer

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

Consumer represents a JetStream consumer

func Consumers

func Consumers(stream string, opts ...RequestOption) (consumers []*Consumer, err error)

Consumers is a sorted list of all known Consumers within a Stream

func LoadConsumer

func LoadConsumer(stream string, name string, opts ...RequestOption) (consumer *Consumer, err error)

LoadConsumer loads a consumer by name

func LoadOrNewConsumer

func LoadOrNewConsumer(stream string, name string, opts ...ConsumerOption) (consumer *Consumer, err error)

LoadOrNewConsumer loads a consumer by name if known else creates a new one with these properties

func LoadOrNewConsumerFromDefault

func LoadOrNewConsumerFromDefault(stream string, name string, template api.ConsumerConfig, opts ...ConsumerOption) (consumer *Consumer, err error)

LoadOrNewConsumerFromDefault loads a consumer by name if known else creates a new one with these properties based on template

func NewConsumer

func NewConsumer(stream string, opts ...ConsumerOption) (consumer *Consumer, err error)

NewConsumer creates a consumer based on DefaultConsumer modified by opts

func NewConsumerFromDefault

func NewConsumerFromDefault(stream string, dflt api.ConsumerConfig, opts ...ConsumerOption) (consumer *Consumer, err error)

NewConsumerFromDefault creates a new consumer based on a template config that gets modified by opts

func (*Consumer) AckPolicy

func (c *Consumer) AckPolicy() api.AckPolicy

func (*Consumer) AckSampleSubject

func (c *Consumer) AckSampleSubject() string

AckSampleSubject is the subject used to publish ack samples to

func (*Consumer) AckWait

func (c *Consumer) AckWait() time.Duration

func (*Consumer) AcknowledgedFloor

func (c *Consumer) AcknowledgedFloor(opts ...RequestOption) (stats api.SequencePair, err error)

AcknowledgedFloor reports the highest contiguous message sequences that were acknowledged

func (*Consumer) AdvisorySubject

func (c *Consumer) AdvisorySubject() string

AdvisorySubject is a wildcard subscription subject that subscribes to all advisories for this consumer

func (*Consumer) ChanQueueSubscribe

func (c *Consumer) ChanQueueSubscribe(group string, ch chan *nats.Msg) (sub *nats.Subscription, err error)

ChanQueueSubscribe see nats.ChanQueueSubscribe Deprecated: use core nats feature

func (*Consumer) ChanSubscribe

func (c *Consumer) ChanSubscribe(ch chan *nats.Msg) (sub *nats.Subscription, err error)

ChanSubscribe see nats.ChangSubscribe Deprecated: use core nats feature

func (*Consumer) Configuration

func (c *Consumer) Configuration() (config api.ConsumerConfig)

Configuration is the Consumer configuration

func (*Consumer) Delete

func (c *Consumer) Delete() (err error)

Delete deletes the Consumer, after this the Consumer object should be disposed

func (*Consumer) DeliverPolicy

func (c *Consumer) DeliverPolicy() api.DeliverPolicy

func (*Consumer) DeliveredState

func (c *Consumer) DeliveredState(opts ...RequestOption) (stats api.SequencePair, err error)

DeliveredState reports the messages sequences that were successfully delivered

func (*Consumer) DeliverySubject

func (c *Consumer) DeliverySubject() string

func (*Consumer) DurableName

func (c *Consumer) DurableName() string

func (*Consumer) FilterSubject

func (c *Consumer) FilterSubject() string

func (*Consumer) IsDurable

func (c *Consumer) IsDurable() bool

func (*Consumer) IsEphemeral

func (c *Consumer) IsEphemeral() bool

func (*Consumer) IsPullMode

func (c *Consumer) IsPullMode() bool

func (*Consumer) IsPushMode

func (c *Consumer) IsPushMode() bool

func (*Consumer) IsSampled

func (c *Consumer) IsSampled() bool

func (*Consumer) MaxDeliver

func (c *Consumer) MaxDeliver() int

func (*Consumer) MetricSubject

func (c *Consumer) MetricSubject() string

MetricSubject is a wildcard subscription subject that subscribes to all metrics for this consumer

func (*Consumer) Name

func (c *Consumer) Name() string

func (*Consumer) NextMsg

func (c *Consumer) NextMsg(opts ...RequestOption) (m *nats.Msg, err error)

NextMsg retrieves the next message

func (*Consumer) NextSubject

func (c *Consumer) NextSubject() string

NextSubject returns the subject used to retrieve the next message for pull-based Consumers, empty when not a pull-base consumer

func (*Consumer) PendingMessageCount

func (c *Consumer) PendingMessageCount(opts ...RequestOption) (int, error)

PendingMessageCount reports the number of messages sent but not yet acknowledged

func (*Consumer) QueueSubscribe

func (c *Consumer) QueueSubscribe(queue string, h func(*nats.Msg)) (sub *nats.Subscription, err error)

QueueSubscribe see nats.QueueSubscribe Deprecated: use core nats feature

func (*Consumer) QueueSubscribeSync

func (c *Consumer) QueueSubscribeSync(queue string) (sub *nats.Subscription, err error)

QueueSubscribeSync see nats.QueueSubscribeSync Deprecated: use core nats feature

func (*Consumer) QueueSubscribeSyncWithChan

func (c *Consumer) QueueSubscribeSyncWithChan(queue string, ch chan *nats.Msg) (sub *nats.Subscription, err error)

QueueSubscribeSyncWithChan see nats.QueueSubscribeSyncWithChan Deprecated: use core nats feature

func (*Consumer) RateLimit added in v0.0.18

func (c *Consumer) RateLimit() uint64

func (*Consumer) RedeliveryCount

func (c *Consumer) RedeliveryCount(opts ...RequestOption) (int, error)

RedeliveryCount reports the number of redelivers that were done

func (*Consumer) ReplayPolicy

func (c *Consumer) ReplayPolicy() api.ReplayPolicy

func (*Consumer) Reset

func (c *Consumer) Reset(opts ...RequestOption) error

Reset reloads the Consumer configuration from the JetStream server

func (*Consumer) SampleFrequency

func (c *Consumer) SampleFrequency() string

func (*Consumer) StartSequence

func (c *Consumer) StartSequence() uint64

func (*Consumer) StartTime

func (c *Consumer) StartTime() time.Time

func (*Consumer) State

func (c *Consumer) State(opts ...RequestOption) (api.ConsumerInfo, error)

State loads a snapshot of consumer state including delivery counts, retries and more

func (*Consumer) StreamName

func (c *Consumer) StreamName() string

func (*Consumer) Subscribe

func (c *Consumer) Subscribe(h func(*nats.Msg)) (sub *nats.Subscription, err error)

Subscribe see nats.Subscribe Deprecated: use core nats feature

func (*Consumer) SubscribeSync

func (c *Consumer) SubscribeSync() (sub *nats.Subscription, err error)

SubscribeSync see nats.SubscribeSync Deprecated: use core nats feature

type ConsumerBackup

type ConsumerBackup struct {
	Name   string             `json:"name"`
	Stream string             `json:"stream"`
	Config api.ConsumerConfig `json:"config"`
}

type ConsumerCfg

type ConsumerCfg struct {
	api.ConsumerConfig
	// contains filtered or unexported fields
}

func NewConsumerConfiguration

func NewConsumerConfiguration(dflt api.ConsumerConfig, opts ...ConsumerOption) (*ConsumerCfg, error)

NewConsumerConfiguration generates a new configuration based on template modified by opts

type ConsumerOption

type ConsumerOption func(o *ConsumerCfg) error

ConsumerOptions configures consumers

func AckWait

func AckWait(t time.Duration) ConsumerOption

func AcknowledgeAll

func AcknowledgeAll() ConsumerOption

func AcknowledgeExplicit

func AcknowledgeExplicit() ConsumerOption

func AcknowledgeNone

func AcknowledgeNone() ConsumerOption

func ConsumerConnection

func ConsumerConnection(opts ...RequestOption) ConsumerOption

func DeliverAllAvailable

func DeliverAllAvailable() ConsumerOption

func DeliverySubject

func DeliverySubject(s string) ConsumerOption

func DurableName

func DurableName(s string) ConsumerOption

func FilterStreamBySubject

func FilterStreamBySubject(s string) ConsumerOption

func MaxDeliveryAttempts

func MaxDeliveryAttempts(n int) ConsumerOption

func RateLimitBitsPerSecond added in v0.0.18

func RateLimitBitsPerSecond(bps uint64) ConsumerOption

func ReplayAsReceived

func ReplayAsReceived() ConsumerOption

func ReplayInstantly

func ReplayInstantly() ConsumerOption

func SamplePercent

func SamplePercent(i int) ConsumerOption

func StartAtSequence

func StartAtSequence(s uint64) ConsumerOption

func StartAtTime

func StartAtTime(t time.Time) ConsumerOption

func StartAtTimeDelta

func StartAtTimeDelta(d time.Duration) ConsumerOption

func StartWithLastReceived

func StartWithLastReceived() ConsumerOption

func StartWithNextReceived

func StartWithNextReceived() ConsumerOption

type MsgInfo

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

MsgInfo holds metadata about a message that was received from JetStream

func ParseJSMsgMetadata

func ParseJSMsgMetadata(m *nats.Msg) (info *MsgInfo, err error)

ParseJSMsgMetadata parse the reply subject metadata to determine message metadata

func (*MsgInfo) Consumer

func (i *MsgInfo) Consumer() string

func (*MsgInfo) ConsumerSequence

func (i *MsgInfo) ConsumerSequence() int64

func (*MsgInfo) Delivered

func (i *MsgInfo) Delivered() int

func (*MsgInfo) Stream

func (i *MsgInfo) Stream() string

func (*MsgInfo) StreamSequence

func (i *MsgInfo) StreamSequence() int64

func (*MsgInfo) TimeStamp

func (i *MsgInfo) TimeStamp() time.Time

type RequestOption

type RequestOption func(o *reqoptions)

RequestOption is a option to configure the NATS related options

func WithAPIValidation

func WithAPIValidation() RequestOption

WithAPIValidation validates responses sent from the NATS server against a schema

func WithConnection

func WithConnection(nc *nats.Conn) RequestOption

WithConnection sets the connection to use

func WithContext

func WithContext(ctx context.Context) RequestOption

WithContext sets a context to use for a specific request

func WithTimeout

func WithTimeout(t time.Duration) RequestOption

WithTimeout sets a timeout for the requests

func WithTrace

func WithTrace() RequestOption

WithTrace enables logging of JSON API requests and responses

type RestoreProgress

type RestoreProgress interface {
	// StartTime is when the process started
	StartTime() time.Time
	// EndTime is when the process ended - zero when not completed
	EndTime() time.Time
	// ChunkSize is the size of the data packets sent over NATS
	ChunkSize() int
	// ChunksSent is the number of chunks of size ChunkSize that was sent
	ChunksSent() uint32
	// ChunksToSend number of chunks of ChunkSize expected to be sent
	ChunksToSend() int
	// BytesSent is the number of bytes sent so far
	BytesSent() uint64
	// BytesPerSecond is the number of bytes received in the last second, 0 during the first second
	BytesPerSecond() uint64
}

func RestoreSnapshotFromFile

func RestoreSnapshotFromFile(ctx context.Context, stream string, file string, opts ...SnapshotOption) (RestoreProgress, *api.StreamState, error)

type SnapshotOption

type SnapshotOption func(o *snapshotOptions)

func RestoreNotify

func RestoreNotify(cb func(RestoreProgress)) SnapshotOption

RestoreNotify notifies cb about progress of the restore operation

func SnapshotChunkSize

func SnapshotChunkSize(sz int) SnapshotOption

SnapshotChunkSize sets the size of data chunks to retrieve

func SnapshotConnection

func SnapshotConnection(opts ...RequestOption) SnapshotOption

SnapshotConnection sets the connection properties to use during snapshot

func SnapshotConsumers

func SnapshotConsumers() SnapshotOption

SnapshotConsumers includes consumer configuration and state in backups

func SnapshotDebug

func SnapshotDebug() SnapshotOption

SnapshotDebug enables logging using the standard go logging library

func SnapshotHealthCheck

func SnapshotHealthCheck() SnapshotOption

SnapshotHealthCheck performs a health check prior to starting the snapshot

func SnapshotNotify

func SnapshotNotify(cb func(SnapshotProgress)) SnapshotOption

SnapshotNotify notifies cb about progress of the snapshot operation

type SnapshotProgress

type SnapshotProgress interface {
	// StartTime is when the process started
	StartTime() time.Time
	// EndTime is when the process ended - zero when not completed
	EndTime() time.Time
	// ChunkSize is the size of the data packets sent over NATS
	ChunkSize() int
	// ChunksReceived is how many chunks of ChunkSize were received
	ChunksReceived() uint32
	// BytesReceived is how many Bytes have been received
	BytesReceived() uint64
	// BlocksReceived is how many data storage Blocks have been received
	BlocksReceived() int
	// BlockSize is the size in bytes of each data storage Block
	BlockSize() int
	// BlocksExpected is the number of blocks expected to be received
	BlocksExpected() int
	// BlockBytesReceived is the size of uncompressed block data received
	BlockBytesReceived() uint64
	// HasMetadata indicates if the metadata blocks have been received yet
	HasMetadata() bool
	// HasData indicates if all the data blocks have been received
	HasData() bool
	// BytesPerSecond is the number of bytes received in the last second, 0 during the first second
	BytesPerSecond() uint64
	// HealthCheck indicates if health checking was requested
	HealthCheck() bool
}

type Stream

type Stream struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Stream represents a JetStream Stream

func LoadOrNewStream

func LoadOrNewStream(name string, opts ...StreamOption) (stream *Stream, err error)

LoadOrNewStreamFromDefault loads an existing stream or creates a new one matching opts

func LoadOrNewStreamFromDefault

func LoadOrNewStreamFromDefault(name string, dflt api.StreamConfig, opts ...StreamOption) (stream *Stream, err error)

LoadOrNewStreamFromDefault loads an existing stream or creates a new one matching opts and template

func LoadStream

func LoadStream(name string, opts ...RequestOption) (stream *Stream, err error)

LoadStream loads a stream by name

func NewStream

func NewStream(name string, opts ...StreamOption) (stream *Stream, err error)

NewStream creates a new stream using DefaultStream as a starting template allowing adjustments to be made using options

func NewStreamFromDefault

func NewStreamFromDefault(name string, dflt api.StreamConfig, opts ...StreamOption) (stream *Stream, err error)

NewStreamFromDefault creates a new stream based on a supplied template and options

func Streams

func Streams(opts ...RequestOption) (streams []*Stream, err error)

Streams is a sorted list of all known Streams

func (*Stream) AdvisorySubject

func (s *Stream) AdvisorySubject() string

AdvisorySubject is a wildcard subscription subject that subscribes to all advisories for this stream

func (*Stream) Configuration

func (s *Stream) Configuration() api.StreamConfig

func (*Stream) ConsumerNames

func (s *Stream) ConsumerNames() (names []string, err error)

ConsumerNames is a list of all known consumers for this Stream

func (*Stream) Delete

func (s *Stream) Delete() error

Delete deletes the Stream, after this the Stream object should be disposed

func (*Stream) DeleteMessage

func (s *Stream) DeleteMessage(seq int) (err error)

DeleteMessage deletes a specific message from the Stream by overwriting it with random data

func (*Stream) DuplicateWindow added in v0.0.18

func (s *Stream) DuplicateWindow() time.Duration

func (*Stream) EachConsumer

func (s *Stream) EachConsumer(cb func(consumer *Consumer)) error

EachConsumer calls cb with each known consumer for this stream, error on any error to load consumers

func (*Stream) Information

func (s *Stream) Information() (info *api.StreamInfo, err error)

Information loads the current stream information

func (*Stream) IsTemplateManaged

func (s *Stream) IsTemplateManaged() bool

IsTemplateManaged determines if this stream is managed by a template

func (*Stream) LatestInformation

func (s *Stream) LatestInformation() (info *api.StreamInfo, err error)

LatestInformation returns the most recently fetched stream information

func (*Stream) LatestState

func (s *Stream) LatestState() (state api.StreamState, err error)

LatestState returns the most recently fetched stream state

func (*Stream) LoadConsumer

func (s *Stream) LoadConsumer(name string) (*Consumer, error)

LoadConsumer loads a named consumer related to this Stream

func (*Stream) LoadOrNewConsumer

func (s *Stream) LoadOrNewConsumer(name string, opts ...ConsumerOption) (consumer *Consumer, err error)

LoadOrNewConsumer loads or creates a consumer based on these options

func (*Stream) LoadOrNewConsumerFromDefault

func (s *Stream) LoadOrNewConsumerFromDefault(name string, deflt api.ConsumerConfig, opts ...ConsumerOption) (consumer *Consumer, err error)

LoadOrNewConsumer loads or creates a consumer based on these options that adjust supplied template

func (*Stream) MaxAge

func (s *Stream) MaxAge() time.Duration

func (*Stream) MaxBytes

func (s *Stream) MaxBytes() int64

func (*Stream) MaxConsumers

func (s *Stream) MaxConsumers() int

func (*Stream) MaxMsgSize

func (s *Stream) MaxMsgSize() int32

func (*Stream) MaxMsgs

func (s *Stream) MaxMsgs() int64

func (*Stream) MetricSubject

func (s *Stream) MetricSubject() string

MetricSubject is a wildcard subscription subject that subscribes to all advisories for this stream

func (*Stream) Name

func (s *Stream) Name() string

func (*Stream) NewConsumer

func (s *Stream) NewConsumer(opts ...ConsumerOption) (consumer *Consumer, err error)

NewConsumer creates a new consumer in this Stream based on DefaultConsumer

func (*Stream) NewConsumerFromDefault

func (s *Stream) NewConsumerFromDefault(dflt api.ConsumerConfig, opts ...ConsumerOption) (consumer *Consumer, err error)

NewConsumerFromDefault creates a new consumer in this Stream based on a supplied template config

func (*Stream) NoAck

func (s *Stream) NoAck() bool

func (*Stream) Purge

func (s *Stream) Purge() error

Purge deletes all messages from the Stream

func (*Stream) ReadMessage

func (s *Stream) ReadMessage(seq int) (msg *api.StoredMsg, err error)

ReadMessage loads a message from the stream by its sequence number

func (*Stream) Replicas

func (s *Stream) Replicas() int

func (*Stream) Reset

func (s *Stream) Reset() error

Reset reloads the Stream configuration from the JetStream server

func (*Stream) Retention

func (s *Stream) Retention() api.RetentionPolicy

func (*Stream) SnapshotToFile

func (s *Stream) SnapshotToFile(ctx context.Context, file string, opts ...SnapshotOption) (SnapshotProgress, error)

SnapshotToFile creates a backup into gzipped tar file

func (*Stream) State

func (s *Stream) State() (stats api.StreamState, err error)

State retrieves the Stream State

func (*Stream) Storage

func (s *Stream) Storage() api.StorageType

func (*Stream) Subjects

func (s *Stream) Subjects() []string

func (*Stream) Template

func (s *Stream) Template() string

func (*Stream) UpdateConfiguration

func (s *Stream) UpdateConfiguration(cfg api.StreamConfig, opts ...StreamOption) error

UpdateConfiguration updates the stream using cfg modified by opts, reloads configuration from the server post update

type StreamConfig

type StreamConfig struct {
	api.StreamConfig
	// contains filtered or unexported fields
}

func NewStreamConfiguration

func NewStreamConfiguration(template api.StreamConfig, opts ...StreamOption) (*StreamConfig, error)

NewStreamConfiguration generates a new configuration based on template modified by opts

type StreamOption

type StreamOption func(o *StreamConfig) error

StreamOption configures a stream

func DiscardNew

func DiscardNew() StreamOption

func DiscardOld

func DiscardOld() StreamOption

func DuplicateWindow added in v0.0.18

func DuplicateWindow(d time.Duration) StreamOption

func FileStorage

func FileStorage() StreamOption

func InterestRetention

func InterestRetention() StreamOption

func LimitsRetention

func LimitsRetention() StreamOption

func MaxAge

func MaxAge(m time.Duration) StreamOption

func MaxBytes

func MaxBytes(m int64) StreamOption

func MaxConsumers

func MaxConsumers(m int) StreamOption

func MaxMessageSize

func MaxMessageSize(m int32) StreamOption

func MaxMessages

func MaxMessages(m int64) StreamOption

func MemoryStorage

func MemoryStorage() StreamOption

func NoAck

func NoAck() StreamOption

func Replicas

func Replicas(r int) StreamOption

func StreamConnection

func StreamConnection(opts ...RequestOption) StreamOption

func Subjects

func Subjects(s ...string) StreamOption

func WorkQueueRetention

func WorkQueueRetention() StreamOption

type StreamTemplate

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

func LoadOrNewStreamTemplate

func LoadOrNewStreamTemplate(name string, maxStreams uint32, config api.StreamConfig, opts ...StreamOption) (template *StreamTemplate, err error)

LoadOrNewStreamTemplate loads an existing template, else creates a new one based on config

func LoadStreamTemplate

func LoadStreamTemplate(name string, opts ...RequestOption) (template *StreamTemplate, err error)

LoadStreamTemplate loads a given stream template from JetStream

func NewStreamTemplate

func NewStreamTemplate(name string, maxStreams uint32, config api.StreamConfig, opts ...StreamOption) (template *StreamTemplate, err error)

NewStreamTemplate creates a new template

func (*StreamTemplate) Configuration

func (t *StreamTemplate) Configuration() api.StreamTemplateConfig

func (*StreamTemplate) Delete

func (t *StreamTemplate) Delete() error

Delete deletes the StreamTemplate, after this the StreamTemplate object should be disposed

func (*StreamTemplate) MaxStreams

func (t *StreamTemplate) MaxStreams() uint32

func (*StreamTemplate) Name

func (t *StreamTemplate) Name() string

func (*StreamTemplate) Reset

func (t *StreamTemplate) Reset() error

Reset reloads the Stream Template configuration and state from the JetStream server

func (*StreamTemplate) StreamConfiguration

func (t *StreamTemplate) StreamConfiguration() api.StreamConfig

func (*StreamTemplate) Streams

func (t *StreamTemplate) Streams() []string

type StreamTemplateConfig

type StreamTemplateConfig struct {
	api.StreamTemplateConfig
	// contains filtered or unexported fields
}

Directories

Path Synopsis
api

Jump to

Keyboard shortcuts

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