Azure服务总线python客户端问题 [英] Azure service bus python client issue

查看:106
本文介绍了Azure服务总线python客户端问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我第一次使用Azure服务总线在C#源和python客户端之间传输消息.

I am using azure service bus for the first time to transfer message between C# source and python client.

我正在创建ServiceBusService对象,并使用它从功能 receive_subscription_message 中获取消息.

I am creating ServiceBusService object and using it i fetch message from function receive_subscription_message.

我得到的有效载荷与预期不符.

The payload i get is not as expected.

我的代码如下.

bus_service = ServiceBusService(service_namespace="service_namespace", shared_access_key_name="All", shared_access_key_value="password")
msg = bus_service.receive_subscription_message('test', 'test', peek_lock=True)
print(msg.body)
msg.delete()

msg.body给出一个字节字符串,如下所示: b'@\x06string\x083http://schemas.microsoft.com/2003/10/Serialization/\x9ae\x0c{"PUID":"3NFLzV3cjCp8f5JLh3KSnkXDgSw1FWgM","HardDelete":null}\x01'

msg.body gives a byte string like below: b'@\x06string\x083http://schemas.microsoft.com/2003/10/Serialization/\x9ae\x0c{"PUID":"3NFLzV3cjCp8f5JLh3KSnkXDgSw1FWgM","HardDelete":null}\x01'

最初将json推送到其中. 有什么办法可以避免额外的参数,而只获取原始的json?

Originally json was pushed in it. Is there any way to avoid additional parameters and fetch original json only?

推荐答案

问题是由在另一端使用的不同协议引起的:使用AMQP或默认.NET序列化行为的C#发送者,以及通过REST API使用Python的接收者HTTP.您可以参考文档 源Python Python Service Bus SDK的代码知道这一点,我已经在另一个SO线程

The issue was caused by the different protocol used at the different side: sender in C# using AMQP or default .NET serialization behavior and receiver in Python using REST API via HTTP. You can refer to the document Using Service Bus from .NET with AMQP 1.0 and the source code of Azure Python Service Bus SDK to know that, and I had explained the similar issue in the other SO thread Interoperability Azure Service Bus Message Queue Messages.

要避免使用其他参数并仅获取原始json,可以尝试以下两种方法.

To avoid additional parameters and fetch original json only, there are two ways which you can try, as below.

  1. 使用 REST API 通过C#中的HTTP通过HTTP发送原始json,而没有来自AMQP的任何其他内容或默认的.NET序列化行为.
  2. 在Python中使用 python-qpid-proton 包通过AMQP接收消息反序列化并获取原始json.
  3. 在当前情况下,由于每条消息具有相同的附加内容,因此只需从消息中删除附加内容以提取原始json.
  1. Using REST API via HTTP in C# to send original json without any additional content from AMQP or default .NET serialization behavior。
  2. Using python-qpid-proton package in Python to receiver message with AMQP to deserialize and get the original json.
  3. Under the current case, just remove the addition content from the messages to extract the origin json, due to there is the same addition content per message.

希望有帮助.

这篇关于Azure服务总线python客户端问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