繁体   English   中英

如何使用python从Azure函数将消息发送到Azure中的队列?

[英]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软件包(例如pyodbcpymssql连接Azure SQL数据库,您需要在Azure Function上安装Python的自定义版本,然后为Python的自定义版本安装pip ,以根据需要安装这些软件包。

因此,步骤如下。

  1. 通过访问URL https://<your function name>.scm.azurewebsites.net/DebugConsole按照文档使用自定义版本的Python在Kudu的路径site\\tools中安装自定义Python运行时。
  2. 自定义python安装后,要将get-pip.py文件下载到自定义Python的路径site\\tool ,然后通过命令python get-pip.py安装pip工具。
  3. 然后,您可以通过Scripts/pip.exe install <package-names>安装这些软件包。

然后,您可以导入这些包以在Azure门户上的Azure函数中编写代码。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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