Example #1
0
func ExampleSQS_ReceiveMessage() {
	svc := sqs.New(nil)

	params := &sqs.ReceiveMessageInput{
		QueueURL: aws.String("String"), // Required
		AttributeNames: []*string{
			aws.String("QueueAttributeName"), // Required
			// More values...
		},
		MaxNumberOfMessages: aws.Long(1),
		MessageAttributeNames: []*string{
			aws.String("MessageAttributeName"), // Required
			// More values...
		},
		VisibilityTimeout: aws.Long(1),
		WaitTimeSeconds:   aws.Long(1),
	}
	resp, err := svc.ReceiveMessage(params)

	if awserr := aws.Error(err); awserr != nil {
		// A service error occurred.
		fmt.Println("Error:", awserr.Code, awserr.Message)
	} else if err != nil {
		// A non-service error occurred.
		panic(err)
	}

	// Pretty-print the response data.
	fmt.Println(awsutil.StringValue(resp))
}
Example #2
0
func ExampleSQS_ChangeMessageVisibilityBatch() {
	svc := sqs.New(nil)

	params := &sqs.ChangeMessageVisibilityBatchInput{
		Entries: []*sqs.ChangeMessageVisibilityBatchRequestEntry{ // Required
			&sqs.ChangeMessageVisibilityBatchRequestEntry{ // Required
				ID:                aws.String("String"), // Required
				ReceiptHandle:     aws.String("String"), // Required
				VisibilityTimeout: aws.Long(1),
			},
			// More values...
		},
		QueueURL: aws.String("String"), // Required
	}
	resp, err := svc.ChangeMessageVisibilityBatch(params)

	if awserr := aws.Error(err); awserr != nil {
		// A service error occurred.
		fmt.Println("Error:", awserr.Code, awserr.Message)
	} else if err != nil {
		// A non-service error occurred.
		panic(err)
	}

	// Pretty-print the response data.
	fmt.Println(awsutil.StringValue(resp))
}
Example #3
0
func ExampleSQS_AddPermission() {
	svc := sqs.New(nil)

	params := &sqs.AddPermissionInput{
		AWSAccountIDs: []*string{ // Required
			aws.String("String"), // Required
			// More values...
		},
		Actions: []*string{ // Required
			aws.String("String"), // Required
			// More values...
		},
		Label:    aws.String("String"), // Required
		QueueURL: aws.String("String"), // Required
	}
	resp, err := svc.AddPermission(params)

	if awserr := aws.Error(err); awserr != nil {
		// A service error occurred.
		fmt.Println("Error:", awserr.Code, awserr.Message)
	} else if err != nil {
		// A non-service error occurred.
		panic(err)
	}

	// Pretty-print the response data.
	fmt.Println(awsutil.StringValue(resp))
}
Example #4
0
func TestFlattenedTraits(t *testing.T) {
	s := sqs.New(nil)
	_, err := s.DeleteMessageBatch(&sqs.DeleteMessageBatchInput{
		QueueURL: aws.String("QUEUE"),
		Entries: []*sqs.DeleteMessageBatchRequestEntry{
			&sqs.DeleteMessageBatchRequestEntry{
				ID:            aws.String("TEST"),
				ReceiptHandle: aws.String("RECEIPT"),
			},
		},
	})

	assert.Error(t, err)
	assert.EqualError(t, err, "The address QUEUE is not valid for this endpoint.")
}
Example #5
0
func ExampleSQS_SendMessageBatch() {
	svc := sqs.New(nil)

	params := &sqs.SendMessageBatchInput{
		Entries: []*sqs.SendMessageBatchRequestEntry{ // Required
			&sqs.SendMessageBatchRequestEntry{ // Required
				ID:           aws.String("String"), // Required
				MessageBody:  aws.String("String"), // Required
				DelaySeconds: aws.Long(1),
				MessageAttributes: &map[string]*sqs.MessageAttributeValue{
					"Key": &sqs.MessageAttributeValue{ // Required
						DataType: aws.String("String"), // Required
						BinaryListValues: [][]byte{
							[]byte("PAYLOAD"), // Required
							// More values...
						},
						BinaryValue: []byte("PAYLOAD"),
						StringListValues: []*string{
							aws.String("String"), // Required
							// More values...
						},
						StringValue: aws.String("String"),
					},
					// More values...
				},
			},
			// More values...
		},
		QueueURL: aws.String("String"), // Required
	}
	resp, err := svc.SendMessageBatch(params)

	if awserr := aws.Error(err); awserr != nil {
		// A service error occurred.
		fmt.Println("Error:", awserr.Code, awserr.Message)
	} else if err != nil {
		// A non-service error occurred.
		panic(err)
	}

	// Pretty-print the response data.
	fmt.Println(awsutil.StringValue(resp))
}
Example #6
0
func ExampleSQS_PurgeQueue() {
	svc := sqs.New(nil)

	params := &sqs.PurgeQueueInput{
		QueueURL: aws.String("String"), // Required
	}
	resp, err := svc.PurgeQueue(params)

	if awserr := aws.Error(err); awserr != nil {
		// A service error occurred.
		fmt.Println("Error:", awserr.Code, awserr.Message)
	} else if err != nil {
		// A non-service error occurred.
		panic(err)
	}

	// Pretty-print the response data.
	fmt.Println(awsutil.StringValue(resp))
}
Example #7
0
func ExampleSQS_ListQueues() {
	svc := sqs.New(nil)

	params := &sqs.ListQueuesInput{
		QueueNamePrefix: aws.String("String"),
	}
	resp, err := svc.ListQueues(params)

	if awserr := aws.Error(err); awserr != nil {
		// A service error occurred.
		fmt.Println("Error:", awserr.Code, awserr.Message)
	} else if err != nil {
		// A non-service error occurred.
		panic(err)
	}

	// Pretty-print the response data.
	fmt.Println(awsutil.StringValue(resp))
}
Example #8
0
func TestSendMessageChecksumInvalidNoValidation(t *testing.T) {
	s := sqs.New(&aws.Config{
		Region:                  "mock-region",
		Credentials:             aws.DetectCreds("AKID", "SECRET", ""),
		DisableParamValidation:  true,
		DisableComputeChecksums: true,
	})
	s.Handlers.Send.Clear()

	req, _ := s.SendMessageRequest(&sqs.SendMessageInput{
		MessageBody: aws.String("test"),
	})
	req.Handlers.Send.PushBack(func(r *aws.Request) {
		body := ioutil.NopCloser(bytes.NewReader([]byte("")))
		r.HTTPResponse = &http.Response{StatusCode: 200, Body: body}
		r.Data = &sqs.SendMessageOutput{
			MD5OfMessageBody: aws.String("000"),
			MessageID:        aws.String("12345"),
		}
	})
	err := req.Send()
	assert.NoError(t, err)
}
Example #9
0
func ExampleSQS_CreateQueue() {
	svc := sqs.New(nil)

	params := &sqs.CreateQueueInput{
		QueueName: aws.String("String"), // Required
		Attributes: &map[string]*string{
			"Key": aws.String("String"), // Required
			// More values...
		},
	}
	resp, err := svc.CreateQueue(params)

	if awserr := aws.Error(err); awserr != nil {
		// A service error occurred.
		fmt.Println("Error:", awserr.Code, awserr.Message)
	} else if err != nil {
		// A non-service error occurred.
		panic(err)
	}

	// Pretty-print the response data.
	fmt.Println(awsutil.StringValue(resp))
}
Example #10
0
import (
	"bytes"
	"io/ioutil"
	"net/http"
	"testing"

	"github.com/datacratic/aws-sdk-go/aws"
	"github.com/datacratic/aws-sdk-go/service/sqs"
	"github.com/stretchr/testify/assert"
)

var svc = func() *sqs.SQS {
	s := sqs.New(&aws.Config{
		Region:                 "mock-region",
		Credentials:            aws.DetectCreds("AKID", "SECRET", ""),
		DisableParamValidation: true,
	})
	s.Handlers.Send.Clear()
	return s
}()

func TestSendMessageChecksum(t *testing.T) {
	req, _ := svc.SendMessageRequest(&sqs.SendMessageInput{
		MessageBody: aws.String("test"),
	})
	req.Handlers.Send.PushBack(func(r *aws.Request) {
		body := ioutil.NopCloser(bytes.NewReader([]byte("")))
		r.HTTPResponse = &http.Response{StatusCode: 200, Body: body}
		r.Data = &sqs.SendMessageOutput{
			MD5OfMessageBody: aws.String("098f6bcd4621d373cade4e832627b4f6"),