delay

package
v1.4.3 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2025 License: MIT Imports: 4 Imported by: 4

Documentation

Index

Constants

View Source
const (
	DelayedUntilKey = "_watermill_delayed_until"
	DelayedForKey   = "_watermill_delayed_for"
)

Variables

This section is empty.

Functions

func Message

func Message(msg *message.Message, delay Delay)

Message sets the delay metadata on the message.

IMPORTANT: Delay doesn't work with all Pub/Subs! Using it won't have any effect on Pub/Subs that don't support it. See the list of supported Pub/Subs in the documentation: https://watermill.io/advanced/delayed-messages/

func NewPublisher

func NewPublisher(pub message.Publisher, config PublisherConfig) (message.Publisher, error)

NewPublisher wraps a publisher with a delay mechanism. A message can be published with delay metadata set in the context by using the WithContext function. If the message doesn't have the delay metadata set, the default delay will be applied, if provided.

func WithContext

func WithContext(ctx context.Context, delay Delay) context.Context

WithContext returns a new context with the given delay. If used together with a publisher wrapped with NewPublisher, the delay will be applied to the message.

IMPORTANT: Delay doesn't work with all Pub/Subs! Using it won't have any effect on Pub/Subs that don't support it. See the list of supported Pub/Subs in the documentation: https://watermill.io/advanced/delayed-messages/

Types

type DefaultDelayGeneratorParams

type DefaultDelayGeneratorParams struct {
	Topic   string
	Message *message.Message
}

type Delay

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

Delay represents a message's delay. It can be either a delay until a specific time or a delay for a specific duration. The zero value of Delay is a zero delay.

IMPORTANT: Delay doesn't work with all Pub/Subs! Using it won't have any effect on Pub/Subs that don't support it. See the list of supported Pub/Subs in the documentation: https://watermill.io/advanced/delayed-messages/

func For

func For(delayedFor time.Duration) Delay

For returns a delay of now plus the given duration.

func Until

func Until(delayedUntil time.Time) Delay

Until returns a delay of the given time.

func (Delay) IsZero

func (d Delay) IsZero() bool

type PublisherConfig

type PublisherConfig struct {
	// DefaultDelayGenerator is a function that generates the default delay for a message.
	// If the message doesn't have the delay metadata set, the default delay will be applied.
	DefaultDelayGenerator func(params DefaultDelayGeneratorParams) (Delay, error)

	// AllowNoDelay allows publishing messages without a delay set.
	// By default, the publisher returns an error when a message is published without a delay and no default delay generator is provided.
	AllowNoDelay bool
}

PublisherConfig is a configuration for the delay publisher.

Jump to

Keyboard shortcuts

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