Sunday, 30 September 2018

Send to Azure Service Bus in #MSDyn365FO

Sending a message to Azure Service Bus is really simple in FinOps.

Below is the job I wrote to send a message to the service bus. It takes a connection string and a queue name for connecting. The message string and key value pair list can be supplied to the properties.

    static str connectionString = 'Endpoint=sb://;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=h5KwXSEFIHxxxxxxxxxxxxxxxxxx';
    static str queueName = 'navaxqueue';

    /// <summary>
    /// Runs the class with the specified arguments.
    /// </summary>
    /// <param name = "_args">The specified arguments.</param>
    public static void main(Args _args)
        if (connectionString && queueName)
            Microsoft.ServiceBus.Messaging.QueueClient queueClient = Microsoft.ServiceBus.Messaging.QueueClient::CreateFromConnectionString(connectionString, queueName);
            Microsoft.ServiceBus.Messaging.BrokeredMessage brokeredMessage = new Microsoft.ServiceBus.Messaging.BrokeredMessage("My Message");
            var properties = brokeredMessage.Properties;

            properties.Add("MyKey1", "MyValue1");
            properties.Add("MyKey2", "MyValue2");

Using Service Bus Explorer you can see the result.


At the moment Microsoft is working on event based triggers. One of the possible solutions they presented was writing to the service bus. Looking forward to it.

I took inspiration from one of the standard classes I noticed in in 8PU15. It subscribes to the insert/delete of a user record to send the user detail to a service bus. The big bonus is that service bus assembles are included on the machine. I won’t dive any deeper into this class in this blog post.



MikS said...

Hi Munib!

First of all, thanks for your post, it's very helpful.
However, I have one question. How can you use "Microsoft.ServiceBus.Messaging"?
It's necessary to add some package on solution?

Thank you!

Munib Ahmed said...

Hi MikS,
I don't understand what you are asking. Can you elaborate?

MS Azure said...
This comment has been removed by a blog administrator.