![](/img/trans.png)
[英]Setting Broker properties on an Azure Service bus message - python
[英]Retrieve message properties from Azure Service bus topics withn Python
使用 Python 2.7 我需要獲取消息的屬性。 我知道該消息包含 3 個屬性:cdId、活動和警報:
在 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 屬性不存在。
在 azure-servicebus 的 v7 中,您可以使用application_properties
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.