HowTo: Send and receive messages from SQS

Official Content
This documentation is valid for:

This article contains an example that shows how to send and consume messages from a Message queue with the Queue API, using AWS SQS.


The code consists of the following:

1. Connect to the AWS SQS using the AWSQueue.MessageQueueProvider external object.
2. It returns a MessageQueue EO which should be used to send the message to the Queue.
3. The result is returned in a variable of type MessageResult SDT.

Next, create a GeneXus object and define the following:

To connect

&queueURL = !""
&accessKey = !"xxxxxxxxxxxxxxxx"
&secretKey = !"xxxxxxxxxxxxxxxxxxxxxxxx"
&region = !"us-east-1"

&AWSBasicCredentials.AccessKey = &accessKey //AWSBasicCredentials SDT is under AWSCore module
&AWSBasicCredentials.SecretKey = &secretKey
&AWSBasicCredentials.Region = &region

&MessageQueue = AWSQueue.MessageQueueProvider.Connect(&AWSBasicCredentials,&queueURL,&errorMessages,&isOK) //GeneXusMessagingQueue.SimpleQueue.MessageQueue

To Send Messages 

&Message = new()
&Message.MessageId = GUID.NewGuid().ToString().Trim()
&Message.MessageBody = !"test1 send one message"

&MessageProperty = new() //GeneXusMessagingQueue.SimpleQueue.MessageProperty
&MessageProperty.PropertyKey = !"key1"
&MessageProperty.PropertyValue = !"Value1"

&MessageProperty = new()
&MessageProperty.PropertyKey = !"key2"
&MessageProperty.PropertyValue = !"Value2"


&MessageOptions.MaxNumberOfMessages = 10 //GeneXusMessagingQueue.SimpleQueue.MessageOptions

&MessageResultCollection = &MessageQueue.SendMessages(&Messages,&MessageOptions,&errorMessages,&success) //GeneXusMessagingQueue.SimpleQueue.MessageResult Collection

To Receive Messages

&MessageCollection = &MessageQueue.ReceiveMessages(&errorMessages,&success) //GeneXusMessagingQueue.SimpleQueue.Message Collection
//Process &MessageCollection