Using Python 2.7 I need to get the properties of the message. I know the message contains 3 properties: cdId, active and alarm:
In C# I have this client which sends the message;
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);
I have made a subscription and I am able to receive the messages using python but I have no clue how to get the properties of the message.
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)
I can get the "activated" part working because I send "Alarm Deactive" or "Alarm Active" as the message text but the is just hack I made to get it at least working partially. I need to be able to read the properties. I have tried msg.properties but that returns with an error that the properties attribute doesn't exists.
dir(msg)give you?['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_queue_name', '_subscription_name', '_topic_name', 'add_headers', 'body', 'broker_properties', 'custom_properties', 'delete', 'location', 'service_bus_service', 'type', 'unlock']