nats

package
v0.0.71 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2024 License: MIT Imports: 14 Imported by: 1

Documentation

Index

Constants

View Source
const (
	RegionHdr     = "region"
	RequestIdHdr  = "x-request-id"
	CompanyIdHdr  = "x-company-id"
	UserIdHdr     = "x-user-id"
	LocationIdHdr = "x-location-id"
	SessionIdHdr  = "x-session-id"
)

Default headers which published in messages from API backend

View Source
const (
	ContentEncodingHdr = "content-encoding"
)

Default nats headers

Variables

This section is empty.

Functions

func DecodeNatsMsg added in v0.0.70

func DecodeNatsMsg(msg *gnats.Msg, v interface{}) error

DecodeNatsMsg will decode the nats message into the provided interface.

func GetCompanyIdFromHeader added in v0.0.71

func GetCompanyIdFromHeader(m *nats.Msg) string

func GetContentEncodingFromHeader added in v0.0.71

func GetContentEncodingFromHeader(m *nats.Msg) string

func GetCustomHeaderValue added in v0.0.71

func GetCustomHeaderValue(m *nats.Msg, header string) string

func GetLocationIdFromHeader added in v0.0.71

func GetLocationIdFromHeader(m *nats.Msg) string

func GetMsgIdFromHeader added in v0.0.71

func GetMsgIdFromHeader(m *nats.Msg) string

func GetRegionFromHeader added in v0.0.71

func GetRegionFromHeader(m *nats.Msg) string

getters

func GetRequestIdFromHeader added in v0.0.71

func GetRequestIdFromHeader(m *nats.Msg) string

func GetSessionIdFromHeader added in v0.0.71

func GetSessionIdFromHeader(m *nats.Msg) string

func GetUserIdFromHeader added in v0.0.71

func GetUserIdFromHeader(m *nats.Msg) string

func NewJetStreamConsumer added in v0.0.71

func NewJetStreamConsumer(config ConsumerConfig) (jetstream.Consumer, error)

NewJetStreamConsumer creates a new JetStream consumer with the given configuration. This will create or update a consumer based on the given configuration.

func NewNats

func NewNats(log logger.Logger, name string, hosts string, credentials gnats.Option, opts ...gnats.Option) (*gnats.Conn, error)

NewNats will return a new nats connections

func SetCompanyIdHeader added in v0.0.71

func SetCompanyIdHeader(m *nats.Msg, value string)

func SetContentEncodingHeader added in v0.0.71

func SetContentEncodingHeader(m *nats.Msg, value string)

func SetCustomHeader added in v0.0.71

func SetCustomHeader(m *nats.Msg, header string, value string)

func SetLocationIdHeader added in v0.0.71

func SetLocationIdHeader(m *nats.Msg, value string)

func SetMsgIdHeader added in v0.0.71

func SetMsgIdHeader(m *nats.Msg, value string)

func SetRegionHeader added in v0.0.71

func SetRegionHeader(m *nats.Msg, value string)

setters

func SetRequestIdHeader added in v0.0.71

func SetRequestIdHeader(m *nats.Msg, value string)

func SetSessionIdHeader added in v0.0.71

func SetSessionIdHeader(m *nats.Msg, value string)

func SetUserIdHeader added in v0.0.71

func SetUserIdHeader(m *nats.Msg, value string)

Types

type ConsumerConfig added in v0.0.71

type ConsumerConfig struct {
	Context   context.Context
	Logger    logger.Logger
	Config    jetstream.ConsumerConfig
	JetStream jetstream.JetStream
	Stream    string
}

type EphemeralOptsFunc added in v0.0.27

type EphemeralOptsFunc func(config *ephemeralConsumerConfig) error

func WithEphemeralAckWait added in v0.0.28

func WithEphemeralAckWait(duration time.Duration) EphemeralOptsFunc

WithEphemeralAckWait overrides the default ack wait of 30s

func WithEphemeralConsumerDescription added in v0.0.27

func WithEphemeralConsumerDescription(description string) EphemeralOptsFunc

WithEphemeralConsumerDescription set the consumer description

func WithEphemeralContext added in v0.0.27

func WithEphemeralContext(context context.Context) EphemeralOptsFunc

WithEphemeralContext set the internal context

func WithEphemeralDelivery added in v0.0.27

func WithEphemeralDelivery(policy nats.DeliverPolicy) EphemeralOptsFunc

WithEphemeralDelivery set the internal context

func WithEphemeralDisableSubscriberLogging added in v0.0.34

func WithEphemeralDisableSubscriberLogging() EphemeralOptsFunc

WithEphemeralDisableSubscriberLogging to turn off extra trace logging in the subscriber

func WithEphemeralMaxAckPending added in v0.0.27

func WithEphemeralMaxAckPending(max int) EphemeralOptsFunc

WithEphemeralMaxAckPending set the maximum ack pending value

func WithEphemeralMaxDeliver added in v0.0.27

func WithEphemeralMaxDeliver(max int) EphemeralOptsFunc

WithEphemeralMaxDeliver set the maximum deliver value

func WithEphemeralMaxRequestBatch added in v0.0.51

