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 ¶
- type Message
- type MessageBuilder
- func NewMessageBuilder() *MessageBuilderdeprecated
- func (b *MessageBuilder) Body(body string) *MessageBuilder
- func (b *MessageBuilder) Build() (*Message, error)
- func (b *MessageBuilder) QueueURL(url string) *MessageBuilder
- func (b *MessageBuilder) WithDeduplicationID(id string) *MessageBuilder
- func (b *MessageBuilder) WithDelaySeconds(seconds int64) *MessageBuilder
- func (b *MessageBuilder) WithGroupID(id string) *MessageBuilder
- type Publisher
- type TracedPublisher
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 to build messages to be sent to SQS.
func NewMessageBuilder
deprecated
func NewMessageBuilder() *MessageBuilder
NewMessageBuilder creates a new MessageBuilder that helps to create 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)
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.