简体   繁体   English

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

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

So the steps as below. 因此,步骤如下。

  1. Follow the document Using a custom version of Python to install a custom Python runtime in the path 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运行时。
  2. After custom python installation, to download a 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工具。
  3. Then, you can install these packages via 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.

相关问题 如何在 Python 中的 Azure 函数输出绑定的上下文中设置队列存储消息 TTL? - How can I set Queue Storage message TTL in the context of an Azure Function output binding in Python? 如何在Python中从Azure服务队列中查看C消息 - How to view c-message from azure service queue in Python 如何使用python快速将消息发送到azure队列存储? - How to quickly send messages to azure queue storage using python? 如何使用 Python 访问 Azure 中的队列消息? - How can I access queue messages in Azure using Python? Azure Functions :如何使用本地调试模式将日志写入 Azure Application Insights 和 Azure Functions 使用 Python? - Azure Function : How do I write my logs to Azure Application Insights using local debug mode with Azure Functions using Python? 单元测试 Python Azure Function:如何构造一个带有 Z0ECD18C1D7A2BB7A28 负载的模拟测试请求消息? - Unit testing Python Azure Function: How do I construct a mock test request message with a JSON payload? 如何修复 Azure Function (Python) 测试错误与 Http 触发器和队列消息 Z29C2C44725E - How To Fix Error For Test of Azure Function (Python) With Http Trigger and Queue Message Output 侦听来自Python的Web作业的Azure队列消息 - listen to azure queue message from python fro web job 使用 Azure 函数 (Python) 从 Azure EventHub 消息中检索传感器数据 - Retrieve sensor data from Azure EventHub Message with Azure Function (Python) 如何在 Azure Functions 中使用 FastAPI 发送文件响应? - how do i send a file response using FastAPI in Azure Functions?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM