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
BizTalk360
BizTalk Server

Over 500+ customers across
30+ countries depend on BizTalk360

Learn More
Serverless360
Azure

Manage and monitor serverless
components effortlessly

Learn More
Atomicscope
Business Users

Monitor your Business Activity in iPaaS
or Hybrid integration solutions

Learn More

Back to Top