go/sqs/README.md
These examples demonstrate how to perform various Amazon SQS operations. For information about Amazon SQS, see the Amazon Simple Queue Service Developer Guide.
You must have an AWS account and have your default credentials and AWS Region configured as described in Configuring the AWS SDK for Go in the AWS SDK for Go Developer Guide.
The unit tests should delete any resources that they create. However, they might result in charges to your AWS account.
To run a unit test, enter the following:
go test
You should see something like the following, where PATH is the path to folder containing the Go files.
PASS
ok PATH 1.904s
If you want to see any log messages, enter:
go test -test.v
You should see some additional log messages. The last two lines should be similar to the previous shown output.
All of the code examples perform the operations in your default AWS Region and use your default credentials. See Configuring the AWS SDK for Go for details.
Each example is in its own directory, with a unit test. Each example can be run on the command line, and most require at least one command-line argument. To see the required command-line arguments, enter the following, where FILENAME is the name of the Go file.
go run FILENAME
The example displays an error message with information about the required command-line arguments.
This directory contains an example of changing the visibility of a message, which prevents other consumers from processing the message. For information about message visibility, see Amazon SQS Visibility Timeout.
Use the following command to set the visibility of a message, where:
go run ChangeMsgVisibility.go -q QUEUE -h MESSAGE-HANDLE [-v VISIBILITY]
The unit test accepts the following configuration values in config.json and stores them in a struct:
The unit test:
This directory contains an example of configuring a queue to use long polling, where the queue waits for a message to arrive. For information about long polling, see Amazon SQS Short and Long Polling.
Use the following command to set the long polling value for a queue, where:
go run ConfigureLPQueue.go -q QUEUE [-d WAIT-TIME]
The unit test accepts the following configuration values in config.json and stores them in a struct:
The unit test:
This directory contains an example of creating a queue using long polling, where the queue waits for a message to arrive. For information about long polling, see Amazon SQS Short and Long Polling.
Use the following command to create a queue using long polling, where:
go run CreateLPQueue.go -q QUEUE [-d WAIT-TIME]
The unit test accepts the following configuration values in config.json and stores them in a struct:
The unit test:
This directory contains an example of creating a queue. For information about creating queues, see Tutorials: Creating Amazon SQS Queues.
Use the following command to create a queue, where:
go run CreateQueue.go -q QUEUE
The unit test accepts the following configuration value in config.json and stores it in a struct:
The unit test:
This directory contains an example of configuring an Amazon SQS queue for messages that could not be delivered to another queue. For information about dead-letter queues, see Tutorial: Configuring an Amazon SQS Dead-Letter Queue.
Use the following command to create a dead-letter queue, where:
go run DeadLetterQueue.go -q QUEUE -d DLQUEUE
The unit test accepts the following configuration values in config.json and stores them in a struct:
The unit test:
This directory contains an example of deleting a message from a queue. For information about deleting messages, see Tutorial: Receiving and Deleting a Message from an Amazon SQS Queue.
Use the following command to delete a message from a queue, where:
go run DeleteMessage.go -q QUEUE -m MESSAGE-HANDLE
The unit test accepts the following configuration values in config.json and stores them in a struct:
The unit test:
This directory contains an example of deleting a queue. For information about deleting queues, see Tutorial: Deleting an Amazon SQS Queue.
Use the following command to delete a queue, where:
go run DeleteQueue.go -q QUEUE
The unit test accepts the following configuration values in config.json and stores them in a struct:
The unit test:
This directory contains an example of retrieving the URL of a queue.
Use the following command to retrieve the URL of a queue, where:
go run GetQueueURL.go -q QUEUE
The unit test accepts the following configuration values in config.json and stores them in a struct:
The unit test:
This directory contains an example of listing queues.
Use the following command to list your queues.
go run ListQueues.go
The unit test accepts the following configuration values in config.json and stores them in a struct:
NOTE: If you set Confirm to true, the unit test sleeps SleepSeconds before listing the queues, which adds a considerable amount of time to running the unit test.
The unit test:
This directory contains an example of receiving a message in a long polling queue. For information about long polling, see Amazon SQS Short and Long Polling.
Use the following command to get a message from a long polling queue, where:
go run ReceiveLPMessage.go -q QUEUE [-v VISIBILITY] [-w WAIT-TIME]
The unit test accepts the following configuration values in config.json and stores them in a struct:
The unit test:
This directory contains an example of receiving a message from a queue.
Use the following command to receive a message from a queue, where:
go run ReceiveMessage.go -q QUEUE [-t VISIBILITY]
The unit test accepts the following configuration values in config.json and stores them in a struct:
The unit test:
This directory contains an example of sending a message to a queue.
Use the following command to send a message to a queue, where:
go run SendMessage.go -q QUEUE
The unit test accepts the following configuration values in config.json and stores them in a struct:
The unit test:
This directory contains an example of sending a message to and receiving a message in a long polling queue.
Use the following command to send a message to and receive a message in a long polling queue. where:
go run SendReceiveLongPolling.go -q QUEUE
The unit test accepts the following configuration values in config.json and stores them in a struct:
The unit test: