How to receive JSON object from the azure service bus topic subscriptions


  • Hi everyone,

     I have few doubt about to implement azure service bus receive messages from topic subscriptions. 

    We are using multiple applications in our organization and we need to share data between one to other subsystems so that we are using azure service bus. Here one of my application has sent a message frequently to the service bus topic subscription. Whenever a new user account is created in our application every time the user profile data will be sending the data to the corresponding service bus topic subscriptions. I have mentioned below the snapshot which I have to receive the JSON object. That <g class="gr_ gr_67 gr-alert gr_gramm Grammar multiReplace" data-gr-id="67" id="67">the message</g> is a JSON object.

    JSON object:


    Now I’m going to receive those JSON object which I have already sent to the azure service bus topic subscriptions queue before moving to the deadletter. 

    JSON objects can be stored a list of JSON objects on the subscription. I have searched lots of examples I could not able to find an appropriate solution. Please let me share your suggestion How can I receive the list of JSON objects? I'll be waiting for your response. 




    • Moved by DotNet Wang Friday, February 03, 2017 2:47 AM
    Thursday, February 02, 2017 3:33 PM

All replies

  • Hi Parthiban,

    Based on your description, your case more related to Azure service bus, I will help move your case to Microsoft Azure  > Service Bus forum for better support.

    Best regards,

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Friday, February 03, 2017 2:46 AM
  • There are several ways to do this.

    If you are using full .net framework, you can use following constructor:

    var msg = new BrokeredMessage(null, serializer);

    where ser:

    var ser = new DataContractJsonSerializer(typeof(object));


    var ser = new DataContractSerializer(typeof(object));

    The later one is default one. This is why your messages are XML serialized.

    However following approach can be more interesting. It is a bit more complicate but it give you a chance to manipulate format and encoding:

          string strMsg = JsonConvert.SerializeObject(anySerializableObject);
           BrokeredMessage msg = new BrokeredMessage(new MemoryStream(UTF8Encoding.UTF8.GetBytes(strMsg)));

          await this.m_QueueClient.SendAsync(msg);

    . . .


     cmdReceiver.OnMessage((msg) =>

               var data = msg.GetBody<Stream>();
               byte[] buff = new byte[data.Length];
               data.Read(buff, 0, (int)data.Length);

               var anySerializableObject = Encoding.UTF8.GetString(buff);


    By using of this approach, it does not matter, if you have a list plain object or anything else. As long it is serializable it will work. 

    Damir Dobric

    Saturday, March 18, 2017 12:20 PM