Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove @strin3http//schemas.microsoft.com/2003/10/Serialization/� received from service bus queue received in python script?

I have set the output of Azure stream analytics job to service bus queue which sends the data in JSON serialized format. When I receive the queue message in python script, along with the data in curly braces, I get @strin3http//schemas.microsoft.com/2003/10/Serialization/� appended in front. I am not able to trim it as the received message is not being recognized as either a string or a message. Because of this I cannot de-serialize the data.

like image 571
Pooja Sethia Avatar asked Mar 30 '16 11:03

Pooja Sethia


2 Answers

This TechNet article suggests the following code:

// Get indices of actual message
var start = jsonString.IndexOf("{");
var end = jsonString.LastIndexOf("}") + 1;
var length = end - start;

// Get actual message
string cleandJsonString = jsonString.Substring(start, length);

Pretty primitive but whatever works I suppose...

like image 176
Ohad Schneider Avatar answered Oct 04 '22 04:10

Ohad Schneider


The issue was similiar with the SO thread Interoperability Azure Service Bus Message Queue Messages.

Per my experience, the data from Azure Stream Analytics to Service Bus was sent via AMQP protocol, but the protocol of receiving the data in Python is HTTP. The excess content was generated by AMQP during transmission.

Assumption that receiving the message via the code below, please see https://azure.microsoft.com/en-us/documentation/articles/service-bus-python-how-to-use-queues/#receive-messages-from-a-queue. The function receive_queue_message with the False value of the argument peek_lock wrapped the REST API Receive and Delete Message (Destructive Read).

msg = bus_service.receive_queue_message('taskqueue', peek_lock=False)
print(msg.body)

According to the source code of Azure Service Bus SDK for Python include the functions receive_queue_message, read_delete_queue_message and _create_message, I think you can directly remove the excess content from the msg.body using the string common function lstrip or strip.

like image 39
Peter Pan Avatar answered Oct 04 '22 04:10

Peter Pan