connector

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: May 18, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDbNameMissing          = errors.New("invalid option: `dbName` is missing")
	ErrCollNameMissing        = errors.New("invalid option: `collName` is missing")
	ErrInvalidCollSizeInBytes = errors.New("invalid option: `collSizeInBytes` must be greater than 0")
	ErrInvalidDbAndCollNames  = errors.New("invalid option: `dbName` and `tokensDbName` cannot be the same if `collName` and `tokensCollName` are the same")
)

Functions

This section is empty.

Types

type CollectionOption

type CollectionOption func(*collection) error

CollectionOption is used to configure a MongoDB collection to be watched.

func WithChangeStreamPreAndPostImages deprecated

func WithChangeStreamPreAndPostImages() CollectionOption

WithChangeStreamPreAndPostImages enables MongoDB's changeStreamPreAndPostImages configuration.

Deprecated: will be removed in future versions. Set this configuration directly on MongoDB instead.

func WithStreamName

func WithStreamName(streamName string) CollectionOption

WithStreamName sets the NATS stream name, where the MongoDB change events will be published for the collection to be watched.

func WithTokensCollCapped

func WithTokensCollCapped(collSizeInBytes int64) CollectionOption

WithTokensCollCapped sets the MongoDB collection that will store the resume tokens for the collection to be watched as capped, with the given size.

func WithTokensCollName

func WithTokensCollName(tokensCollName string) CollectionOption

WithTokensCollName sets the name of the MongoDB collection that will store the resume tokens for the collection to be watched.

func WithTokensDbName

func WithTokensDbName(tokensDbName string) CollectionOption

WithTokensDbName sets the name of the MongoDB database that will store the resume tokens collection for the collection to be watched.

type Connector

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

The Connector type represents a connector between MongoDB and NATS.

func New

func New(opts ...Option) (*Connector, error)

New creates a new Connector. The given options will override its default configuration.

func (*Connector) Run

func (c *Connector) Run() error

Run runs the Connector. It performs the following operations:

For each configured collection to be watched:
	- It creates the given collection on MongoDB, if it does not already exist
	- It creates the resume tokens collection for the given collection on MongoDB, if it does not already exist
	- It creates the given stream on NATS, if it does not already exist
	- Spins up a goroutine to watch the given collection
It runs an HTTP server in its own goroutine.
It runs another goroutine that will perform graceful shutdown once the Connector's context is cancelled.

type Option

type Option func(*Options) error

Option is used to configure the Connector.

func WithCollection

func WithCollection(dbName, collName string, opts ...CollectionOption) Option

WithCollection configures a collection to be watched by the Connector, with the given options.

func WithContext

func WithContext(ctx context.Context) Option

WithContext sets the Connector's context.

func WithLogLevel

func WithLogLevel(logLevel string) Option

WithLogLevel sets the Connector's log level.

func WithMongoUri

func WithMongoUri(mongoUri string) Option

WithMongoUri sets the Connector's MongoDB URI.

func WithNatsUrl

func WithNatsUrl(natsUrl string) Option

WithNatsUrl sets the Connector's NATS URL.

func WithServerAddr

func WithServerAddr(serverAddr string) Option

WithServerAddr sets the Connector's HTTP server address.

type Options

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

Options represents the possible options to be applied to a Connector.

Jump to

Keyboard shortcuts

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