Skip to content
This repository has been archived by the owner on Jun 15, 2023. It is now read-only.

Latest commit

 

History

History
81 lines (52 loc) · 2.8 KB

sqs-example-managing-visibility-timeout.rst

File metadata and controls

81 lines (52 loc) · 2.8 KB

Managing Visibility Timeout in Queues

This example shows you how to:

  • Change visibility timeout with queues

You can download complete versions of these example files from the aws-doc-sdk-examples <sqs> repository on GitHub.

Scenario

This example manages visibility timeout with queues. It uses these methods of the client class:

  • CreateQueue <service/sqs/#SQS.CreateQueue>
  • ListQueues <service/sqs/#SQS.ListQueues>
  • GetQueueUrl <service/sqs/#SQS.GetQueueUrl>
  • DeleteQueue <service/sqs/#SQS.DeleteQueue>

Prerequisites

  • You have set up <setting-up> and configured <configuring-sdk> the .
  • You are familiar with using visibility timeout. To learn more, see Visibility Timeout <sqs-visibility-timeout> in the .

Change the Visibility Timeout

Create a new Go file named sqs_changingvisibility.go.

You must import the relevant Go and packages by adding the following lines.

example_code/sqs/sqs_changingvisibility.go

Initialize a session that the SDK will use to load credentials from the shared credentials file, ~/.aws/credentials.

example_code/sqs/sqs_changingvisibility.go

Get a message from the queue. Call ReceiveMessage. Pass in the URL of the queue to return details of the next message in the queue. Print any errors, or a message if no message was received.

example_code/sqs/sqs_changingvisibility.go

If a message was returned, use its receipt handle to set the timeout to 30 seconds.

example_code/sqs/sqs_changingvisibility.go