简体   繁体   中英

Implementation of a queue in Azure service bus using python

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?

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.

  1. 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 within PATH environment variable. If you were using a linux distribution like Ubuntu, it may be necessary to first type sudo at the front of the pip command.
  2. 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.
  3. 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 via sbs.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) 
  4. 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.

  1. How to use Service Bus queues in Python
  2. How to use Service Bus topics and subscriptions in Python
  3. Introduction for the usage of the service bus in Azure Python SDK
  4. The usage of Python package azure-servicebus

Hope it helps. Any concern, please feel free to let me know.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM