Navigate to <CF_HOME>/cfusion/bin.
Microsoft Azure Service Bus is a managed enterprise integration message broker. Service Bus can decouple applications and services. Service Bus offers a platform for asynchronous data and state transfer.
Data is transferred between different applications and services using messages. A message is in binary format and can contain JSON, XML, or just text.
The Data is transferred between different applications and services using messages. A message is in binary format and can contain JSON, XML, or just text.
You can use Service Bus to transfer data, increase scalability, implement workflows, manage topics and subscriptions, and many more.
For more information, see Overview of Service Bus.
A namespace is a container for all messaging components. You can have multiple queues and topics in a single namespace. Namespaces often serve as containers for various applications and services.
Messages are sent to and received from queues. Queues store messages until the receiving application is available to receive and process them.
You can also use topics to send and receive messages. While a queue is often used for point-to-point communication, topics are useful in publish/subscribe scenarios.
Adobe ColdFusion (2021 release) is modularized, if you are only using the ZIP installer. By default, the package for Azure Service Bus is not installed. The first step is to install the Service Bus package in ColdFusion.
Note: If you are using the GUI installer, the packages are pre-installed.
The package for Service Bus is called azureservicebus.
To install the package azureservicebus, use the Package Manager page in the ColdFusion Administrator, or follow the steps below:
Navigate to <CF_HOME>/cfusion/bin.
Enter the command:
Enter the command, install azureservicebus.
Wait for the Azure Service Bus package to get installed.
For more information, see ColdFusion Package Manager.
In ColdFusion (2021 release), there is a method getCloudService() that gives you a handle to create objects for accessing various cloud services.
The syntax of the service handle is as follows:
service=getCloudService(cloudCred,cloudConfig), where:
After you've acquired the Azure credentials, you must declare these credentials in one of the following ways. Only then you can use these credentials to create a Service Bus object, after which you can use the object to make calls to the various Azure Service Bus methods.
In the ColdFusion Administrator, click Data & Services > Cloud Credentials.
An alias is a named representation of a cloud service and its configuration details. You can set the config alias through ColdFusion Administrator.
A connection string includes the authorization information required for your application to access data in an Azure Storage account.
For more information, see Configure Azure Storage connection strings.
After entering the details, click Add Credential.
In the ColdFusion Administrator, click Data & Services > Cloud Configuration.
Enter the following details, like configuration Alias, Vendor, and the name of the service.
After adding the configuration options, you may need to add a few more options. You can do so in the next screen. The following are a few options that you may need to add:
For more information, see Cloud configuration options.
Once you've created the aliases for Blob credential and configuration options, you can create the object by using the getCloudService API, and include the following in your CFM.
sbObject= getCloudService("sbCred", "sbConf")
You can specify the Blob credentials and configuration options in Application.cfc. For example,
<cfscript> this.sqsCred = { "alias" : "firstAWSCred", "vendorName" : "AZURE", "region" : "us-west-2", "secretAccessKey" : "xxxxxxxxxxxxxxxxxxx", "accessKeyId" : "xxxxxxxxxxxxxxxxxx" } this.sqsConf = { "serviceName" : "SERVICE_BUS" } this.serviceBusCred = { "vendorName" : "AZURE", "connectionString" : "xxxxxxxxxx" } this.serviceBusConf = { "serviceName" : "SERVICE_BUS" } </cfscript>
sbObject = getCloudService(this.serviceBusCred, this.serviceBusConf)
On a CFM page, you can specify the Service Bus credentials and configuration options in one of the four methods, specified below:
After you've created the aliases for Azure Blob credential and configuration options, you can use these aliases in the getCloudService handle as shown below:
<cfscript> // define the credential and the configuration aliases in the ColdFusion Admin sbObject=getCloudService("sbCred","sbConf") // code below. ........... </cfscript>
<cfscript> sbCred = { "vendorName" : "AZURE", "connectionString" : "xxxxxx" } sbConf = { "serviceName" : "AZURE_SERVICEBUS", "options" : { "operationTimeout" : "10s", "retryPolicy":"default" } } </cfscript>
<cfscript> // Using config alias and struct for service credentials // service bus credentials sbCred= { "vendorName" : "AZURE", "connectionString" : "xxxxxx" } sb= getCloudService(sbCred, "sbConf") // code below ..................................... </cfscript>
<cfscript> // Using Structs for both cloud credential and config sbCred = { "vendorName" : "AZURE", "connectionString" : "xxxxxx" } sbConf = { "serviceName" : "AZURE_SERVICEBUS", "options" : { "operationTimeout" : "10s", "retryPolicy":"default" } } sb= getCloudService(sbCred , sbConf ) // code below ................................................................... </cfscript>
You can also add Service Bus credentials and configuration options by using the Admin APIs. The methods to add credentials and configuration are available in cloud.cfc.
The examples below demonstrate the usage of the methods addCredential(struct credential) and addServiceConfig(struct config).
<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= { "vendorName" : "AZURE", "connectionString" : "xxxxxx" } // 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= { "serviceName" : "AZURE_SERVICEBUS", "options" : { "operationTimeout" : "10s", "retryPolicy":"default" } } // add config configStruct try{ cloudObj.addServiceConfig(configStruct) writeOutput("Configuration service added successfully") } catch(any e){ writeDump(e) } </cfscript>
You can also set up SQS credential and configuration via the CFSetup configuration utility.
Add cloud credential
Set credential
Add cloud configuration
Set configuration
In ColdFusion Administrator > Settings, you can modify thread pool settins that are used for handling Service Bus events.
In Service Bus, topics can have multiple, independent subscriptions. A subscriber to a topic can receive a copy of each message sent to that Topic. Multiple receivers could be allocated to a subscription. A topic can have zero or more subscriptions, but a subscription can only belong to one topic.
EXAMPLE
<cfscript> sb = getcloudService(this.serviceBusCred, this.serviceBusConf) // topic metadata createTopicMetadata = { "autoDeleteOnIdle" = "45M", "requiresDuplicateDetection" = "yes", //"maxSize" = 1024, "entityStatus" = "Active", "userMetadata" = "my user metadata", "enableBatchedOperations" = "true", "enablePartitioning" = "yes" } //sb.deleteTopic("secondTopic") tempTopic = sb.createTopic("Topic_005", createTopicMetadata) //sb.deleteTopic("firstTopic") writeDump(tempTopic) //writeDump(sb.listTopics()) </cfscript>
Applications receive messages from subscriptions in the same way that they receive them from queues by using a QueueClient or MessageSession object. A topic can have zero or more subscriptions, but a subscription can only belong to one topic. For more information, see Azure SB subscriptions.
EXAMPLE
<cfscript> sb = getcloudService(this.serviceBusCred, this.serviceBusConf) subscriptionMetadata={ "subscriptionName"="sub_1", "topicPath"="Topic_005", "lockDuration" = "77s", "maxDeliveryCount" = 12, "enableDeadLetteringOnMessageExpiration"="true", "enableDeadLetteringOnFilterEvaluationException"="true" } mysub=sb.subscribe(subscriptionMetadata) writeDump(mysub) </cfscript>
Once you’ve created a queue, you can send messages to the queue, using the function sendMessage. For more information, see the official docs.
EXAMPLE
<cfscript> sb = getcloudService(this.serviceBusCred, this.serviceBusConf) sb.deleteQueue("Queue18") // send message sendMessageMetadata = { "messageBody" = "my message is here", "messageProperties" = { "myatt1" = "att1,att2" } } tempQ = sb.createQueue("Queue18") //writedump(tempQ) mypath=tempQ.getPath() sendMessageResponse = tempQ.sendMessage(sendMessageMetadata) writeDump(sendMessageResponse) </cfscript>
Member function
<cfscript> sb = getcloudService(this.serviceBusCred, this.serviceBusConf); myQ = sb.listQueues().get("queueList")[1] sendMessage() public function sendMessage() { writeoutput("send message response") closure = function (){ writeoutput("my function my choice") } sendMessageMetadata = { "messageBody" = "my message my choice", "messageProperties" = { "myatt1" = "att1,att2" } } sendMessageResponse = myQ.sendMessage(sendMessageMetadata) writeDump(sendMessageResponse) } </cfscript>
To list all queues, use the function listQueues.
EXAMPLE
<cfscript> sb = getcloudService(this.serviceBusCred, this.serviceBusConf) // list all queues allQueues=sb.listQueues() writeDump(allQueues) </cfscript>
Member function
<cfscript> sb = getcloudService(this.serviceBusCred, this.serviceBusConf); myQ = sb.listQueues().get("queueList")[1] writeDump(myQ.getDescription()) </cfscript>
To delete a queue, use the function deleteQueue. This function the name of the queue as parameter.
EXAMPLE
<cfscript> sb = getcloudService(this.serviceBusCred, this.serviceBusConf) // list all queues try{ sb.deleteQueue("Queue8") writeOutput("Queue deleted successfully") } catch (any e){ writeOutput("Unable to delete queue") } </cfscript>
To update a queue, use the function updateQueue. This function accepts the following parameters:
The metadata struct consists of the following values:
EXAMPLE
<cfscript> sb = getcloudService(this.serviceBusCred, this.serviceBusConf) // define queue attributes lockDuration = 51 qName = "Q_001" queueAttributes = { "autoDeleteOnIdle" = "240h", "enableDeadLetteringOnMessageExpiration" = true, "maxDeliveryCount" = 101, "requiresDuplicateDetection" = "YES", // cannot be changed w/ update. "lockDuration" = "#lockDuration#s", //"maxSizeInMB" = 2048, //check for default value "entityStatus" = "Active", "userMetadata" = "some user metadata : data val", "enableBatchedOperations" = true, "enablePartitioning" = false // cannot be changed w/ update. } queueAttributesUpdated = { "autoDeleteOnIdle" = "10M", "enableDeadLetteringOnMessageExpiration" = false, "entityStatus" = "Disabled", "userMetadata" = "some new user metadata", "enableBatchedOperations" = "no" } // create the queue sb.createQueue(qName, queueAttributes) try{ sb.updateQueue(qName, queueAttributesUpdated) writeOutput("Queue updated successfully.") } catch (any e){ writeOutput("Could not update queue.") } </cfscript>
When Prefetch is enabled in any of the official Service Bus clients, the receiver quietly acquires more messages, up to the PrefetchCount limit, beyond what the application initially asked for. For more information, see Service bus prefetch.
EXAMPLE
<cfscript> sb = getcloudService(this.serviceBusCred, this.serviceBusConf) // create a queue myQueue=sb.createQueue("Q_004") // set prefetch count try{ setCount=sb.setPrefectCount(myQueue,50) writeOutput("Prefetch count set successfully.") } catch (any e){ writeOutput("Unable to set prefetch count.") } </cfscript>
Example
<cfscript> sb = getcloudService(this.serviceBusCred, this.serviceBusConf) // get prefetch count getCount=sb.getPrefetchCount("Q_004") writeDump(getCount) </cfscript>
Use the function sendMessageBatch to send a batch of messages to a queue. The function accepts the following parameters:
Example
<cfscript> sb = getcloudService(this.serviceBusCred, this.serviceBusConf) msgLockDurationInQ = 3 pauseTimeInSecs = (msgLockDurationInQ+3) * 1000 msgCount = 5 qName = "Q_batchOps" queueAttributes = { "maxDeliveryCount" = 100, "lockDuration" = "#msgLockDurationInQ#s" } // create a queue myQueue=sb.createQueue(qName,queueAttributes) // send messages in a batch msgBatch = arrayNew(1) for(n=1; n <= msgCount; n++){ msgInstance = { "messageId" = "#n#", "messageBody" = "msg time stamp - #now()#" } msgBatch[n] = msgInstance } messageBatchResponse=sb.sendMessageBatch(qName, msgBatch) writeDump(messageBatchResponse) </cfscript>
You can submit messages to a queue or topic for delayed processing; for example, to schedule a job to become available for processing by a system at a certain time. For more information, see the official docs.
Example
<cfscript> sb = getcloudService(this.serviceBusCred, this.serviceBusConf) // create a queue myQueue=sb.createQueue("Q_006") schedMessage={ "messageId" = "001", "messageBody" = "message body", "ScheduledEnqueueTimeUtc"="02/02/2020" } scheduleResponse=sb.scheduleMessageToQueue(myQueue, schedMessage) writeDump(scheduleResponse) </cfscript>
Message browsing, or peeking, enables a Service Bus client to enumerate all messages that reside in a queue or subscription, typically for diagnostic and debugging purposes. For more information, see the official docs.
Example
<cfscript> sb = getcloudService(this.serviceBusCred, this.serviceBusConf) msgCount = 3 msgLockDuration = 3 qName = "Q_Peek_Ex" queueAttributes = { "maxDeliveryCount" = msgCount, "lockDuration" = "#msgLockDuration#s" } queue = sb.createQueue(qName, queueAttributes) peekProps = { "fromSequenceNumber" = 1, "messageCount" = msgCount - 1 } writeOutput("peeking q msgs...<br>") writeDump(queue.peekMessage(peekProps)) </cfscript>
After you create a topic, you can update the topic using the updateTopic function. The function accepts the following parameters:
Example
<cfscript> sb = getcloudService(this.serviceBusCred, this.serviceBusConf) // define topic attributes topicName = "topic_001"; autoDeleteOnIdle = 45 topicAttributes = { "autoDeleteOnIdle" = "#autoDeleteOnIdle#M", //"requiresDuplicateDetection" = "yes", //cannot be modified. def.: false "maxSizeInMB" = 1024, "entityStatus" = "Active", "userMetadata" = "modified metadata", "enableBatchedOperations" = true, "enablePartitioning" = "no" } // create a topic topic = sb.createTopic(topicName) //create with default attributes writeOutput("created topic: " & topic.getPath() & "<br>") // update the topic try{ sb.updateTopic(topicName, topicAttributes) writeOutput("Topic " & topicName & " updated successfully") } catch (any e){ writeOutput("Unable to update topic") } </cfscript>
Delete a topic that you’d created. Use the function deleteTopic. The function accepts the topicPath as argument.
Example
<cfscript> sb = getcloudService(this.serviceBusCred, this.serviceBusConf) topicName="topic_001" // delete the previously created topic- "topic_001" try{ sb.deleteTopic(topicName) writeOutput("Topic " & topicName & " deleted successfully") } catch(any e){ writeOutput("Unable to delete the topic") } </cfscript>
List all topics in an account. Use the function listTopics.
Example
<cfscript> sb = getcloudService(this.serviceBusCred, this.serviceBusConf) // create two topics sb.createTopic("T1") // Topic 1 sb.createTopic("T2") // Topic 2 // list all topics listResponse=sb.listTopics() writeDump(listResponse) </cfscript>
You can unsubscribe to a topic using the unsubscribe method.
Example
<cfscript> sb = getcloudService(this.serviceBusCred, this.serviceBusConf) topicName = "topic-for-sub"; subscriptionName = "subsciption-001" subscriptionAttribs = { "subscriptionName" = subscriptionName, "autoDeleteOnIdle" = "5M", "maxDeliveryCount" = 10, "lockDuration" = "10s", "defaultMessageTimeToLive" = "10M" } // create topic try{ topic=sb.createTopic(topicName) //create w/ default attributes writeOutput("Topic created successfully") } catch(any e){ writeOutput("Unable to create topic") } // create subscription try{ subscription = topic.subscribe(topicName, subscriptionAttribs) //create w/ default attributes writeOutput("Subscribed to topic successfully") } catch(any e){ writeOutput("Unable to subscribe to topic") } // unsubscribe to topic //unsubscribe(String topicPath, String subscriptionName) try{ sb.unsubscribe(topic,subscription) writeOutput("Unsubscribed successfully") } catch(any e){ writeOutput("Unable to unsubscribe") } </cfscript>
To retrieve the name of a subscription, previously, created, use the function getSubscription. The function accepts the name of the topic and the subscription.
Example
<cfscript> sb = getcloudService(this.serviceBusCred, this.serviceBusConf) topicName = "testTopic" // create a topic topic=sb.createTopic(topicName) subscriptionName = "sub-00" // get a subscription subscription = topic.getSubscription(subscriptionName) writeDump(subsciption) </cfscript>
The RegisterMessageHandler method registers handlers. The handler is invoked when the event happens.
For more information, see the official docs.
Example
<cfscript> sb = getcloudService(this.serviceBusCred, this.serviceBusConf) // void registerMessageHandler(String topicPath, String subscriptionName, Map metadata) // create topic // topic metadata createTopicMetadata = { "autoDeleteOnIdle" = "45M", "requiresDuplicateDetection" = "yes", //"maxSize" = 1024, "entityStatus" = "Active", "userMetadata" = "my user metadata", "enableBatchedOperations" = "true", "enablePartitioning" = "yes" } topic = sb.createTopic("Topic_013", createTopicMetadata) // create a subscription subscriptionName = "Sub_013" subscriptionAttribs = { "subscriptionName" = subscriptionName, "autoDeleteOnIdle" = "5M", "maxDeliveryCount" = 10, "lockDuration" = "10s", "defaultMessageTimeToLive" = "10M" } subscription = topic.subscribe(subscriptionAttribs) messageHandlerOptions={ "autocomplete"="yes", "maxautorenewduration"="50M", "maxconsurrentcalls"=30 } renewMessageResponse=sb.registerMessageHandler(topic,subscription,messageHandlerOptions) writeDump(renewMessageResponse) </cfscript>
Discards all messages to a subscription.
Syntax
abandonSubscriptionMessage(String formattedSubscriptionPath, Map metadata)
<cfscript> sb = getcloudService(this.serviceBusCred, this.serviceBusConf) topicName = "topic_003"; topic = topicUtil.createTopic(sb, topicName, false, {}) //purgeAndRecreate, attribs originalLabel = "Red" adandonCountLabel = "adandonCount" subscriptionName = "sub_003" subscription = topic.subscribe({ "subscriptionName" = subscriptionName }) updatedMessageProperties = { "DeadLetterReason" = "reason for this", "DeadLetterErrorDescription" = "collateral" } abandonResponse = sb.abandonSubscriptionMessage(subscription.getTopicName(), subscription.getSubscriptionName(), updatedMessageProperties) writeDump(abandonResponse) </cfscript>
Abandons a message with a lock token. This will make the message available again for processing. Abandoning a message will increase the delivery count on the message.
Syntax
abandonMessage(String queuePath, Map metadata)
<cfscript> sb = getcloudService(this.serviceBusCred, this.serviceBusConf) qName = "cfqa-abandon-msg" // create queue queue = sb.createQueue(qName) oldLabel = "red" newLabel = "blue" sentMessage = sendMessage(queue, oldLabel) writeOutput("peeking at the queue: #qName#, before abandoning message.<br>") receivedMessage = sb.receiveMessagesFromQueue(queue, "PEEKLOCK", 1) //READ_MODE_RECEIVEANDDELETE for(message in receivedMessage){ //cfdump(var=#message#, label="message received.") abandonMessage(qName, message.lockToken, newLabel) } </cfscript>
When a queue or subscription client receives a message that it is willing to process, but for which processing is not currently possible due to special circumstances inside of the application, it has the option of "deferring" retrieval of the message to a later point. The message remains in the queue or subscription, but it is set aside.
Syntax
deferMessage(String queuePath, Map metadata)
<cfscript> sb = getcloudService(this.serviceBusCred, this.serviceBusConf) qName="queue_002" // create queue queue = sb.createQueue(qName, {"lockDuration": "2s"}) // send message to the queue msgBatch = arrayNew(1) for(n=1; n <= msgCount; n++){ msgInstance = { "messageId" = "#n#", "messageBody" = "msg time stamp - #now()#" } msgBatch[n] = msgInstance } sb.sendMessageBatch(qName, msgBatch) receivedMessage = sb.receiveMessagesFromQueue(queue, "PEEKLOCK", 1) //READ_MODE_RECEIVEANDDELETE // defer message for(message in receivedMessage){ propertiesToModify = {"deferred_time:" : dateTimeFormat(now())} sb.deferMessage(qName, { "lockToken" = message.lockToken , "propertiesToModify" = propertiesToModify }) } </cfscript>
Deferred messages remain in the main queue along with all other active messages (unlike dead-letter messages that live in a subqueue), but they can no longer be received using the regular Receive/ReceiveAsync functions. Deferred messages can be discovered via message browsing if an application loses track of them.
Syntax
receiveDeferredMessage(String queuePath, Map metadata)
<cfscript> sb = getcloudService(this.serviceBusCred, this.serviceBusConf) qName="queue_002" // create queue queue = sb.createQueue(qName, {"lockDuration": "2s"}) // send message to the queue msgBatch = arrayNew(1) for(n=1; n <= msgCount; n++){ msgInstance = { "messageId" = "#n#", "messageBody" = "msg time stamp - #now()#" } msgBatch[n] = msgInstance } sb.sendMessageBatch(qName, msgBatch) receivedMessage = sb.receiveMessagesFromQueue(queue, "PEEKLOCK", 1) //READ_MODE_RECEIVEANDDELETE // defer message for(message in receivedMessage){ propertiesToModify = {"deferred_time:" : dateTimeFormat(now())} sb.deferMessage(qName, { "lockToken" = message.lockToken , "propertiesToModify" = propertiesToModify }) } // receive deferred message receivedDeferredMessage = sb.receiveDeferredMessage(qName, { "sequenceNumber" : seqNo } ) writeDump(receivedDeferredMessage) </cfscript>
Azure Service Bus queues and topic subscriptions provide a secondary sub-queue, called a dead-letter queue. The dead-letter queue need not be explicitly created and cannot be deleted. The purpose of the dead-letter queue is to hold messages that cannot be delivered to any receiver, or messages that cannot be processed.
Syntax
deadLetterMessage(String queuePath, Map metadata)
Syntax
deadLetterSubscriptionMessage(String formattedSubscriptionPath, Map metadata)
A Filter or a Subscription Rule specifies which messages that have been sent to that Topic must be received by a Topic Subscription. Whenever a Topic Subscription is created, a default Topic Subscription Rule gets created, which enables all the messages sent to that Topic to be received by it.
Syntax
addSubscriptionRule(String topicPath, String subscriptionName, Map metadata)
<cfscript> sb = getcloudService(this.serviceBusCred, this.serviceBusConf) // create a topic topicName = "topic_001" topic = sb.createTopic(topicName) subscriptionName = "subscription_001" // subscribe to topic sb.subscribe( topicName, { "subscriptionName" = subscriptionName } ) // get rules filterRuleTrue = { "type" = "true", "name" = "trueFilter" } sb.addSubscriptionRule(topicName, subscriptonName, filterRuleTrue) </cfscript>
Syntax
removeSubscriptionRule(String topicPath, String subscriptionName, String ruleName)
<cfscript> sb = getcloudService(this.serviceBusCred, this.serviceBusConf) // create a topic topicName = "topic_001" topic = sb.createTopic(topicName) subscriptionName = "subscription_001" // subscribe to topic sb.subscribe( topicName, { "subscriptionName" = subscriptionName } ) // get rules filterRuleTrue = { "type" = "true", "name" = "trueFilter" } sb.addSubscriptionRule(topicName, subscriptonName, filterRuleTrue) removeRuleResponse=sb.removeSubscriptionRule(topicName, subscriptonName, filterRuleTrue) </cfscript>
Syntax
getSubscriptionRules(String formattedSubscriptionPath)
You can schedule a message to a queue or topic. The message is enqueued into the bus to scheduled time message, the message is delivered to the receiver end. This is currently asynchronous process for better performance.
Syntax
scheduleMessageToQueue(String queuePath, Map metadata)
<cfscript> sb = getcloudService(this.serviceBusCred, this.serviceBusConf) // create a queue myQueue=sb.createQueue("Q_006") schedMessage={ "messageId" = "001", "messageBody" = "message body", "ScheduledEnqueueTimeUtc"="02/02/2020" } scheduleResponse=sb.scheduleMessageToQueue(myQueue, schedMessage) writeDump(scheduleResponse) </cfscript>
Syntax
scheduleMessageToTopic(String topicPath, Map metadata)
Syntax
cancelScheduledTopicMessage(String topicPath, long sequenceNumber)
Syntax
cancelScheduledQueueMessage(String queuePath, long sequenceNumber)
<cfscript> sb = getcloudService(this.serviceBusCred, this.serviceBusConf) qName = "cancel-scheduled-1msg2" delayInSecs = 30 msgCount = 1 // create a queue queue = sb.createQueue(qName) if(!listFindNoCase(qUtil.getQueuesListStr(sb), qName)) writeOutput("queue #qName# NOT created. This is NOT expected.<br>") else writeOutput("queue #qName# created successfully.<br>") messageArrayToSend = getMessageArray(msgCount) seqNo = scheduler.scheduleMessage(sb, qName, messageArrayToSend[1], delayInSecs) writeOutput("cancelling message with sequence no: #seqNo#<br>") cancelMessageResponse = sb.cancelScheduledMessage(qName, seqNo) if(cancelMessageResponse[statusCode] NEQ 200) writeOutput("error cancelling msg for #qName#, seqno. #seqNo#<br>") </cfscript>
The Peek method enumerates all messages that exist in the queue or subscription log, in a sequence, from the lowest to the highest.
Syntax
peekMessageFromQueue(String queuePath, Struct metadata)
<cfscript> sb = getcloudService(this.serviceBusCred, this.serviceBusConf) // create queue qName="queue-005" queue = sb.createQueue(qName) peekProperties = { "fromSequenceNumber" = 1, "messageCount" = 10 } peekResponse = sb.peekMessageFromQueue(queue.getPath(), peekProperties) receivedMsgArray = peekResponse.messages writeDump(receivedMsgArray) </cfscript>
Syntax
peekMessageFromSubscription(String topicPath, String subscriptionName, Struct metadata)
<cfscript> sb = getcloudService(this.serviceBusCred, this.serviceBusConf) qName = "q-msg-Peek-x4" msgCount = 3 msgLockDuration = 2 // create a queue queue=sb.createQueue(qName,{ "lockDuration"=msgLockDuration, "maxDeliveryCount"=msgCount }) // set peek properties peekProps = { "fromSequenceNumber" = 1, "messageCount" = msgCount } peekResponse = sb.peekMessage(queue.getPath(), peekProps) // array of size msgCount - 1 if(peekResponse[statusCode] == 200){ receivedMessages = peekResponse.messages writeOutput("received message deserialized:<br>") } else writeOutput("message browsing failed") </cfscript>
Sign in to your account