With the Message Broker API, you can send and receive messages from a Message Broker. This article contains an example that shows how to receive messages from Azure Service Bus Queue.
The process 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 receive the messages.
3. The ReceiveMessages method returns a collection of Messages and a variable of GeneXus.Common.Messages to process the errors.
The following code is the one used to connect to an Azure Service Bus Queue:
&brokerReceiverOptions = new()
&brokerReceiverOptions.PrefetchCount = 10
&MessageBroker = AzureServiceBus.MessageBrokerProvider.Connect(&queueName,&queueConnection,&isSessionEnabled,&brokerReceiverOptions,&senderIdentifier,&errorMessages,&isOK)
if not &isOK
for &errorMessage in &errorMessages
msg(format(!"%1 (%2)",&errorMessage.Description, &errorMessage.Id), status)
endfor
endif
The following code is the one used for receiving messages from the Azure Service Bus Queue:
&receiveMessageOptions.MaxMessages = 100
&receiveMessageOptions.MaxWaitTime = 10
&MessageCollection = &MessageBroker.ReceiveMessages(&receiveMessageOptions.ToJson(), &errorMessages,&success)
//Process &errorMessages
&MessageBroker.Dispose()