natsq

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

README

natsq

Go Report Card GitHub license codecov

Queue Worker implementation with NATS

Installing

go get github.com/nbs-go/natsq

Usage

TODO

Contributors

Documentation

Index

Constants

View Source
const (
	ContextStartedAt = ContextKey("startedAt")
	ContextPublishId = ContextKey("publishId")
)
View Source
const (
	HeaderPublishId = "PublishId"
)

Variables

This section is empty.

Functions

func NewPublishId

func NewPublishId(ctx context.Context) (context.Context, string)

NewPublishId retrieve publishId from logging requestId or generates new one requestId is useful for tracing related log

Types

type ContextKey

type ContextKey string

type Handler

type Handler interface {
	OnSubscribePanic(ctx context.Context, topic string, data []byte, errValue any, stack []byte)
	Publish(ctx context.Context, conn *nats.Conn, msg *nats.Msg) error
}

type InitOptionSetter

type InitOptionSetter func(o *initOption)

func WithHandler

func WithHandler(h Handler) InitOptionSetter

type SubscriberHandlerFunc

type SubscriberHandlerFunc func(ctx context.Context, msg *nats.Msg)

SubscriberHandlerFunc is a native NATS handler that includes context

type Worker

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

Worker is a Queue Messaging adapter implemented using NATS

func NewWorker

func NewWorker(host string, port uint16, authToken string, args ...InitOptionSetter) *Worker

func (*Worker) Client

func (w *Worker) Client() (*nats.Conn, error)

func (*Worker) Close

func (w *Worker) Close()

func (*Worker) MustPublish

func (w *Worker) MustPublish(ctx context.Context, topic string, payload any)

func (*Worker) MustSubscribe

func (w *Worker) MustSubscribe(topic string, handler WorkerHandlerFunc)

func (*Worker) Publish

func (w *Worker) Publish(ctx context.Context, topic string, data any) (err error)

func (*Worker) PublishMsg

func (w *Worker) PublishMsg(msg *nats.Msg) (err error)

PublishMsg publish message using native nats.Conn PublishMsg function

func (*Worker) Subscribe

func (w *Worker) Subscribe(topic string, handler WorkerHandlerFunc) error

Subscribe handles subscription using WorkerHandler that wraps into native NATS SubscriberHandler

func (*Worker) SubscribeMsg

func (w *Worker) SubscribeMsg(topic string, handler SubscriberHandlerFunc) error

SubscribeMsg handles subscription using native NATS SubscriberHandler

type WorkerHandlerFunc

type WorkerHandlerFunc func(ctx context.Context, topic string, data []byte) (noRetry bool)

WorkerHandlerFunc is a default function for Worker type for handling subscription noRetry indicates function is done and no retry

Jump to

Keyboard shortcuts

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