pm_effectively_once

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2024 License: MIT Imports: 9 Imported by: 1

Documentation

Index

Constants

View Source
const DefaultDeduplicateKey = "deduplicate_key"

Variables

This section is empty.

Functions

func SubscriptionInterceptor

func SubscriptionInterceptor(mutexer Mutexer, opt ...Option) pm.SubscriptionInterceptor

SubscriptionInterceptor process only the first event and discards the others with the same de-duplicate key. To make this interceptor work, you need to set the de-duplicate key in the attributes when publishing message like below. If the key is not set, messageID will be used as the de-duplicate key.

// publisher msg := pubsub.Message{Data: []byte("something"), Attributes: map[string]string{pm_effectively_once.DeduplicateKey: "unique-key"}} pubsub.Topic{}.Publish(ctx, msg)

// subscriber pubsubSubscriber := pm.NewSubscriber(

	pubsubClient,
	pm.WithSubscriptionInterceptor(
		pm_effectively_once.SubscriptionInterceptor(pm_effectively_once.NewRedisMutexer(redisClient)),
	),
)

Types

type Mutexer

type Mutexer interface {
	RunInTx(ctx context.Context, deduplicateKey string, f func() error) error
}

func NewDatastoreMutexer

func NewDatastoreMutexer(kind string, dsClient *datastore.Client) Mutexer

func NewMemoryMutexer

func NewMemoryMutexer() Mutexer

func NewRedisMutexer

func NewRedisMutexer(redisClient *redis.Client, keyPrefix string, lockDuration time.Duration) Mutexer

type Option

type Option func(*options)

func WithCustomDeduplicateKey

func WithCustomDeduplicateKey(key string) Option

WithCustomDeduplicateKey customizes the attribute key for de-duplicate key.

Jump to

Keyboard shortcuts

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