messagequeue

package
v2.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2026 License: AGPL-3.0 Imports: 2 Imported by: 0

Documentation

Overview

Package messagequeue provides message queue publisher and consumer interfaces with implementations for Google Pub/Sub, Redis, and Amazon SQS.

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	// ErrEmptyTopicName is returned when a topic name is empty.
	ErrEmptyTopicName = platformerrors.New("empty topic name")
)

Functions

This section is empty.

Types

type Consumer

type Consumer interface {
	Consume(ctx context.Context, stopChan chan bool, errors chan error)
}

Consumer produces events onto a queue.

type ConsumerFunc

type ConsumerFunc func(context.Context, []byte) error

ConsumerFunc is a function type that handles consumed messages.

type ConsumerProvider

type ConsumerProvider interface {
	ProvideConsumer(ctx context.Context, topic string, handlerFunc ConsumerFunc) (Consumer, error)
}

ConsumerProvider is a function that provides a Consumer for a given topic.

type NoopConsumer

type NoopConsumer struct{}

NoopConsumer is a no-op implementation of Consumer.

func (*NoopConsumer) Consume

func (n *NoopConsumer) Consume(context.Context, chan bool, chan error)

type NoopConsumerProvider

type NoopConsumerProvider struct{}

NoopConsumerProvider is a no-op implementation of ConsumerProvider.

func (*NoopConsumerProvider) ProvideConsumer

type NoopPublisher

type NoopPublisher struct{}

NoopPublisher is a no-op implementation of Publisher.

func (*NoopPublisher) Publish

func (n *NoopPublisher) Publish(context.Context, any) error

func (*NoopPublisher) PublishAsync

func (n *NoopPublisher) PublishAsync(context.Context, any)

func (*NoopPublisher) Stop

func (n *NoopPublisher) Stop()

type NoopPublisherProvider

type NoopPublisherProvider struct{}

NoopPublisherProvider is a no-op implementation of PublisherProvider.

func (*NoopPublisherProvider) Close

func (n *NoopPublisherProvider) Close()

func (*NoopPublisherProvider) ProvidePublisher

func (n *NoopPublisherProvider) ProvidePublisher(context.Context, string) (Publisher, error)

type Publisher

type Publisher interface {
	// Stop halts all publishing.
	Stop()
	// Publish writes a message onto a message queue.
	Publish(ctx context.Context, data any) error
	// PublishAsync writes a message onto a message queue, but logs any encountered errors instead of returning them.
	PublishAsync(ctx context.Context, data any)
}

Publisher produces events onto a queue.

func NewNoopPublisher

func NewNoopPublisher() Publisher

NewNoopPublisher is a noop Publisher.

Example
package main

import (
	"context"
	"fmt"

	"github.com/verygoodsoftwarenotvirus/platform/v2/messagequeue"
)

func main() {
	pub := messagequeue.NewNoopPublisher()
	defer pub.Stop()

	err := pub.Publish(context.Background(), map[string]string{"event": "user.created"})
	fmt.Println(err)
}
Output:

<nil>

type PublisherProvider

type PublisherProvider interface {
	Close()
	ProvidePublisher(ctx context.Context, topic string) (Publisher, error)
}

PublisherProvider is a function that provides a Publisher for a given topic.

func NewNoopPublisherProvider

func NewNoopPublisherProvider() PublisherProvider

NewNoopPublisherProvider is a noop PublisherProvider.

Example
package main

import (
	"context"
	"fmt"

	"github.com/verygoodsoftwarenotvirus/platform/v2/messagequeue"
)

func main() {
	provider := messagequeue.NewNoopPublisherProvider()
	defer provider.Close()

	pub, err := provider.ProvidePublisher(context.Background(), "user-events")
	if err != nil {
		panic(err)
	}

	fmt.Println(pub != nil)
}
Output:

true

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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