Attention: this is a legacy library and thus not supported by Toradex anymore. We recommend that you use the new libraries for all Toradex modules. Please see the Toradex CE Libraries and Code Samples for up-to-date information.
Amazon SQS works by exposing Amazon’s web-scale messaging infrastructure as a web service. Any computer on the Internet can add or read messages without any additional software installation or special firewall configurations. The components of applications using Amazon SQS can run independently. They do not need to be on the same network, developed with the same technologies, or running at the same time. A queue can be created in 8 regions – US East (Northern Virginia), US West (Oregon), US West (Northern California), EU (Ireland), Asia Pacific (Singapore), Asia Pacific (Tokyo), Asia Pacific (Sydney), and South America (Sao Paulo). The message body can contain up to 64 KB of text in any format. Messages can be sent, received or deleted and can be retained in a queue for up to 14 days. They can also be sent and read simultaneously.
For more information, please refer to: http://aws.amazon.com/sqs/
Notes:
Before calling any other function, you should call SqsOpenQueue() with all the parameter inputs: AWS Access Id, AWS Secret Key, AWS Owner ID, AWS SqS Region / Path and queueName as detailed below: * It will return TRUE if successful or FALSE if the call fails. Use GetLastError() to get extended error details.
“SendQueue” is the name of the queue. You can choose any name.
if (!SqsOpenQueue(AWS_ACCOUNT_ACCESS_ID, AWS_ACCOUNT_SECRET_KEY, AWS_SQS_SINGAPORE_REGION, AWS_ACCOUNT_OWNER_ID, queueName, &SendQueue)) { printf("SqsOpenQueue Fails: Error Code: "); printf("%d\n", GetLastError()); }SendQueue handle will be used by all other function calls as a parameter input hereafter.
The SqsCreateQueue() function is used to create a queue in a region.
if (!SqsCreateQueue(SendQueue)) { printf("SqsCreateQueue Fails: Error Code: "); printf("%d\n", GetLastError()); } else { printf("SqsCreateQueue Success\n"); }
The SqsDeleteQueue() function is used to delete a queue in a region.
if (!SqsDeleteQueue(SendQueue)) { printf("SqsDeleteQueue Fails: Error Code: "); printf("%d\n", GetLastError()); } else { printf("SqsDeleteQueue Success\n"); }
The SqsGetQueueUrl() function is used to get URL of a queue in a region.
char queueUrlData[1024] = {0}; memset(queueUrlData, 0, 1024); if (!SqsGetQueueUrl(SendQueue, queueUrlData, 255)) { printf("SqsGetQueueUrl Fails: Error Code: "); printf("%d\n", GetLastError()); } else { printf("SqsGetQueueUrl Success\n"); printf("> %s\n", queueUrlData); }
The SqsGetQueueUrl() function is used to get the URL of a queue in a region.
if (!SqsListQueues(SendQueue, "", "\\queueList.xml")) { printf("SqsListQueues Fails: Error Code: "); printf("%d\n", GetLastError()); } else { printf("SqsListQueues Success\n"); }
The SqsFindQueue() function is used to get queue details, one by one, from the local file.
char queueListData[1024] = {0}; DWORD listQueueNextPointer = 0; memset(queueListData, 0, 1024 if (SqsFindQueue("\\queueList.xml", queueListData, 1024, &listQueueNextPointer, listFilesize)) { printf("> %s\n", queueListData); }
To find the next queue call SqsFindQueue() again, this time don’t set listQueueNextPointer as 0
memset(queueListData, 0, 1024 if (SqsFindQueue("\\queueList.xml", queueListData, 1024, &listQueueNextPointer, listFilesize)) { printf("> %s\n", queueListData); }
The SqsSendMessage() function is used to send a message to a queue.
char sendMessageID[100 + 1] = {0}; // 100 is the max string length of the message ID. memset(sendMessageID, 0, 100 + 1); if (!SqsSendMessage(SendQueue, "Hello, Message from Toradex Colibri.", 0, sendMessageID, 100 + 1)) // No Delay in delivery { printf("SqsSendMessage Fails: Error Code: "); printf("%d\n", GetLastError()); } else { printf("SqsSendMessage Success, "); printf("MessageID: %s\n", sendMessageID); }
The SqsReceiveMessage() function is used to receive a message from a queue.
char receiveMessageBody[4096 + 1] = {0}; // to receive 4KB message only char receiveMessageID[100 + 1] = {0}; char recieptHandle[1024 + 1] ={0}; //max size of the reciept handle is 1024 memset(receiveMessageBody, 0, 4096 + 1); memset(receiveMessageID, 0, 100 + 1); memset(recieptHandle, 0, 1024 + 1); if (!SqsReceiveMessage(SendQueue, "ALL", 10, 30, receiveMessageBody, receiveMessageID, receiptHandle)) { printf("SqsReceiveMessage Fails: Error Code: "); printf("%d\n", GetLastError()); } else { printf("SqsReceiveMessage Success\n"); printf("MessageID:%s\n", receiveMessageID); printf("Received Message: %s\n", receiveMessageBody); printf("RecieptHandle: %s\n", recieptHandle); }
The SqsDeleteMessage() function is used to delete a message from a queue.
if (!SqsDeleteMessage(SendQueue, recieptHandle)) { printf("SnsDeleteMessage Fails: Error Code: "); printf("%d\n", GetLastError()); } else { printf("SnsDeleteMessage Success\n"); }
The SqsChangeMessageVisibility() function is used to change message visibility.
if (!SqsChangeMessageVisibility(SendQueue, receiptHandle, 90)) // New Timeout setting { printf("SnsChangeMessageVisibility Fails: Error Code: "); printf("%d\n", GetLastError()); } else { printf("SnsChangeMessageVisibility Success\n"); }
The SqsGetQueueAttributes() function is used to get queue attributes.
char queueAttributesData[1024] = {0}; memset(queueAttributesData, 0, 1024); if (!SqsGetQueueAttributes(SendQueue, queueAttributesData, 1024)) { printf("SqsGetQueueAttributes Fails: Error Code: "); printf("%d\n", GetLastError()); } else { printf("SqsGetQueueAttributes Success\n"); printf("> %s\n", queueAttributesData); }
The SqsSetQueueAttributes() function is used to set queue attributes.
* #define QUEUE_ATTRIBUTE_VISIBILITY_TIMEOUT 1 * #define QUEUE_ATTRIBUTE_MAXIMUM_MESSAGE_SIZE 2 * #define QUEUE_ATTRIBUTE_MESSAGE_RETENTION_PERIOD 3 * #define QUEUE_ATTRIBUTE_DELAY_SECONDS 4
if (!SqsSetQueueAttributes(SendQueue, QUEUE_ATTRIBUTE_VISIBILITY_TIMEOUT, 35)) { printf("SqsSetQueueAttributes Fails: Error Code: "); printf("%d\n", GetLastError()); } else { printf("SqsSetQueueAttributes Success\n"); }
The SqsCloseQueue() function is used to close queue handle opened by the SqsOpenQueue().
if (!SqsCloseQueue(&SendQueue)) { printf("SqsCloseQueue Fails: Error Code: "); printf("%d\n", GetLastError()); } else { printf("SqsCloseQueue Success\n"); }