[英]How can I set Queue Storage message TTL in the context of an Azure Function output binding in Python?
[英]How to do I send a message to a queue in Azure from an Azure function using python?
我正在使用具有时间触发器的azure函数,并且尝试与数据库通信以返回字典列表,我试图将每个字典作为字符串(队列消息)发送到队列,我打算使用输出活页夹执行此操作,但不知道如何操作,因此我使用的是Azure模块。 问题是我发送的每条消息由于某种原因而进入中毒队列,而我不知道为什么,这是我的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))
也有一种方法可以在python的azure函数中将数据库用作资源吗?
为了使用这些python软件包(例如pyodbc
或pymssql
连接Azure SQL数据库,您需要在Azure Function上安装Python的自定义版本,然后为Python的自定义版本安装pip
,以根据需要安装这些软件包。
因此,步骤如下。
https://<your function name>.scm.azurewebsites.net/DebugConsole
按照文档使用自定义版本的Python在Kudu的路径site\\tools
中安装自定义Python运行时。 get-pip.py
文件下载到自定义Python的路径site\\tool
,然后通过命令python get-pip.py
安装pip
工具。 Scripts/pip.exe install <package-names>
安装这些软件包。 然后,您可以导入这些包以在Azure门户上的Azure函数中编写代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.