Thanks to visit codestin.com
Credit goes to pkg.go.dev

interfaces

package
v1.0.0-beta.8 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 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)

DelayFn is a function type that represents a delay function. It takes the current number of retries as input and returns the delay in seconds.

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(_ int64) (delay int64) {
		return 0
	}
	// DefaultDelayFn is the default delay function that will be used if no delay function is provided.
	// It is set to LinearDelayFn by default.
	DefaultDelayFn DelayFn = LinearDelayFn
)

type InboundMessage

type InboundMessage struct {
	Message
	// RetryCount is the number of times the message has been retried.
	// This is set by the library to identify the number of times the message has been retried.
	RetryCount int64 `json:"retryCount"`
	// Metadata is the metadata of the message.
	// This is set by the library to identify the metadata of the message.
	Metadata map[string]any `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 is the unique identifier for the message.
	// This is set by the publisher to identify the message in the queue.
	// The id is auto-generated by the the library if not provided.
	ID string `json:"id"`
	// Action is the action that will be performed on the message.
	// This is set by the publisher to identify the action that will be performed on the message.
	// For RabbitMQ, the action is the routing key.
	Action string `json:"action"`
	// Topic is the topic that the message will be published to.
	// This is set by the publisher to identify the topic that the message will be published to.
	// For RabbitMQ, the topic is the exchange name.
	Topic string `json:"topic"`
	// Data is the data that will be published to the queue.
	// This is set by the publisher to identify the data that will be published to the queue.
	// It should be a valid JSON object.
	Data any `json:"data"`
	// ContentType is the content type of the message.
	// This is set by the publisher to identify the content type of the message.
	// Default value is "application/json".
	ContentType headerVal.ContentType `json:"-"`
	// Timestamp is the timestamp of the message.
	// This is set by the publisher to identify the timestamp of the message.
	// Default value is the current time.
	Timestamp time.Time `json:"timestamp"`
	// Headers is the headers of the message.
	// This is set by the publisher to identify the headers of the message.
	// This library will provide extra headers values by default based on the library type.
	// Don't use any prefix with :goqueue-, it will conflicted and overrided by the library.
	Headers map[string]any `json:"-"`
	// ServiceAgent is the service agent that will be used to publish the message.
	// This is set by the publisher to identify the service agent that will be used to publish the message.
	// This will be set by the library and override any value
	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

GetSchemaVersion is a method to get the schema version of the message. This is used to get the schema version of the message. This will be set by the library and override any value

func (*Message) SetSchemaVersion

func (m *Message) SetSchemaVersion(v string)

SetSchemaVersion is a method to set the schema version of the message. This is used to set the schema version of the message. This will be set by the library and override any value

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

PublisherMiddlewareFunc is a function type that represents a publisher middleware function. It takes a next PublisherFunc as input parameter and returns a PublisherFunc.

Jump to

Keyboard shortcuts

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