Whatever message this page gives is out now! Go check it out!
sqsObject= getCloudService("sqsCred", "sqsConf")component
{
this.name="AWS_STD_Queue";
void function onApplicationStart(){
application.awsCred = {
"alias" : "aws_std_queue",
"vendorName" : "AWS",
"region" : "us-east-1",
"secretAccessKey" : "xxxxxxxxxxxxxxxxx",
"accessKeyId" : "xxxxxxxxxxxxxxxx"
}
application.snsConf = {
"serviceName" : "SNS"
}
application.sqsConf ={
"serviceName" : "SQS"
}
}
}sqsObject = getCloudService(application.awsCred, application.sqsConf)<cfscript>
// define the credential and the configuration aliases in the ColdFusion Admin
sqs=getCloudService("awsCred","sqsConf")
// code below.
...........
</cfscript><cfscript>
// Using credential alias and struct for service config
sqsConf = {
"alias":"sqsConf",
"serviceName" : "SQS",
"clientOverrideConfig":{
"retryPolicy":{
"numRetries":4
}
},
"httpClientConfig":{
"maxConnections":50
}
}
sqs= getCloudService("sqsCred", sqsConf)
// code below
.....................
</cfscript><cfscript>
// Using config alias and struct for service credentials
// sqs credentials
sqsCreds={
"vendorName":"AWS",
"alias": "sqsCred",
"region":"us-east-2",
"accessKeyId": "access key",
"secretAccessKey": "secret access"
}
sqs= getCloudService(sqsCreds, "sqsConf")
// code below
.....................................
</cfscript><cfscript>
// Using Structs for both cloud credential and config
sqsCred={
"vendorName":"AWS",
"alias": "sqs_cred_alias",
"region":"us-east-2",
"accessKeyId": "access key",
"secretAccessKey": "secret access key"
}
sqsConf = {
"alias":"sqs_conf_alias",
"serviceName" : "SQS",
"clientOverrideConfig":{
"retryPolicy":{
"numRetries":4
}
},
"httpClientConfig":{
"maxConnections":50
}
}
sqs = getCloudService(sqsCred, sqsConf )
// code below
...................................................................
</cfscript><cfscript>
// Create an object of administrator component and call the login method
adminObj = createObject("component","cfide.adminapi.administrator")
adminObj.login("admin")
// Create an object of cloud component
cloudObj = createObject("component","cfide.adminapi.cloud")
// define credentials struct
credentialStruct={
"alias" : "CredSQS",
"vendorName" : "AWS",
"region" : "us-east-2",
"secretAccessKey" : "secret access key",
"accessKeyId" : "access key"
}
// add credential credentialStruct
try{
cloudObj.addCredential(credentialStruct)
writeOutput("Credentials added successfully")
}
catch(any e){
writeDump(e)
}
</cfscript><cfscript>
// Create an object of administrator component and call the login method
adminObj = createObject("component","cfide.adminapi.administrator")
adminObj.login("admin")
// Create an object of cloud component
cloudObj = createObject("component","cfide.adminapi.cloud")
// define configuration struct
configStruct={
"alias":"ConfSQS",
"serviceName":"SQS",
"clientOverrideConfig":{
"retryPolicy":{
"numRetries":4
}
},
"httpClientConfig":{
"maxConnections":50
}
}
// add config configStruct
try{
cloudObj.addServiceConfig(configStruct)
writeOutput("Configuration service added successfully")
}
catch(any e){
writeDump(e)
}
</cfscript>createQueue(String queueName, Struct queueAttributes)Parameter | Description | Type | Required |
queueName | Name of the queue. If you want to create a FIFO queue, the queue name must end with the .fifo suffix. Queue names are case-sensitive. | String | Yes |
queueAttributes | Struct of strings containing the following attributes:
Server Side Encryption-related attributes:
FIFO-related attributes:
Note: You cannot change the queue from Standard to FIFO queue and vice-versa. | Struct | No |
<cfscript>
cred={
"credentialAlias" : "alias",
"vendorName" : "AWS",
"region" : "us-east-2",
"secretAccessKey" : "secret access",
"accessKeyId" : "access key"
}
conf={
"serviceName"="SQS"
}
sqs=getCloudService(cred, conf)
queueName="QueueOne"
// standard queue
myQueue=sqs.createQueue(queueName)
try{
myQueue=sqs.createQueue(queueName)
writeOutput("Standard queue created")
}
catch (any e){
writeDump(e)
}
</cfscript><cfscript>
sqs = getCloudService(application.awsCred, application.sqsConf)
queueName="MyQueue"
// Creates a new standard
setQueueAttributesMetadata = {
"attributes"={
"VisibilityTimeout"="10",
"MessageRetentionPeriod"="100",
"MaximumMessageSize"="1024",
"DelaySeconds"="10",
"ReceiveMessageWaitTimeSeconds"="20"
}
}
// standard queue
try{
myQueue=sqs.createQueue(queueName,setQueueAttributesMetadata)
writeOutput("Queue with attributes created")
}
catch (any e){
writeDump(e)
}
</cfscript><cfscript>
sqs = getCloudService(application.awsCred, application.sqsConf)
queueName="MyQueue.fifo" // A FIFO queue name must end with the .fifo suffix
// Creates FIFO queue
setQueueAttributesMetadata = {
"attributes"={
"FifoQueue":"true", // This attribute must be True for a FIFO queue
"VisibilityTimeout"="10",
"MessageRetentionPeriod"="100",
"MaximumMessageSize"="1024",
"DelaySeconds"="10",
"ReceiveMessageWaitTimeSeconds"="20"
}
}
// FIFO queue
try{
myQueue=sqs.createQueue(queueName,setQueueAttributesMetadata)
writeOutput("FIFO queue with attributes created")
}
catch (any e){
writeDump(e)
}
</cfscript><cfscript>
sqs = getCloudService(application.awsCred, application.sqsConf);
//Use the sqs service object to create a queue using createQueue(). This method returns a queue object.
myQueue = sqs.createQueue("QueueWithSSE");
setQueueAttributesMetadata = {
"attributes"={
"KmsMasterKeyId"="arn:aws:kms:us-east-2:xxxxxxxxxxx:key/xxxxxxxxxxxx",
"KmsDataKeyReusePeriodSeconds"="120"
}
};
setQueueAttributesResponse = myQueue.setAttributes(setQueueAttributesMetadata);
KmsMasterKeyIdVal = myQueue.getAttributes({
"attributeNames"=["KmsMasterKeyId"]
})
val = KmsMasterKeyIdVal["attributes"];
writeoutput(val["KmsMasterKeyId"]);
</cfscript>listQueues(queueNamePrefix)Parameter | Type | Required |
queueNamePrefix | String | No |
<cfscript>
// Create a queue in SQS
// Get the getCloudService from the credentials and configuration we declared in Application.cfc
sqs = getCloudService(application.awsCred, application.sqsConf);
// Use the sqs service object to create a queue using createQueue().
// This method returns a queue object.
writeoutput("Create queue in AWS</br>");
myQueue = sqs.createQueue("MyQueueWithAttrib")
writeoutput("Listing all the queues in AWS<br>")
writeDump(sqs.listQueues().queueUrls)
writeOutput("The number of queues in the region is:")
queueCount= ArrayLen(sqs.listQueues().queueUrls)
writeOutput(queueCount)
</cfscript>getQueueUrl(queueName)Parameter | Description | Type | Required |
queueName | The name of the queue whose URL you want to retrieve. | String | Yes |
<cfscript>
sqs=getCloudService(application.awsCred, application.sqsConf)
qURL=sqs.GetQueueUrl("BatchQueue")
writeDump(qURL)
</cfscript>getQueueArn(String queueUrl)Parameter | Description | Type | Required |
queueURL | The url of the queue. | String | Yes |
<cfscript>
sqs=getCloudService(application.awsCred, application.sqsConf)
stdQueueObj = sqs.createQueue("stdQueueARN");
queueARN = stdQueueObj.getQueueArn();
writeoutput(queueARN)
</cfscript>tagQueue(String queueUrl, Struct tags)Parameter | Description | Type | Required |
queueURL | The url of the queue which is to be tagged. | String | Yes |
map | The tags to be added to the queue. | Struct | Yes |
<cfscript>
sqs=getCloudService(application.awsCred, application.sqsConf)
// create a queue
myQueue=sqs.createQueue("QueueTags")
// get url of the queue
queueUrl=sqs.getQueueUrl("QueueTags")
writeOutput("The queue url is: " & queueUrl)
// create tags
queueTags={
"tags"={
"Product":"ColdFusion",
"Version":"2021",
"Build":"338001",
"Date":"2020/10/28",
"Location":"Adobe",
"Place":"Bangalore"
}
}
try{
queueTagResponse=sqs.tagQueue(queueUrl,queueTags)
writeOutput(""&"Queue successfully tagged")
writeDump(queueTagResponse)
}
catch(any e){
writeDump(e)
}
</cfscript><cfscript>
sqs=getCloudService(application.awsCred, application.sqsConf)
// create a queue
myQueue=sqs.createQueue("QueueTags")
// get url of the queue
queueUrl=sqs.getQueueUrl("QueueTags")
writeOutput("The queue url is: " & queueUrl)
// create tags
queueTags={
"tags"={
"Product":"ColdFusion",
"Version":"2021",
"Build":"338001",
"Date":"2020/10/28",
"Location":"Adobe",
"Place":"Bangalore"
}
}
try{
queueTagResponse=myQueue.tag(queueTags)
writeOutput(""&"Queue successfully tagged")
writeDump(queueTagResponse)
}
catch(any e){
writeDump(e)
}
</cfscript>listQueueTags(queueURL)Parameter | Description | Type | Required |
queueURL | The url of the queue. | String | Yes |
<cfscript>
sqs=getCloudService(application.awsCred, application.sqsConf)
// list queues
queueList=sqs.listQueues()
// get queue url of the queue created in the previous example
queueUrl=queueList.queueUrls[16]
tagList=sqs.listQueueTags(queueUrl)
writeOutput("List of tags in the queue:")
writeDump(tagList.tags)
</cfscript><cfscript>
sqs=getCloudService(application.awsCred, application.sqsConf)
// create a queue
myQueue=sqs.createQueue("QueueTags")
// add tags to the queue
queueTags={
"tags"={
"Product":"ColdFusion",
"Version":"2021",
"Build":"338001",
"Date":"2020/10/28",
"Location":"Adobe"
}
}
myQueue.tag(queueTags)
// list tags
listTagResponse=myQueue.listQueueTags()
writeDump(listTagResponse)
</cfscript>untagQueue(String queueUrl, Struct tags)Parameter | Description | Type | Required |
queueURL | The url of the queue. | String | Yes |
map | Array of tags to be removed from the specified queue. | Array | Yes |
<cfscript>
sqs = getCloudService(application.awsCred, application.sqsConf);
//writeoutput("Create queue in AWS<br>");
myQueue = sqs.createQueue("Tagging_Queue");
//writeoutput("set Tag queue attributes response");
tagQueueMetadata = {"tags"=
{
"Product"="ColdFusion",
"Environment"="Production"
}
};
// tag the queue
setQueueAttributesResponse = myQueue.tag(tagQueueMetadata);
writeoutput(#myQueue.ListQueueTags().tags["Product"]#);
writeoutput(#myQueue.ListQueueTags().tags["Environment"]#&"<br>");
untagQueueMetadata = {"tagKeys"=["Product","Environment"]};
// untag the queue
untagQueueResponse = myQueue.untag(untagQueueMetadata);
try{
writeoutput(#myQueue.ListQueueTags().tags["Environment"]#);
}
catch(any e){
writeoutput(e.Message);
}
</cfscript>deleteQueue(queueURL)Parameter | Description | Type | Required |
queueURL | The url of the queue. | String | Yes |
<cfscript>
// Get the getCloudService from the credentials and configuration we declared in Application.cfc
sqs = getCloudService(application.awsCred, application.sqsConf)
// Use the sqs service object to create a queue using createQueue(). This method returns a queue object.
myQueue=sqs.createQueue("QueueForDeletion");
// get queue Url
queueUrl=sqs.getQueueUrl("QueueForDeletion")
try{
sqs.deleteQueue(queueUrl)
writeOutput("Queue deleted successfully.")
}
catch(any e){
writeDump(e)
}
</cfscript>purgeQueue(queueURL)Parameter | Description | Type | Required |
queueURL | The url of the queue. | String | Yes |
<cfscript>
sqs = getCloudService(application.awsCred, application.sqsConf);
stdQueue = sqs.createQueue("PurgeMessageQueue");
stdQueueUrl = stdQueue.getQueueUrl();
sendMessageMetadata = {
"messageBody"="This is a sample message",
"messageAttributes"={
"timestamps"=dateTimeFormat(now()),
"geospatial_data"="San Francisco",
"signatures"="ADBE",
"identifiers"="ColdFusion"
}
}
// send message to the queue
sqs.sendMessage(stdQueueUrl,sendMessageMetadata)
try{
sqs.purgeQueue(stdQueueUrl)
writeOutput("Queue purged successfully.")
}
catch(any e){
writeDump(e)
}
</cfscript>sendMessage(String queueUrl, Struct message)Parameter | Description | Type | Required |
queueUrl | The URL of the queue to which a message is to be sent. | String | Yes |
messageAttributes | Key-value pair of SQS message attributes. For more information, see SQS Message Attributes. | Struct | No |
messageBody | The message to send to the queue. | String | Yes |
messageDeduplicationId | Applies only to FIFO queues. This is a token for deduplication of messages. | String | No |
messageGroupId | Applies only to FIFO queues. This is a tag for a specific message group. | String | No |
messageSystemAttribute | Key-value pair of message system attributes. For more information, see SQS Message System Attributes. | Struct | No |
<cfscript>
//Get the getCloudService from the credentials and configuration we declared in Application.cfc
sqs = getCloudService(application.awsCred, application.sqsConf);
// Use the sqs service object to create a queue using createQueue().
// This method returns a queue object.
myQueue = sqs.createQueue("SimpleMessageQueue");
// Use the queue object to send a message to the queue.
message = {"messageBody"="This is a sample message."};
sendMessageResponse = myQueue.sendMessage(message);
writedump(sendMessageResponse)
// display the status code
writeoutput(sendMessageResponse.sdkHttpResponse["statusCode"]); // 200
</cfscript><cfscript>
sqs = getCloudService(application.awsCred, application.sqsConf);
stdQueue = sqs.createQueue("sendMessage");
stdQueueUrl = stdQueue.getQueueUrl();
sendMessageMetadata = {
"messageBody"="This is a sample message",
"messageAttributes"={
"timestamps"="#dateTimeFormat(now())#",
"geospatial_data"="San Francisco",
"signatures"="ADBE",
"identifiers"="ColdFusion"
}
}
sendMessageResp = sqs.sendMessage(stdQueueUrl,sendMessageMetadata);
writeoutput(sendMessageResp.sdkHttpResponse.statusCode); // 200
</cfscript><cfscript>
try{
sqs = getCloudService(application.awsCred, application.sqsConf);
queueAttributes = {
"attributes" : {"FifoQueue" : "true"}
}
fifoQueue = sqs.createQueue("sendMessage.fifo", queueAttributes);
fifoQueueUrl = fifoQueue.getQueueUrl();
sendMessageMetadata = {
"messageBody"="This is a sampe message",
"messageGroupId" ="12345",
"messageDeduplicationId" ="123456",
"messageAttributes"={
"timestamps"="#dateTimeFormat(now())#",
"geospatial_data"="San Jose",
"signatures"="ADBE",
"identifiers"="ColdFusion"
}
};
// send message
sendMessageResp = sqs.sendMessage(fifoQueueUrl,sendMessageMetadata);
writeoutput(sendMessageResp.sdkHttpResponse.statusCode); // 200
}
catch(any e){
writeDump(e);
}
</cfscript><cfscript>
// Get the getCloudService from the credentials and configuration we declared in Application.cfc
sqs = getCloudService(application.awsCred, application.sqsConf)
// Use the sqs service object to create a queue using createQueue(). This method returns a queue object.
//writeoutput("Create queue in AWS<br>");
myQueue = sqs.createQueue("MessageQueueWithAttribute");
//Use the queue object to send a message to the queue.
sendMessageMetadata = {
"messageBody"="This is a sample message",
"messageAttributes"={
"timestamps"=datetimeformat(now()),
"geospatial_data"="Bangalore",
"signatures"="ADBE",
"identifiers"="ColdFusion"
}
};
sendMessageResponse = myQueue.sendMessage(sendMessageMetadata);
writeoutput("message successfully sent with attribute");
writeDump(sendMessageResponse)
</cfscript>receiveMessage(String queueUrl, Map receiveMessageOptions)Parameter | Description | Type | Required |
queueUrl | The URL of the queue from which messages are received. | String | Yes |
messageAttributeNames | One of the following:
| Struct | No |
maxNumberOfMessages | The maximum number of messages to return. Valid value 1-10. | Integer | No |
receiveRequestAttemptId | ONLY FOR FIFO queues. | String | No |
vVisibilityTimeout | The time for which messages remain hidden from retrieve requests. | Integer | No |
waitTime | The duration for which a message waits before arriving in the queue. | Integer | No |
<cfscript>
sqs = getCloudService(application.awsCred, application.sqsConf);
// define attribues for a FIFO queue
queueAttributes = {
"attributes" : {
"FifoQueue" : "true"
}
}
fifoQueue = sqs.createQueue("sendMessage.fifo", queueAttributes);
fifoQueueUrl = fifoQueue.getQueueUrl();
sendMessageMetadata = {
"messageBody"="This is a sample message",
"messageGroupId" ="12345",
"messageDeduplicationId" ="123456",
"messageAttributes"={
"timestamps"="#dateTimeFormat(now())#",
"geospatial_data"="Bangalore",
"signatures"="SG",
"identifiers"="ColdFusion"
}
}
// send message
sqs.sendMessage(fifoQueueUrl,sendMessageMetadata)
// define receive message metadata
receiveMessageMetadata = {
"messageAttributeNames"="All"
}
try{
receiveMessageResp = sqs.receiveMessage(fifoQueueUrl,receiveMessageMetadata)
writeOutput("Message received successfully")
writeDump(receiveMessageResp)
}
catch (any e){
writeDump(e)
}
</cfscript><cfscript>
sqs = getCloudService(application.awsCred, application.sqsConf);
// create a queue
stdQueue = sqs.createQueue("ReceiveMessageQueueNew");
// get queue url
stdQueueUrl = stdQueue.getQueueUrl();
sendMessageMetadata = {
"messageBody"="This is a sample message",
"messageAttributes"={
"timestamps"="#dateTimeFormat(now())#",
"geospatial_data"="San Jose",
"signatures"="SG",
"identifiers"="ColdFusion"
}
}
// send message
sqs.sendMessage(stdQueueUrl,sendMessageMetadata);
// define receive message metadata
receiveMessageMetadata = {
"messageAttributeNames"="All"
}
try{
receiveMessageResp = sqs.receiveMessage(stdQueueUrl,receiveMessageMetadata)
writeOutput("Message received successfully")
writeDump(receiveMessageResp)
writeoutput(ArrayLen(receiveMessageResp.messages)>0) // TRUE
}
catch(any e){
writeDump(e)
}
</cfscript>deleteMessage(String queueUrl, Struct message)Parameter | Description | Type | Required |
queueURL | The url of the queue. | String | Yes |
receiptHandle | The receipt handle associated with the message to delete. | String | Yes |
<cfscript>
sqs = getCloudService(application.awsCred, application.sqsConf);
// create a queue
stdQueue = sqs.createQueue("ReceiveMessageQueueNew");
// get queue url
stdQueueUrl = stdQueue.getQueueUrl();
sendMessageMetadata = {
"messageBody"="This is a sample message",
"messageAttributes"={
"timestamps"="#dateTimeFormat(now())#",
"geospatial_data"="San Jose",
"signatures"="SG",
"identifiers"="ColdFusion"
}
}
// send message
sqs.sendMessage(stdQueueUrl,sendMessageMetadata)
// receive message
// define receive message metadata
receiveMessageMetadata = {
"messageAttributeNames"="All"
}
receiveMessageResp=sqs.receiveMessage(stdQueueUrl,receiveMessageMetadata)
// get receipt handle
receiptHandle={
"receiptHandle":receiveMessageResp.messages[1].receiptHandle
}
// delete message
try{
deleteMessageResponse=sqs.deleteMessage(stdQueueUrl,receiptHandle)
writeOutput("Message deleted successfully")
writeDump(deleteMessageResponse)
}
catch(any e){
writeDump(e)
}
</cfscript>setQueueAttributes(String queueUrl, Struct queueAttributes)Parameter | Description | Type | Required |
queueURL | The URL of the queue whose attributes are to be set. | String | Yes |
attribute | Key-value pair of the following:
Attributes for FIFO:
Attributes for Server-Side Encryption:
| Struct | Yes |
<cfscript>
sqs = getCloudService(application.awsCred, application.sqsConf)
// create a queue
sqs.createQueue("QueueAttributeDemo")
// get queue url
qURL=sqs.getQueueUrl("QueueAttributeDemo")
// define queue attribute metadata
setQueueAttributes = {
"attributes"={
"VisibilityTimeout"="10",
"MessageRetentionPeriod"="100",
"MaximumMessageSize"="1024",
"DelaySeconds"="10",
"ReceiveMessageWaitTimeSeconds"="20"
}
}
// set the queue attributes
try{
queueAttributeResponse=sqs.setQueueAttributes(qURL,setQueueAttributes
writeOutput("Queue attributes set successfully")
writeDump(queueAttributeResponse)
}
catch(any e){
writeOutput("Unable to set queue attribute")
writeDump(e)
}
</cfscript>getQueueAttributes(String queueUrl, Struct queueAttributes)Parameter | Description | Type | Required |
queueURL | The URL of the queue whose attributes are to be retrieved. | String | Yes |
attributeNames | One of the following:
Attributes for SSE:
Attributes for FIFO:
| Array | Yes |
<cfscript>
sqs = getCloudService(application.awsCred, application.sqsConf)
// create a queue
sqs.createQueue("QueueGetAttributeDemo")
// get queue url
qURL=sqs.getQueueUrl("QueueGetAttributeDemo")
// define queue attribute metadata
setQueueAttributes = {
"attributes"={
"VisibilityTimeout"="10",
"MessageRetentionPeriod"="100",
"MaximumMessageSize"="1024",
"DelaySeconds"="10",
"ReceiveMessageWaitTimeSeconds"="20"
}
}
// set the queue attributes
sqs.setQueueAttributes(qURL,setQueueAttributes)
// define get attribute metadata
getQueueAttributesMetadata={
"attributeNames"=["All"]
}
try{
getAttributeResponse=sqs.getQueueAttributes(qURL,getQueueAttributesMetadata)
writeOutput("Queue attributes are:")
writeDump(getAttributeResponse.attributes)
}
catch(any e){
writeDump(e)
}
</cfscript>changeMessageVisibility(String queueUrl, Struct message)Parameter | Description | Type | Required |
queueURL | The URL of the queue whose message's visibility timeout is to be changed. | String | Yes |
receiptHandle | The receipt handle of the message whose visibility timeout is to be changed. | String | Yes |
visibilityTimeout | The new timeout value (0-43200) | Integer | Yes |
<cfscript>
sqs = getCloudService(application.awsCred, application.sqsConf);
stdQueue = sqs.createQueue("ChangeVisibilityDemo");
stdQueueUrl = stdQueue.getQueueUrl();
sendMessageMetadata = {
"messageBody"="This is a sample message",
"messageAttributes"={
"timestamps"="#dateTimeFormat(now())#",
"geospatial_data"="London",
"signatures"="CF",
"identifiers"="ColdFusion"
}
}
// send message to the queue
sqs.sendMessage(stdQueueUrl,sendMessageMetadata);
// define receive message metadata
receiveMessageMetadata = {
"messageAttributeNames"="All"
};
// receive message
receiveMessageResp=sqs.receiveMessage(stdQueueUrl,receiveMessageMetadata);
msgReceiptHandle= receiveMessageResp.messages[1].receiptHandle;
// define change visibility metadata
changeVisibilityMetadata= {
"visibilityTimeout":"100", // 100 seconds
"receiptHandle":msgReceiptHandle
}
try{
changeVisibiltyResponse= sqs.changeMessageVisibility(stdQueueUrl,changeVisibilityMetadata)
writeOutput("Message visibility timeout changed successfully")
writeDump(changeVisibiltyResponse)
writeoutput(changeVisibiltyResponse.sdkHttpResponse.statusCode)
}
catch(any e){
writeDump(e)
}
</cfscript>changeMessageVisibilityBatch(String queueUrl, List<Map> messages)Parameter | Description | Type | Required |
queueURL | The url of the queue whose messages' visibility is to be changed. | String | Yes |
changeMessageVisibilityBatchMetadata | Receipt handles of the messages for which the visibility timeout must be changed. For more information, see the array objects. | Array | Yes |
<cfscript>
sqsObj = getCloudService(application.awsCred, application.sqsConf);
stdQueueName = "stdBatchQueue"
// create the queue
stdQueueObj = sqsObj.createQueue(stdQueueName);
// get the queue url
stdQueueUrl = stdQueueObj.getQueueUrl()
// define the metadata for sending messages in a batch
sendMessageBatchMetadata =
[
{
"id":"1",
"messageAttributes":{
"name":"name1",
"type":"string",
"value":"value1"
},
"messageBody":"This is the body of batch 1"
},
{
"id":"2",
"messageAttributes":{
"name":"name2",
"type":"number",
"value":24
},
"messageBody":"This is the body of batch 2"
},
{
"id":"3",
"messageAttributes":{
"name":"name3",
"type":"string",
"value":"value2"
},
"messageBody":"This is the body of batch 3"
}
]
// send the messages in batch
sendMessageBatchResponse = sqsObj.sendMessageBatch(stdQueueUrl, sendMessageBatchMetadata);
// Receive the messages in the queue
receiveMessageMetadata = {
"messageAttributeNames"="All",
"maxNumberOfMessages"=5
}
receiveMessageResp = sqsObj.receiveMessage(stdQueueUrl,receiveMessageMetadata);
writeDump(receiveMessageResp)
//break;
// Define metadata for visibility change
changeMessageVisibilityBatchMetadata=[
{
"id":receiveMessageResp.messages[1].messageId,
"receiptHandle":receiveMessageResp.messages[1].receiptHandle,
"visibilityTimeout":"20"
}
// {
// "id":receiveMessageResp.messages[2].messageId,
// "receiptHandle":receiveMessageResp.messages[2].receiptHandle,
// "visibilityTimeout":"10"
// }
]
// Change visiblity in batch
changeMessageVisibilityBatchResponse=sqsObj.changeMessageVisibilityBatch(stdQueueUrl,changeMessageVisibilityBatchMetadata)
writeDump(changeMessageVisibilityBatchResponse)
</cfscript>sendMessageBatch(String queueUrl, List<Map> messages)Parameter | Description | Type | Required |
queueURL | The url of the queue to which messages are to be sent in a batch. | String | Yes |
sendMessageBatchMetadata | Array of SendMessageBatchRequestEntry objects. | Array | Yes |
<cfscript>
sqs = getCloudService(application.awsCred, application.sqsConf)
// get queue url to which the message batch will be sent.
myQueueUrl=sqs.listQueues().queueUrls[1]
sendMessageBatchMetadata =
[
{
"id":"1",
"messageAttributes":{
"name":"name1",
"type":"string",
"value":"value1"
},
"messageBody":"This is the body of batch 1"
},
{
"id":"2",
"messageAttributes":{
"name":"name2",
"type":"number",
"value":24
},
"messageBody":"This is the body of batch 2"
}
]
try{
sendMessageBatchResponse = sqs.sendMessageBatch(myQueueUrl, sendMessageBatchMetadata)
writeOutput("Message batch sent successfully")
writeDump(sendMessageBatchResponse)
writeDump(sendMessageBatchResponse.successful)
}
catch (any e){
writeDump(e)
}
</cfscript>deleteMessageBatch(String queueUrl, List<Map> messages)Parameter | Description | Type | Required |
queueURL | The url of the queue whose messages are to be deleted. | String | Yes |
deleteMessageBatchMetadata | List of receipt handles of the messages to be deleted. Array of DeleteMessageBatchRequestEntry objects. | Array | Yes |
<cfscript>
sqs = getCloudService(application.awsCred, application.sqsConf)
// create a queue
myQueue = sqs.createQueue("SendDeleteBatchMessage")
// get queue url
qURL=myQueue.getQueueUrl()
// upoad a file
myImage = "image.PNG"
sendMessageBatchMetadata = [
{"id"="1", "messageBody"="Delete Batch Message 1", "messageAttributes"={"date"=datetimeformat(now()), "myAtt12"="#toBinary(toBase64(myImage))#"}},
{"id"="2", "messageBody"="Delete Batch Message 2", "messageAttributes"={"send_date"=datetimeformat(now())}}
];
sendMessageResponse = sqs.sendMessageBatch(qURL, sendMessageBatchMetadata)
// writeDump(sendMessageResponse)
// break;
// receive messages in the queue
receiveMessageMetadata = {"messageAttributeNames"="All","maxNumberOfMessages"=2}
receiveMessageResponse = sqs.receiveMessage(qURL,receiveMessageMetadata);
writeDump(receiveMessageResponse)
//break;
writeoutput("Delete message batch response");
msgReceiptHandle1= receiveMessageResponse.messages[1].receiptHandle;
msgReceiptHandle2= receiveMessageResponse.messages[2].receiptHandle;
deleteMessageBatchMetadata = [
{"id"="1", "receiptHandle"="#msgReceiptHandle1#"},
{"id"="2", "receiptHandle"="#msgReceiptHandle2#"}
];
deleteMessageResponse = sqs.deleteMessageBatch(qURL,deleteMessageBatchMetadata);
writeDump(deleteMessageResponse)
</cfscript><cfscript>
try{
sqs = getCloudService(application.awsCred, application.sqsConf);
queueAttributes = {
"attributes" : {"FifoQueue" : "true"}
}
fifoQueue = sqs.createQueue("sendBatchMessage.fifo", queueAttributes);
fifoQueueUrl = fifoQueue.getQueueUrl();
sendMessageBatchMetadata = [
{"id"="1", "messageBody"="First Batch message","messageGroupId" ="720","messageDeduplicationId" ="23", "messageAttributes"={"myAtt1"="First"}},
{"id"="2", "messageBody"="Second Batch Message","messageGroupId" ="008","messageDeduplicationId" ="45", "messageAttributes"={"myAtt21"="Second"}}
];
sendMessageResp = sqs.sendMessageBatch(fifoQueueUrl,sendMessageBatchMetadata);
writeoutput(sendMessageResp.sdkHttpResponse.statusCode);
receiveMessageMetadata = {"messageAttributeNames"="All","maxNumberOfMessages"=2};
receiveMessageResp = sqs.receiveMessage(fifoQueueUrl,receiveMessageMetadata);
msgReceiptHandle1= receiveMessageResp.messages[1].receiptHandle;
msgReceiptHandle2= receiveMessageResp.messages[2].receiptHandle;
deleteMessageBatchMetadata = [
{"id"="1", "receiptHandle"="#msgReceiptHandle1#"},
{"id"="2", "receiptHandle"="#msgReceiptHandle2#"}
];
deleteMsgReps= sqs.deleteMessageBatch(fifoQueueUrl,deleteMessageBatchMetadata);
writeoutput(deleteMsgReps.sdkHttpResponse.statusCode);
}
catch(any e){
writeDump(e);
}addPermission(String queueUrl, Struct permission)Parameter | Description | Type | Required |
Actions | The action the client wants to allow for the specified principal. Valid values are:
| Array | Yes |
awsAccountIds | The AWS account number of the principal who is given permission. | Array | Yes |
Label | The unique id of the permission to be set. | String | Yes |
queueUrl | The URL of the queue. | String | Yes |
<cfscript>
sqs = getCloudService(application.awsCred, application.sqsConf);
// create queue
sqs.createQueue("AddPermission");
// get url of the queue
queueUrl=sqs.getQueueUrl("AddPermission")
// define permission struct
addPermissionStruct={
"actions" = ["SendMessage"], // Send message action granted
"awsAccountIds" = ["xxxxxxxxxxxxx"],
"label" = "label-cf-sqs"
}
try{
addPermissionResp = sqs.addPermission(queueUrl,addPermissionStruct)
writeOutput("Permission added successfully")
writeDump(addPermissionResp)
}
catch (any e){
writeDump(e)
}
</cfscript>removePermission(String queueUrl, String permissionLabel)Parameters | Description | Type | Required |
queueURL | The url of the queue from which you want to remove the permission. | String | Yes |
permissionLabel | The unique Id of the permission to remove. | String | Yes |
<cfscript>
sqs = getCloudService(application.awsCred, application.sqsConf);
// create queue
sqs.createQueue("RemovePermission");
// get url of the queue
queueUrl=sqs.getQueueUrl("AddPermission")
// define permission struct
addPermissionStruct={
"actions" = ["SendMessage"], // Send message action granted
"awsAccountIds" = ["xxxxxxxxxxxxx"],
"label" = "label-cf-sqs"
}
sqs.addPermission(queueUrl,addPermissionStruct)
// remove permission struct
labelToRemove="label-cf-sqs"
try{
removePermissionResp = sqs.removePermission(queueUrl,labelToRemove)
writeOutput("Permission removed successfully")
writeDump(removePermissionResp)
}
catch(any e){
writeDump(e)
}
</cfscript>listDeadLetterSourceQueues(queueUrl)Parameter | Description | Type | Required |
queueURL | The URL of a dead-letter queue. | String | Yes |
<cfscript>
sqs = getCloudService(application.awsCred, application.sqsConf);
setQueueAttributesMetadata = {
"attributes"={
"FifoQueue" : "true"
}
}
// create FIFO queues
myQueue = sqs.createQueue("FIFOQueue4DL.fifo",setQueueAttributesMetadata);
deadLetterQueue = sqs.createQueue("dead_Letter_Queue.fifo",setQueueAttributesMetadata);
queueUrl = myQueue.getQueueUrl();
getQueueAttributesMetadata = {"attributeNames":["All"]};
deadLetterQueueARN = deadLetterQueue.getAttributes(#getQueueAttributesMetadata#).attributes["QueueArn"];
redrivePolicy = {
"maxReceiveCount" = 2,
"deadLetterTargetArn" = "#deadLetterQueueARN#"
}
setQueueAttributesMetadata = {
"attributes"={
"RedrivePolicy" = "#serializeJson(redrivePolicy)#"
}
};
setQueueAttributesResponse = myQueue.setAttributes(setQueueAttributesMetadata);
getQueueAttributesMetadata = {"attributeNames"=["All"]};
getQueueAttributesResponse = myQueue.getAttributes(getQueueAttributesMetadata);
redrivePolicyVal= #deserializeJson(getQueueAttributesResponse.attributes["RedrivePolicy"])#;
writeoutput(#redrivePolicyVal.deadLetterTargetArn#);
</cfscript><cfscript>
sqs = getCloudService(application.awsCred, application.sqsConf);
myQueue = sqs.createQueue("longPolling");
writeoutput(myQueue.getQueueUrl());
queueUrl = myQueue.getQueueUrl();
setQueueAttributesMetadata = {
"attributes"={
"ReceiveMessageWaitTimeSeconds"="20"
}
};
setQueueAttributesResponse = myQueue.setAttributes(setQueueAttributesMetadata);
longPollingVal=myQueue.getAttributes({"attributeNames"=["ReceiveMessageWaitTimeSeconds"]});
writeoutput(longPollingVal.attributes["ReceiveMessageWaitTimeSeconds"]);
</cfscript>