aws-go-sqs: github.com/nabeken/aws-go-sqs/queue Index | Examples | Files | Directories

package queue

import "github.com/nabeken/aws-go-sqs/queue"

Package queue provides SQS queue manipulations on the top of stripe/aws-go.

Index

Examples

Package Files

doc.go queue.go

func BuildBatchRequestEntry Uses

func BuildBatchRequestEntry(messages ...BatchMessage) ([]*sqs.SendMessageBatchRequestEntry, map[string]int)

BuildBatchRequestEntry builds batch entries and id2index map.

func GetQueueURL Uses

func GetQueueURL(s sqsiface.SQSAPI, name string) (*string, error)

GetQueueURL returns a URL for the given queue name.

func IsBatchError Uses

func IsBatchError(err error) (errors []*BatchError, ok bool)

IsBatchError checks that err contains BatchError. If err contains BatchError, it returns []*BatchError, true. If not, it returns nil, false.

func NewBatchError Uses

func NewBatchError(id2index map[string]int, errors []*sqs.BatchResultErrorEntry) error

NewBatchError composes an error from errors if available.

type BatchChangeMessageVisibility Uses

type BatchChangeMessageVisibility struct {
    ReceiptHandle     *string
    VisibilityTimeout int64
}

A BatchChangeMessageVisibility represents each request to change a visibility timeout.

type BatchError Uses

type BatchError struct {
    Index       int
    Code        string
    Message     string
    SenderFault bool
}

A BatchError represents an error for batch operations such as SendMessageBatch and ChangeMessageVisibilityBatch. Index can be used to identify a message causing the error. See SendMessageBatch how to handle an error in batch operation.

func (*BatchError) Error Uses

func (e *BatchError) Error() string

type BatchMessage Uses

type BatchMessage struct {
    Body    string
    Options []option.SendMessageInput
}

A BatchMessage represents each request to send a message. Options are used to change parameters for the message.

type Queue Uses

type Queue struct {
    SQS sqsiface.SQSAPI
    URL *string
}

A Queue is an SQS queue which holds queue url in URL. Queue allows you to call actions without queue url for every call.

func New Uses

func New(s sqsiface.SQSAPI, name string) (*Queue, error)

New initializes Queue with queue name name.

func (*Queue) ChangeMessageVisibility Uses

func (q *Queue) ChangeMessageVisibility(receiptHandle *string, visibilityTimeout int64) error

ChangeMessageVisibility changes a message visibiliy timeout.

func (*Queue) ChangeMessageVisibilityBatch Uses

func (q *Queue) ChangeMessageVisibilityBatch(opts ...BatchChangeMessageVisibility) error

ChangeMessageVisibilityBatch changes a visibility timeout for each message in opts.

func (*Queue) DeleteMessage Uses

func (q *Queue) DeleteMessage(receiptHandle *string) error

DeleteMessage deletes a message from SQS queue.

func (*Queue) DeleteMessageBatch Uses

func (q *Queue) DeleteMessageBatch(receiptHandles ...*string) error

DeleteMessageBatch deletes messages from SQS queue.

func (*Queue) DeleteQueue Uses

func (q *Queue) DeleteQueue() error

DeleteQueue deletes a queue in SQS.

func (*Queue) PurgeQueue Uses

func (q *Queue) PurgeQueue() error

PurgeQueue purges messages in SQS queue. It deletes all messages in SQS queue.

func (*Queue) ReceiveMessage Uses

func (q *Queue) ReceiveMessage(opts ...option.ReceiveMessageInput) ([]*sqs.Message, error)

ReceiveMessage receives messages from SQS queue. opts are used to change parameters for a request.

func (*Queue) SendMessage Uses

func (q *Queue) SendMessage(body string, opts ...option.SendMessageInput) (*sqs.SendMessageOutput, error)

SendMessage sends a message to SQS queue. opts are used to change parameters for a message.

Code:

// Create SQS instance
s := sqs.New(session.New())

// Create Queue instance
q, err := queue.New(s, "example-queue-name")
if err != nil {
    log.Fatal(err)
}

// MessageAttributes
attrs := map[string]interface{}{
    "ATTR1": "STRING!!",
    "ATTR2": 12345,
}

if _, err := q.SendMessage("MESSAGE BODY", option.MessageAttributes(attrs)); err != nil {
    log.Fatal(err)
}

log.Print("successed!")

func (*Queue) SendMessageBatch Uses

func (q *Queue) SendMessageBatch(messages ...BatchMessage) error

SendMessageBatch sends messages to SQS queue.

Code:

// Create SQS instance
s := sqs.New(session.New())

// Create Queue instance
q, err := queue.New(s, "example-queue-name")
if err != nil {
    log.Fatal(err)
}

// MessageAttributes
attrs := map[string]interface{}{
    "ATTR1": "STRING!!",
}

// Create messages for batch operation
batchMessages := []queue.BatchMessage{
    queue.BatchMessage{
        Body: "success",
    },
    queue.BatchMessage{
        Body:    "failed",
        Options: []option.SendMessageInput{option.MessageAttributes(attrs)},
    },
}

err = q.SendMessageBatch(batchMessages...)
if err != nil {
    batchErrors, ok := queue.IsBatchError(err)
    if !ok {
        log.Fatal(err)
    }
    for _, e := range batchErrors {
        if e.SenderFault {
            // Continue if the failure is on the client side.
            log.Print(e)
            continue
        }
        // Retry if the failure is on the server side
        // You can use e.Index to identify the message
        // failedMessage := batchMessages[e.Index]
    }
}

Directories

PathSynopsis
optionPackage option provides adapters to change a parameter in SQS request.

Package queue imports 6 packages (graph). Updated 2017-06-01. Refresh now. Tools for package owners.