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

    Question

  • 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:

    {"id":"N322333","firstName":"adsdddd","lastName":"asddd","email":"hello@gmail.com123ZXc","emailVerified":false,"dateOfBirth":"2016-08-03","login":"qqqqqqqqqq","password":"Pass@1234","homePhone":"233322","mobilePhone":"1111111122asdf","workPhone":"22222","gender":1,"centerId":"I23642","userType":"student","staffRole":null,"staffActive":false}

    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. 

    Regards,

    Parthiban.



    Parthiban

    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 MSDNFSF@microsoft.com.

    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));

    of

    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:
    SENDER:

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

          await this.m_QueueClient.SendAsync(msg);

    . . .

    RECEIVER:

     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
    developers.de
    daenet.de
    daenet.eu
    daenet.com


    Saturday, March 18, 2017 12:20 PM