![](/img/trans.png)
[英]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.