I am an absolute beginner with Service Bus. I want to understand the implementation of a queue using python. The documentation tells me to install Azure Python SDK. I've done that.I made the python file as per instructions, yet I am getting syntax error. I ran the file on the python shell. Did I do that right? How do I know that the Azure Package is being used?
-
put some effort what you have done actually. – Gahan Jun 03 '17 at 12:18
-
Please post your current code and the syntax error you got here. – Peter Pan Jun 05 '17 at 12:45
1 Answers
As you said, you got a syntax error, it sounds like the issue you got was caused by a Python usage problem, not be related to Azure Service Bus SDK for Python. Without your python code, I don't know what happended in your code. Just as reference, I post some steps for using Azure Python SDK to connect Azure Service Bus.
- Install Azure Service Bus SDK for Python via pip in a console. Open a console like CMD on Windows or terminal on Linux, type & enter
pip install azure-servicebus
if you had installed Python environment and configure it withinPATH
environment variable. If you were using a linux distribution like Ubuntu, it may be necessary to first typesudo
at the front of the pip command. - Copy the servicebus namespace & the primary key for the policy name
RootManageSharedAccessKey
on Azure portal to be ready for using it in your python script. Write your python script to connect Service Bus as below.
from azure.servicebus import ServiceBusService key_name = 'RootManageSharedAccessKey' # SharedAccessKeyName from Azure portal key_value = '' # SharedAccessKey from Azure portal sbs = ServiceBusService(service_namespace, shared_access_key_name=key_name, shared_access_key_value=key_value)
Then you can use
sbs
to do other operations, such as create a queue viasbs.create_queue('taskqueue')
, or send message via the code below.from azure.servicebus import Message msg = Message('Hello World!') sbs.send_queue_message('taskqueue', msg)
In the console, you can type
python <your script name>.py
to run it. If got any error, please update your post to let me know.
You can refer to the documents listed below to know the steps above.
- How to use Service Bus queues in Python
- How to use Service Bus topics and subscriptions in Python
- Introduction for the usage of the service bus in Azure Python SDK
- The usage of Python package
azure-servicebus
Hope it helps. Any concern, please feel free to let me know.

- 23,476
- 4
- 25
- 43