Send an Un-Serialized String to Azure Service Bus Queue or Topic

Posted: September 7, 2015  |  Categories: Azure Development Uncategorized
Tags:
 When I was doing some recent work with Azure Services Bus and the preview API App / Logic App, I ran into an issue with serialization of message content with the standard brokered message.

When you send a message will the brokered message client like below you end up with a serialized message in the service bus, when you try to read this message with the API app Azure Service Bus Connector, you must de-serialize the string before you can use it.

private void SendMessageToTopic(string inMessage)
        {
            string connectionString = CloudConfigurationManager.GetSetting("Microsoft.ServiceBus.ConnectionString");

            MessagingFactory factory = MessagingFactory.CreateFromConnectionString(connectionString);
            MessageSender testQueue = factory.CreateMessageSender("statement-processfile");

            BrokeredMessage message = new BrokeredMessage(inMessage);

            testQueue.Send(message);
        }
So if you want to just send a plain un-serialized string to the service bus you need to use the following code, this way processing the string in the API app Azure Service Bus Connector and your logic app is much easier.
        private void SendMessageToTopic(string inMessage)
        {
            string connectionString = CloudConfigurationManager.GetSetting("Microsoft.ServiceBus.ConnectionString");

            MessagingFactory factory = MessagingFactory.CreateFromConnectionString(connectionString);
            MessageSender testQueue = factory.CreateMessageSender("statement-processfile");

            Stream streamMessage = new MemoryStream(Encoding.UTF8.GetBytes(inMessage));
            BrokeredMessage message = new BrokeredMessage(streamMessage);

            testQueue.Send(message);
        }
Hope this help you send messages to the Azure Service Bus Queue and Topics so that you can use them in the Azure API App / Logic Apps

Ensure the reprocessing of messages in Service Bus is monitored and automated.

#1 Azure Monitoring Platform
turbo360

Back to Top