func WithEphemeralMaxRequestBatch(max int) EphemeralOptsFunc

WithEphemeralMaxRequestBatch set the maximum number of records to fetch

type ExactlyOnceOptsFunc added in v0.0.27

type ExactlyOnceOptsFunc func(config *exactlyOnceConsumerConfig) error

func WithExactlyOnceAckWait added in v0.0.56

func WithExactlyOnceAckWait(ackWait time.Duration) ExactlyOnceOptsFunc

Add the ability to set the ack wait time for the consumer

func WithExactlyOnceByStartTimePolicy added in v0.0.53

func WithExactlyOnceByStartTimePolicy(start time.Time) ExactlyOnceOptsFunc

func WithExactlyOnceConsumerDescription added in v0.0.27

func WithExactlyOnceConsumerDescription(description string) ExactlyOnceOptsFunc

WithExactlyOnceConsumerDescription set the consumer description

func WithExactlyOnceContext added in v0.0.27

func WithExactlyOnceContext(context context.Context) ExactlyOnceOptsFunc

WithExactlyOnceContext set the internal context

func WithExactlyOnceDelivery added in v0.0.27

func WithExactlyOnceDelivery(policy nats.DeliverPolicy) ExactlyOnceOptsFunc

WithExactlyOnceDelivery set the internal context

func WithExactlyOnceDisableSubscriberLogging added in v0.0.34

func WithExactlyOnceDisableSubscriberLogging() ExactlyOnceOptsFunc

WithExactlyOnceDisableSubscriberLogging to turn off extra trace logging in the subscriber

func WithExactlyOnceMaxDeliver added in v0.0.27

func WithExactlyOnceMaxDeliver(max int) ExactlyOnceOptsFunc

WithExactlyOnceMaxDeliver set the maximum deliver value

func WithExactlyOnceMaxRequestBatch added in v0.0.56

func WithExactlyOnceMaxRequestBatch(max int) ExactlyOnceOptsFunc

Add the ability to set the max fetch value for the consumer

func WithExactlyOnceReplicas added in v0.0.32

func WithExactlyOnceReplicas(replicas int) ExactlyOnceOptsFunc

WithExactlyOnceReplicas set the number of replicas for the consumer

type Handler added in v0.0.22

type Handler func(ctx context.Context, payload []byte, msg *nats.Msg) error

type QueueOptsFunc added in v0.0.27

type QueueOptsFunc func(config *queueConsumerConfig) error

func WithQueueAckWait added in v0.0.52

func WithQueueAckWait(max time.Duration) QueueOptsFunc

WithQueueAckWait set the maximum ack wait duration value

func WithQueueConsumerDescription added in v0.0.27

func WithQueueConsumerDescription(description string) QueueOptsFunc

WithQueueConsumerDescription set the consumer description

func WithQueueContext added in v0.0.27

func WithQueueContext(context context.Context) QueueOptsFunc

WithQueueContext set the internal context

func WithQueueDelivery added in v0.0.27

func WithQueueDelivery(policy nats.DeliverPolicy) QueueOptsFunc

WithQueueDelivery set the internal context

func WithQueueDisableSubscriberLogging added in v0.0.34

func WithQueueDisableSubscriberLogging() QueueOptsFunc

WithQueueDisableSubscriberLogging to turn off extra trace logging in the subscriber

func WithQueueMaxAckPending added in v0.0.27

func WithQueueMaxAckPending(max int) QueueOptsFunc

WithQueueMaxAckPending set the maximum ack pending value

func WithQueueMaxDeliver added in v0.0.27

func WithQueueMaxDeliver(max int) QueueOptsFunc

WithQueueMaxDeliver set the maximum deliver value

func WithQueueMaxRequestBatch added in v0.0.51

func WithQueueMaxRequestBatch(max int) QueueOptsFunc

WithQueueMaxRequestBatch set the maximum number of records to fetch

func WithQueueReplicas added in v0.0.32

func WithQueueReplicas(replicas int) QueueOptsFunc

WithQueueReplicas set the number of replicas

type Subscriber added in v0.0.22

type Subscriber interface {
	// Close the subscriber and stop delivery
	Close() error
}

Subscriber represents a nats subscriber

func NewEphemeralConsumer added in v0.0.23

func NewEphemeralConsumer(logger logger.Logger, js nats.JetStreamContext, stream string, subject string, handler Handler, opts ...EphemeralOptsFunc) (Subscriber, error)

NewEphemeralConsumer will create (or reuse) an ephemeral consumer

func NewExactlyOnceConsumer added in v0.0.3

func NewExactlyOnceConsumer(logger logger.Logger, js nats.JetStreamContext, stream string, durable string, subject string, handler Handler, opts ...ExactlyOnceOptsFunc) (Subscriber, error)

NewExactlyOnceConsumer will create (or reuse) an exactly once durable consumer

func NewQueueConsumer added in v0.0.22

func NewQueueConsumer(logger logger.Logger, js nats.JetStreamContext, stream string, durable string, subject string, handler Handler, opts ...QueueOptsFunc) (Subscriber, error)

NewQueueConsumer will create (or reuse) a queue consumer with default config

Jump to

Keyboard shortcuts

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