interfaces

package
v1.0.0-beta.2 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DelayFn

type DelayFn func(currenRetries int64) (delay int64)
var (
	// ExponentialBackoffDelayFn is a delay function that implements exponential backoff.
	// It takes the number of retries as input and returns the delay in seconds.
	ExponentialBackoffDelayFn DelayFn = func(currenRetries int64) (delay int64) {
		return 2 << (currenRetries - 1)
	}

	// LinearDelayFn is a delay function that implements linear delay.
	// It takes the number of retries as input and returns the delay in seconds.
	LinearDelayFn DelayFn = func(currenRetries int64) (delay int64) {
		return currenRetries
	}

	// NoDelayFn is a DelayFn implementation that returns 0 delay for retries.
	NoDelayFn DelayFn = func(currenRetries int64) (delay int64) {
		return 0
	}
	DefaultDelayFn DelayFn = LinearDelayFn
)

type InboundMessage

type InboundMessage struct {
	Message
	RetryCount int64                  `json:"retryCount"`
	Metadata   map[string]interface{} `json:"metadata"`
	// Ack is used for confirming the message. It will drop the message from the queue.
	Ack func(ctx context.Context) (err error) `json:"-"`
	// Nack is used for rejecting the message. It will requeue the message to be re-delivered again.
	Nack func(ctx context.Context) (err error) `json:"-"`
	// MoveToDeadLetterQueue is used for rejecting the message same with Nack, but instead of requeueing the message,
	// Read how to configure dead letter queue in each queue provider.
	// eg RabbitMQ: https://www.rabbitmq.com/docs/dlx
	MoveToDeadLetterQueue func(ctx context.Context) (err error) `json:"-"`
	// Requeue is used to put the message back to the tail of the queue after a delay.
	RetryWithDelayFn func(ctx context.Context, delayFn DelayFn) (err error) `json:"-"`
}

type InboundMessageHandler

type InboundMessageHandler interface {
	HandleMessage(ctx context.Context, m InboundMessage) (err error)
}

type InboundMessageHandlerFunc

type InboundMessageHandlerFunc func(ctx context.Context, m InboundMessage) (err error)

func (InboundMessageHandlerFunc) HandleMessage

func (mhf InboundMessageHandlerFunc) HandleMessage(ctx context.Context, m InboundMessage) (err error)

type InboundMessageHandlerMiddlewareFunc

type InboundMessageHandlerMiddlewareFunc func(next InboundMessageHandlerFunc) InboundMessageHandlerFunc

type Message

type Message struct {
	ID           string                     `json:"id"`
	Action       string                     `json:"action"`
	Topic        string                     `json:"topic"`
	Data         any                        `json:"data"`
	ContentType  headerVal.ContentType      `json:"-"`
	Timestamp    time.Time                  `json:"timestamp"`
	Headers      map[string]interface{}     `json:"-"`
	ServiceAgent headerVal.GoquServiceAgent `json:"-"`
	// contains filtered or unexported fields
}

Message represents a message that will be published to the queue It contains the message ID, action, topic, data, content type, timestamp, headers, and service agent. The schema version is set by the SetSchemaVersion method. The message is used to publish messages to the queue. Read the concept of message publishing in the documentation, here: TODO(bxcodec): Add link to the documentation

func (*Message) GetSchemaVersion

func (m *Message) GetSchemaVersion() string

func (*Message) SetSchemaVersion

func (m *Message) SetSchemaVersion(v string)

type PublisherFunc

type PublisherFunc func(ctx context.Context, m Message) (err error)

PublisherFunc is a function type that represents a publisher function. It takes a context and a message as input parameters and returns an error.

func (PublisherFunc) Publish

func (f PublisherFunc) Publish(ctx context.Context, m Message) (err error)

Publish sends the given message using the provided context. It calls the underlying PublisherFunc to perform the actual publishing. If an error occurs during publishing, it is returned.

type PublisherHandler

type PublisherHandler interface {
	Publish(ctx context.Context, m Message) (err error)
}

PublisherHandler is an interface that defines the behavior of a message publisher.

type PublisherMiddlewareFunc

type PublisherMiddlewareFunc func(next PublisherFunc) PublisherFunc

Jump to

Keyboard shortcuts

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