1

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.

3
  • 1
    What does dir(msg) give you? Commented Oct 28, 2014 at 13:15
  • It returns: ['__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'] Commented Oct 28, 2014 at 13:22
  • It turns out: 'custom_properties' contains the properties of the message I created Commented Oct 28, 2014 at 13:24

1 Answer 1

1

In the v7 of the azure-servicebus, you can utilize the application_properties.

https://learn.microsoft.com/en-us/python/api/azure-servicebus/azure.servicebus.servicebusmessage?view=azure-python

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.