sqs

package
v0.61.2 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2021 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package sqs provides a set of common interfaces and structs for publishing messages to AWS SQS. Implementations in this package also include distributed tracing capabilities by default.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Message

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

Message is a struct embedding information about messages that will be later published to SQS thanks to the SQS publisher.

type MessageBuilder

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

MessageBuilder helps building messages to be sent to SQS.

func NewMessageBuilder deprecated

func NewMessageBuilder() *MessageBuilder

NewMessageBuilder creates a new MessageBuilder that helps creating messages.

Deprecated: The SQS client package is superseded by the `github.com/beatlabs/client/sqs/v2` package. Please refer to the documents and the examples for the usage.

This package is frozen and no new functionality will be added.

func (*MessageBuilder) Body

func (b *MessageBuilder) Body(body string) *MessageBuilder

Body sets the body of the message.

func (*MessageBuilder) Build

func (b *MessageBuilder) Build() (*Message, error)

Build tries to build a message given its specified data and returns an error if any goes wrong.

func (*MessageBuilder) QueueURL

func (b *MessageBuilder) QueueURL(url string) *MessageBuilder

QueueURL sets the queue URL.

func (*MessageBuilder) WithDeduplicationID

func (b *MessageBuilder) WithDeduplicationID(id string) *MessageBuilder

WithDeduplicationID sets the deduplication ID.

func (*MessageBuilder) WithDelaySeconds

func (b *MessageBuilder) WithDelaySeconds(seconds int64) *MessageBuilder

WithDelaySeconds sets the delay of the message, in seconds.

func (*MessageBuilder) WithGroupID

func (b *MessageBuilder) WithGroupID(id string) *MessageBuilder

WithGroupID sets the group ID.

type Publisher

type Publisher interface {
	Publish(ctx context.Context, msg Message) (messageID string, err error)
}

Publisher is the interface defining an SQS publisher, used to publish messages to SQS.

Example
// Create the SQS API with the required config, credentials, etc.
sess, err := session.NewSession(
	aws.NewConfig().
		WithEndpoint("http://localhost:4576").
		WithRegion("eu-west-1").
		WithCredentials(
			credentials.NewStaticCredentials("aws-id", "aws-secret", "aws-token"),
		),
)
if err != nil {
	panic(err)
}

api := sqs.New(sess)

// Create the publisher
pub, err := NewPublisher(api)
if err != nil {
	panic(err)
}

// Create a message
msg, err := NewMessageBuilder().
	Body("message body").
	QueueURL("http://localhost:4576/queue/foo-queue").
	Build()
if err != nil {
	panic(err)
}

// Publish it
msgID, err := pub.Publish(context.Background(), *msg)
if err != nil {
	panic(err)
}

fmt.Println(msgID)
Output:

type TracedPublisher

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

TracedPublisher is an implementation of the Publisher interface with added distributed tracing capabilities.

func NewPublisher deprecated

func NewPublisher(api sqsiface.SQSAPI) (*TracedPublisher, error)

NewPublisher creates a new SQS publisher.

Deprecated: The SQS client package is superseded by the `github.com/beatlabs/client/sqs/v2` package. Please refer to the documents and the examples for the usage.

This package is frozen and no new functionality will be added.

func (TracedPublisher) Publish

func (p TracedPublisher) Publish(ctx context.Context, msg Message) (messageID string, err error)

Publish tries to publish a new message to SQS. It also stores tracing information.

Directories

Path Synopsis
Package sqs provides a set of common interfaces and structs for publishing messages to AWS SQS.
Package sqs provides a set of common interfaces and structs for publishing messages to AWS SQS.

Jump to

Keyboard shortcuts

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