broker

package
v0.2.6 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2023 License: Apache-2.0, MIT Imports: 4 Imported by: 0

Documentation

Overview

Package broker contains message broker abstraction and NATS JetStream broker implementation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Broker

type Broker interface {
	// Sub subscribes to broker and returns a channel to receive messages.
	Sub() (<-chan Message, error)
	// Pub synchronously publishes a message to broker.
	Pub([]byte) error
	// Exit gracefully shuts down subscriber.
	Exit()
}

Broker defines common broker methods.

type Message

type Message struct {
	Data       []byte
	Ack        func()
	InProgress func()
}

Message contains data from the broker.

type NatsJetStream

type NatsJetStream struct {
	Debug func(s string)
	// contains filtered or unexported fields
}

NatsJetStream implements Broker interface for NATS JetStream broker. Exported field Debug can be used for debugging.

func NewNatsJetStream

func NewNatsJetStream(client nats.JetStreamContext, config *NatsJetStreamConfig) *NatsJetStream

NewNatsJetStream creates new NATS JetStream broker implementing broker.Broker interface.

func (*NatsJetStream) Exit added in v0.2.0

func (b *NatsJetStream) Exit()

Exit implements broker.Broker interface.

func (*NatsJetStream) Pub

func (b *NatsJetStream) Pub(data []byte) error

Pub implements broker.Broker interface.

func (*NatsJetStream) Sub

func (b *NatsJetStream) Sub() (<-chan Message, error)

Sub implements broker.Broker interface.

type NatsJetStreamConfig

type NatsJetStreamConfig struct {
	// Consume this subject
	ConsumeSubject string
	// Optional. If provided, queue group will be used.
	ConsumerGroup string
	// Produce into this subject
	ProduceSubject string
	// ReceiveChannelSize will prevent dropping messages caused by th slow consumer.
	ReceiveChannelSize int
	// How long to wait for ACK. If crossed, message will be redelivered. Default 60.s
	AckWait time.Duration
	// MaxRedeliveries defines how many times message will be redelivered if not acknowledged. Default 2.
	MaxRedeliveries uint8
}

NatsJetStreamConfig contains NatsJetStream configuration parameters.

Jump to

Keyboard shortcuts

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