sns

package
v0.60.1-beta Latest Latest
Warning

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

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

Documentation

Overview

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

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

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

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 SNS thanks to the SNS publisher.

type MessageBuilder

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

MessageBuilder helps building messages to be sent to SNS.

func NewMessageBuilder deprecated

func NewMessageBuilder() *MessageBuilder

NewMessageBuilder creates a new MessageBuilder that helps creating messages.

Deprecated: The SNS client package is superseded by the `github.com/beatlabs/client/sns/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) 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) Message

func (b *MessageBuilder) Message(msg string) *MessageBuilder

Message attaches a message to the message struct.

func (*MessageBuilder) MessageStructure

func (b *MessageBuilder) MessageStructure(msgStructure string) *MessageBuilder

MessageStructure sets the message structure of the message.

func (*MessageBuilder) PhoneNumber

func (b *MessageBuilder) PhoneNumber(phoneNumber string) *MessageBuilder

PhoneNumber sets the phone number to whom the message will be sent.

func (*MessageBuilder) TargetArn

func (b *MessageBuilder) TargetArn(targetArn string) *MessageBuilder

TargetArn sets the target ARN where the message will be sent.

func (*MessageBuilder) TopicArn

func (b *MessageBuilder) TopicArn(topicArn string) *MessageBuilder

TopicArn sets the topic ARN where the message will be sent.

func (*MessageBuilder) WithBinaryAttribute

func (b *MessageBuilder) WithBinaryAttribute(name string, value []byte) *MessageBuilder

WithBinaryAttribute attaches a binary attribute to the message.

func (*MessageBuilder) WithNumberAttribute

func (b *MessageBuilder) WithNumberAttribute(name string, value string) *MessageBuilder

WithNumberAttribute attaches a number attribute to the message, formatted as a string.

func (*MessageBuilder) WithStringArrayAttribute

func (b *MessageBuilder) WithStringArrayAttribute(name string, values []interface{}) *MessageBuilder

WithStringArrayAttribute attaches an array of strings attribute to the message.

The accepted values types are string, number, boolean and nil. Any other type will throw an error.

func (*MessageBuilder) WithStringAttribute

func (b *MessageBuilder) WithStringAttribute(name string, value string) *MessageBuilder

WithStringAttribute attaches a string attribute to the message.

func (*MessageBuilder) WithSubject

func (b *MessageBuilder) WithSubject(subject string) *MessageBuilder

WithSubject attaches a subject to the message.

type Publisher

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

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

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

api := sns.New(sess)

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

// Create a message
msg, err := NewMessageBuilder().
	Message("my message").
	TopicArn("arn:aws:sns:eu-west-1:123456789012:MyTopic").
	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 snsiface.SNSAPI) (*TracedPublisher, error)

NewPublisher creates a new SNS publisher.

Deprecated: The SNS client package is superseded by the `github.com/beatlabs/client/sns/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 SNS. It also stores tracing information.

Directories

Path Synopsis
Package v2 provides a wrapper for publishing messages to AWS SNS.
Package v2 provides a wrapper for publishing messages to AWS SNS.

Jump to

Keyboard shortcuts

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