python - 使用 Python 从 Azure 服务总线主题检索消息属性

标签 python azure azureservicebus

使用 Python 2.7 我需要获取消息的属性。我知道该消息包含 3 个属性:cdId、active 和alarm:

在 C# 中,我有一个发送消息的客户端;

 string connectionString = CloudConfigurationManager.GetSetting("Microsoft.ServiceBus.ConnectionString");
            TopicClient newClient = TopicClient.CreateFromConnectionString(connectionString, "cdMessages");

 var serviceMsg = new BrokeredMessage("Alarm Deactive");
            serviceMsg.Properties["cdId"] = message.Properties["cdId"];
            serviceMsg.Properties["active"] = false;
            serviceMsg.Properties["alarm"] = false;
            newClient.Send(serviceMsg);

我已经订阅了,并且可以使用 python 接收消息,但我不知道如何获取消息的属性。

key_name = '******'
key_value ='******'
service_namespace1 = '******' 
sbs = ServiceBusService(service_namespace=service_namespace1,
                        shared_access_key_name=key_name,
                        shared_access_key_value=key_value)
Active = "active"
Deactive = "Deactivate"


 sbs.create_subscription('cdmessages', 'AllMessages')
 while True: 

msg = sbs.receive_subscription_message('cdmessages', 'AllMessages', peek_lock=False)
print(msg.body)
MessageString = str(msg.body)

if MessageString.find(Active) == True
    newState = "Activated"
    return(newState)

我可以让“激活”部分工作,因为我发送“警报停用”或“警报事件”作为消息文本,但这只是我为了让它至少部分工作而进行的黑客攻击。我需要能够读取属性。我已经尝试过 msg.properties 但返回错误,指出properties 属性不存在。

最佳答案

关于python - 使用 Python 从 Azure 服务总线主题检索消息属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26609263/

相关文章:

azure - 使用设置变量将字符串转换为 azure 数据工厂中的日期格式

azure - Terraform 如何轮换 Azure AD 应用程序 secret

c# - 在Azure上部署WCF服务,尝试访问数据库时超时

python - 如何在不运行 CLIrunner.invoke() 的情况下将输入传递给 click.confirm

python - 如何创建自定义 python 解释器?即已经包含某些模块?

python - Python中调用cls对象的构造函数

c# - 获取 Azure EventHub 的项目计数

c# - 如何使用c#创建microsoft azure服务总线队列?

azure - 从 0 个实例自动扩展云服务?

python - 删除Python中嵌套的bbcode引号?