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 ¶
var ( // ErrEmptyTopicName is returned when a topic name is empty. ErrEmptyTopicName = platformerrors.New("empty topic name") )
Functions ¶
This section is empty.
Types ¶
type ConsumerFunc ¶
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 NoopConsumerProvider ¶
type NoopConsumerProvider struct{}
NoopConsumerProvider is a no-op implementation of ConsumerProvider.
func (*NoopConsumerProvider) ProvideConsumer ¶
func (n *NoopConsumerProvider) ProvideConsumer(context.Context, string, ConsumerFunc) (Consumer, error)
type NoopPublisher ¶
type NoopPublisher struct{}
NoopPublisher is a no-op implementation of Publisher.
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 ¶
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