Official Content

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.

Connecting to Azure Service Bus Queue

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)

Receiving messages from the Service Bus Queue

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

Variables defined in the example

&brokerReceiverOptions BrokerReceiverOptions, AzureServiceBus
&MessageBroker MessageBroker, GeneXusMessagingMessageBroker
&receiveMessageOptions ReceiveMessageOptions, AzureServiceBus
&MessageCollection Message (Collection), GeneXusMessagingMessageBroker


Last update: January 2024 | © GeneXus. All rights reserved. GeneXus Powered by Globant