Official Content

This article contains an example that shows how to send messages to a Message Broker with the Message Broker API, using Azure Service Bus (Topic).


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 send the messages.
3. The SendMessages method returns a boolean result depending on the success of the execution and a variable of GeneXus.Common.Messages to process the errors.

Connecting to Azure Service Bus Topic 

The following code is the one used to connect to an Azure Service Bus Topic:

&brokerReceiverOptions = new() // BrokerReceiverOptions, AzureServiceBus
&brokerReceiverOptions .ReceiveMode = ReceiveModeOptions.ReceiveAndDelete

&MessageBroker = AzureServiceBus.MessageBrokerProvider.Connect(&topicName,&SubscriptionName,&connectionString,&IsSessionEnabled,&brokerReceiverOptions ,&senderIdentifier,&errorMessages,&success) 

if not &success
    msg(!"Connection failed", status)
    for &errorMessage in &errorMessages
        msg(format(!"%1 (%2)",&errorMessage.Description, &errorMessage.Id), status)

Sending a batch of messages

The following code is the one used for sending a batch of messages:

&Message = new() 
&Message.MessageId = GUID.NewGuid().ToString().Trim()
&Message.MessageBody = !"message body"

&MessageProperty = new()
&MessageProperty.PropertyKey = !"key1"
&MessageProperty.PropertyValue = !"Value1"

&MessageProperty = new()
&MessageProperty.PropertyKey = !"key2"
&MessageProperty.PropertyValue = !"Value2"



&success =  &MessageBroker.SendMessages(&Messages,"",&errorMessages)

//Process &errorMessages 

Variables defined in the samples

&brokerReceiverOptions BrokerReceiverOptions, AzureServiceBus
&MessageBroker MessageBroker, GeneXusMessagingMessageBroker
&MessageProperty MessageProperty, GeneXusMessagingMessageBroker


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