This article contains an example that shows how to schedule a message in Azure Service Bus.
The code consists of the following:
1. Connect to the Azure Service Bus using the AzureServiceBus.MessageBrokerProvider external object.
2. The Connect method returns a MessageBroker external object that should be used to schedule the message.
3. Use the ScheduleMessage method, passing to it ScheduleMessageOptions. The method returns the message SequenceNumber, to be able to cancel it later.
The following code is the one used to connect to an Azure Service Bus Queue:
&MessageBroker = AzureServiceBus.MessageBrokerProvider.Connect(&queueName,&queueConnection,&errorMessages,&isOK)
The following code is the one used for sending a message to be scheduled:
&Message = new()
&Message.MessageId = GUID.NewGuid().ToString()
&Message.MessageBody = !"message body"
&MessageProperty = new()
&MessageProperty.PropertyKey = !"propKey1"
&MessageProperty.PropertyValue = !"propValue1"
&Message.MessageAttributes.Add(&MessageProperty)
&MessageProperty = new()
&MessageProperty.PropertyKey = !"propKey2"
&MessageProperty.PropertyValue = !"propValue2"
&Message.MessageAttributes.Add(&MessageProperty)
//Broker Properties
&MessageProperty = new()
&MessageProperty.PropertyKey = !"subject"
&MessageProperty.PropertyValue = !"Subject of message"
&Message.MessageAttributes.Add(&MessageProperty)
//SEND
&datetime = Datetime.Now()
&ScheduleMessageOptions.ScheduledEnqueueTime = &datetime.AddMinutes(60)
&sequenceNumber = &MessageBroker.ScheduleMessage(&Message,&ScheduleMessageOptions.ToJson(),&errorMessages)
if &sequenceNumber = 0
for &errorMessage in &errorMessages
msg(format(!"%1 (%2)",&errorMessage.Description, &errorMessage.Id), status)
endfor
else
msg(!"sequenceNumber scheduled:" + &sequenceNumber, status)
endif
To cancel the schedule, use:
&isOK= &MessageBroker.CancelSchedule(&sequenceNumber,&errorMessages)
//Process &errorMessages
&MessageBroker.Dispose()