[英]How to do I send a message to a queue in Azure from an Azure function using python?
I am using an azure function that has a time trigger and I am trying to communication with a data base to return a list of dictionaries, I am trying to send each dictionary as a string (queue message) to a queue, I was going to do this with an output binder but could not figure out how to, so I am using the azure module. 我正在使用具有时间触发器的azure函数,并且尝试与数据库通信以返回字典列表,我试图将每个字典作为字符串(队列消息)发送到队列,我打算使用输出活页夹执行此操作,但不知道如何操作,因此我使用的是Azure模块。 Problem is every message I send goes into a poison queue for some reason, and I cannot figure out why, here is a code snippet of what I have in my Azure function. 问题是我发送的每条消息由于某种原因而进入中毒队列,而我不知道为什么,这是我的Azure函数中的代码片段。
import os
import platform
import WorkWithDatabase
#import base64
from azure.storage.queue import QueueService
acc='...ACCOUNT NAME'
key='...KEY'
#Connect to QueueService
queue_service = QueueService(account_name=acc, account_key=key)
#Pull missing data from the database,
#Call a function in another script to do this
missingList=WorkWithDatabase.ListRequests()
for item in missingList:
queue_service.put_message('taskqueue', str(item))
Also Is there a way I can use the database as a resource in an azure function with python?? 也有一种方法可以在python的azure函数中将数据库用作资源吗?
For using these python packages, such as pyodbc
or pymssql
to connect Azure SQL Database, you need to install a custom version of Python on Azure Function, then to install pip
for the custom verion of Python to install these package as you want. 为了使用这些python软件包(例如pyodbc
或pymssql
连接Azure SQL数据库,您需要在Azure Function上安装Python的自定义版本,然后为Python的自定义版本安装pip
,以根据需要安装这些软件包。
So the steps as below. 因此,步骤如下。
site\\tools
of Kudu via access the url https://<your function name>.scm.azurewebsites.net/DebugConsole
. 通过访问URL https://<your function name>.scm.azurewebsites.net/DebugConsole
按照文档使用自定义版本的Python在Kudu的路径site\\tools
中安装自定义Python运行时。 get-pip.py
file to the path site\\tool
of custom Python, then to install pip
tool via command python get-pip.py
. 自定义python安装后,要将get-pip.py
文件下载到自定义Python的路径site\\tool
,然后通过命令python get-pip.py
安装pip
工具。 Scripts/pip.exe install <package-names>
. 然后,您可以通过Scripts/pip.exe install <package-names>
安装这些软件包。 Then, you can import these packages to write your code in your Azure Function on Azure portal. 然后,您可以导入这些包以在Azure门户上的Azure函数中编写代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.