Open In App

Messaging Via Azure Service bus | SendMessage and ScheduleMessage

In this section, we are going to discuss in brief about the data transfer methods to transfer data across Azure topics via service bus pooling. We can either send a normal message or a schedule based message. We will walk through each of these two basic type of messaging.

Azure Service Bus: Microsoft Azure Service Bus is a fully managed enterprise integration messaging service on cloud used to connect any applications, devices, and services running in the cloud to any other applications or services. This platform acts as a messaging backbone for applications over cloud and across any devices.



How does it work ? Data is transferred between different applications and services using messages. A message is in binary format and can contain JSON, XML, or just text. These messages are placed on to the service bus the application is connected with, so that all or specific users connected on, with this application, over the socket service connection open can receive the data transferred over the service bus.

Types of messaging: Data Messages transferred over the Azure service bus can be made of two major types, whether the data need to be sent on a specific schedule or is that required to be sent on immediate basis. Here we will discuss in detail about both these process of messaging. Each of these has its own specific methods for invoking the messaging process.



Bug Fix:




import { DefaultDataTransformer }
            from "@azure/amqp-common";
...
...
  
const dt = new DefaultDataTransformer();
  
const sequenceId = await sender.scheduleMessage(
        scheduledEnqueueTimeUtc,
        {body: dt.encode(JSON.stringify(content)),
        label: "MyTopic"});
  
response = sequenceId.toString();

Now you will receive the proper sequenceId, which you can use to cancel the message if required in the future using the following code piece.

CancelMessage: This method deleted the message placed in the service bus early using the scheduleMessage call. We need to send the sequenceNumber returned during the call as the only parameter for this method invocation. If the message is already delivered then we receive an error MessageNotFound which needs to be handled in the catch.

Prototype:

cancelScheduledMessage( long sequenceNumber )

Thus we have covered how we can communicate data by using the above two methods and placing the data requests either via a scheduled basis or non scheduled manner.


Article Tags :