不知道Azure函数是否正在记录任何事件,Python中的本地开发VS代码

我正在尝试开发Azure功能以与IoTHub进行交互。我正在使用Python版本3.7.8中的Visual Studio Code 1.47.2进行本地开发。该函数是版本2,并使用Azure Functions核心工具2.7.2628。对于开发,我使用的是Azure存储模拟器5.10.0.0

我所做的是使用EventHub触发器在python中创建默认项目。然后修改以下文件:

function.json
{
  "scriptFile": "__init__.py","bindings": [
    {
      "type": "eventHubTrigger","name": "event","direction": "in","eventHubName": "IoTHubName",#Got from the Event Hub-compatible name in Build-in endpoints
      "connection": "IoTHubConnectionString",#Got from Event Hub-compatible endpoint
      "cardinality": "many","consumerGroup": "$Default","dataType": "binary"
    }
  ]
}
local.setting.json
{
  "IsEncrypted": false,"Values": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true","FUNCTIONS_WORKER_RUNTIME": "python","eventHubConnectionString": "here the Event Hub-compatible endpoint"
  }
}

我首先要查看该功能是否正常工作,我为此功能使用了以下代码:

_init_.py
from typing import List
import logging

import azure.functions as func


def main(event: func.EventHubEvent):
    logging.info('Python EventHub trigger processed an event: %s',event.get_body().decode('utf-8'))

我用F5启动调试,终端显示以下内容:

> Executing task: .venv\Scripts\python -m pip install -r requirements.txt <

Requirement already satisfied: azure-functions in c:\...\pythontries\pyfuncappeventhub1\.venv\lib\site-packages (from -r requirements.txt (line 1)) (1.3.0)

Terminal will be reused by tasks,press any key to close it.

> Executing task: .venv\Scripts\activate ; func host start <

Found Python version 3.7.8 (py).

                  %%%%%%
                 %%%%%%
            @   %%%%%%    @
          @@   %%%%%%      @@
       @@@    %%%%%%%%%%%    @@@
     @@      %%%%%%%%%%        @@
       @@         %%%%       @@
         @@      %%%       @@
           @@    %%      @@
                %%
                %

Azure Functions Core Tools (2.7.2628 Commit hash: 42e149f5313330f1f0a5e721a7e59d9ef7d27e6f)
Function Runtime Version: 2.0.13907.0
AZURE_FUNCTIONS_ENVironMENT: Development
[22.07.2020 10:07:12] Building host: startup suppressed: 'False',configuration suppressed: 'False',startup operation id: 'somecode'
[22.07.2020 10:07:12] Reading host configuration file 'C:...\host.json'
[22.07.2020 10:07:12] Host configuration file read:
[22.07.2020 10:07:12] {
[22.07.2020 10:07:12]   "version": "2.0",[22.07.2020 10:07:12]   "logging": {
[22.07.2020 10:07:12]     "applicationInsights": {
[22.07.2020 10:07:12]       "samplingSettings": {
[22.07.2020 10:07:12]         "isEnabled": true
[22.07.2020 10:07:12]       }
[22.07.2020 10:07:12]     }
[22.07.2020 10:07:12]   },[22.07.2020 10:07:12]   "extensionBundle": {
[22.07.2020 10:07:12]     "id": "microsoft.Azure.Functions.ExtensionBundle",[22.07.2020 10:07:12]     "version": "[1.*,2.0.0)"
[22.07.2020 10:07:12]   }
[22.07.2020 10:07:12] }
[22.07.2020 10:07:12] FUNCTIONS_WORKER_RUNTIME set to python. Skipping WorkerConfig for language:java
[22.07.2020 10:07:12] FUNCTIONS_WORKER_RUNTIME set to python. Skipping WorkerConfig for language:node
[22.07.2020 10:07:12] FUNCTIONS_WORKER_RUNTIME set to python. Skipping WorkerConfig for language:powershell
[22.07.2020 10:07:12] Loading functions metadata
[22.07.2020 10:07:12] Reading functions metadata
[22.07.2020 10:07:12] 1 functions found
[22.07.2020 10:07:12] 1 functions loaded
[22.07.2020 10:07:12] Looking for extension bundle microsoft.Azure.Functions.ExtensionBundle at C:\...\AppData\Local\Temp\Functions\ExtensionBundles\microsoft.Azure.Functions.ExtensionBundle
[22.07.2020 10:07:12] Found a matching extension bundle at C:\...\AppData\Local\Temp\Functions\ExtensionBundles\microsoft.Azure.Functions.ExtensionBundle\1.3.0
[22.07.2020 10:07:12] Fetching information on versions of extension bundle microsoft.Azure.Functions.ExtensionBundle available on https://functionscdn.azureedge.net/public/ExtensionBundles/microsoft.Azure.Functions.ExtensionBundle/index.json
[22.07.2020 10:07:13] Skipping bundle download since it already exists at path C:\...\AppData\Local\Temp\Functions\ExtensionBundles\microsoft.Azure.Functions.ExtensionBundle\1.3.0
[22.07.2020 10:07:13] Loading extension bundle from C:\...\AppData\Local\Temp\Functions\ExtensionBundles\microsoft.Azure.Functions.ExtensionBundle\1.3.0
[22.07.2020 10:07:13] Loading startup extension 'EventHubs'
[22.07.2020 10:07:13] Loaded extension 'EventHubs' (3.0.6.0)
[22.07.2020 10:07:13] FUNCTIONS_WORKER_RUNTIME set to python. Skipping WorkerConfig for language:java
[22.07.2020 10:07:13] FUNCTIONS_WORKER_RUNTIME set to python. Skipping WorkerConfig for language:node
[22.07.2020 10:07:13] FUNCTIONS_WORKER_RUNTIME set to python. Skipping WorkerConfig for language:powershell
[22.07.2020 10:07:13] Initializing Warmup Extension.
[22.07.2020 10:07:13] Initializing Host. OperationId: 'somecode'.
[22.07.2020 10:07:13] Host initialization: ConsecutiveErrors=0,StartupCount=1,OperationId=somecode
[22.07.2020 10:07:13] LoggerFilterOptions
[22.07.2020 10:07:13] {
[22.07.2020 10:07:13]   "MinLevel": "None",[22.07.2020 10:07:13]   "Rules": [
[22.07.2020 10:07:13]     {
[22.07.2020 10:07:13]       "ProviderName": null,[22.07.2020 10:07:13]       "CategoryName": null,[22.07.2020 10:07:13]       "LogLevel": null,[22.07.2020 10:07:13]       "Filter": "<AddFilter>b__0"
[22.07.2020 10:07:13]     },[22.07.2020 10:07:13]     {
[22.07.2020 10:07:13]       "ProviderName": "microsoft.Azure.WebJobs.Script.WebHost.Diagnostics.SystemLoggerProvider",[22.07.2020 10:07:13]       "LogLevel": "None",[22.07.2020 10:07:13]       "Filter": null
[22.07.2020 10:07:13]     },[22.07.2020 10:07:13]       "Filter": "<AddFilter>b__0"
[22.07.2020 10:07:13]     }
[22.07.2020 10:07:13]   ]
[22.07.2020 10:07:13] }
[22.07.2020 10:07:13] FunctionResultAggregatorOptions
[22.07.2020 10:07:13] {
[22.07.2020 10:07:13]   "BatchSize": 1000,[22.07.2020 10:07:13]   "FlushTimeout": "00:00:30",[22.07.2020 10:07:13]   "IsEnabled": true
[22.07.2020 10:07:13] }
[22.07.2020 10:07:13] SingletonOptions
[22.07.2020 10:07:13] {
[22.07.2020 10:07:13]   "LockPeriod": "00:00:15",[22.07.2020 10:07:13]   "ListenerLockPeriod": "00:00:15",[22.07.2020 10:07:13]   "LockAcquisitionTimeout": "10675199.02:48:05.4775807",[22.07.2020 10:07:13]   "LockAcquisitionPollingInterval": "00:00:05",[22.07.2020 10:07:13]   "ListenerLockRecoveryPollingInterval": "00:01:00"
[22.07.2020 10:07:13] }
[22.07.2020 10:07:13] Httpoptions
[22.07.2020 10:07:13] {
[22.07.2020 10:07:13]   "DynamicThrottlesEnabled": false,[22.07.2020 10:07:13]   "MaxConcurrentRequests": -1,[22.07.2020 10:07:13]   "MaxOutstandingRequests": -1,[22.07.2020 10:07:13]   "RoutePrefix": "api"
[22.07.2020 10:07:13] }
[22.07.2020 10:07:13] EventHubOptions
[22.07.2020 10:07:13] {
[22.07.2020 10:07:13]   "BatchCheckpointFrequency": 1,[22.07.2020 10:07:13]   "EventProcessorOptions": {
[22.07.2020 10:07:13]     "EnableReceiverRuntimeMetric": false,[22.07.2020 10:07:13]     "InvokeProcessorAfterReceiveTimeout": false,[22.07.2020 10:07:13]     "MaxBatchSize": 10,[22.07.2020 10:07:13]     "PrefetchCount": 300,[22.07.2020 10:07:13]     "ReceiveTimeout": "00:01:00"
[22.07.2020 10:07:13]   },[22.07.2020 10:07:13]   "PartitionmanagerOptions": {
[22.07.2020 10:07:13]     "LeaseDuration": "00:00:30",[22.07.2020 10:07:13]     "RenewInterval": "00:00:10"
[22.07.2020 10:07:13]   }
[22.07.2020 10:07:13] }
[22.07.2020 10:07:13] Starting JobHost
[22.07.2020 10:07:13] Starting Host (HostId=somecode,InstanceId=somecode,Version=2.0.13907.0,ProcessId=somecode,AppDomainId=1,InDebugMode=False,InDiagnosticMode=False,FunctionsExtensionVersion=(null))
[22.07.2020 10:07:13] Loading functions metadata
[22.07.2020 10:07:13] Loading proxies metadata
[22.07.2020 10:07:13] Initializing Azure Function proxies
[22.07.2020 10:07:14] 0 proxies loaded
[22.07.2020 10:07:14] 1 functions loaded
[22.07.2020 10:07:14] Starting worker process:py  c:/U.../.vscode/extensions/ms-python.python-2020.7.94776/pythonFiles/lib/python/debugpy --listen 127.0.0.1:9091 --wait-for-client "C:\programdata\chocolatey\lib\azure-functions-core-tools\tools\workers\python\3.7/WINDOWS/X64/worker.py" --host 127.0.0.1 --port 51794 --workerId somecode --requestId somecode --grpcMaxMessageLength 2147483647
[22.07.2020 10:07:14] py process with Id=19880 started
[22.07.2020 10:07:14] Generating 1 job function(s)
[22.07.2020 10:07:14] Found the following functions:
[22.07.2020 10:07:14] Host.Functions.pyEventHubTrigger1
[22.07.2020 10:07:14]
[22.07.2020 10:07:14] Initializing function HTTP routes
[22.07.2020 10:07:14] No HTTP routes mapped
[22.07.2020 10:07:14]
[22.07.2020 10:07:14] Host initialized (768ms)
[22.07.2020 10:07:16] Host started (2577ms)
[22.07.2020 10:07:16] Job host started
Hosting environment: Development
Content root path: C:\...\pythonTries\pyFuncAppEventHub1
Now listening on: http://0.0.0.0:7071
Application started. Press Ctrl+C to shut down.
[22.07.2020 10:07:21] Host lock lease acquired by instance ID '000000000000000000000000F61C9814'.
[22.07.2020 10:07:22]  INFO: Starting Azure Functions Python Worker.
[22.07.2020 10:07:22]  INFO: Worker ID: somecode,Request ID: somecode,Host Address: someaddress
[22.07.2020 10:07:22]  INFO: Successfully opened gRPC channel to someaddress
[22.07.2020 10:07:22]  INFO: Detach console logging. Switch to gRPC logging
[22.07.2020 10:07:22] Detach console logging. Switch to gRPC logging
[22.07.2020 10:07:22]  INFO: Received WorkerInitRequest,request ID somecode
[22.07.2020 10:07:22] Received WorkerInitRequest,request ID somecode
[22.07.2020 10:07:22]  INFO: Received FunctionLoadRequest,request ID: somecode,function ID: somecode
[22.07.2020 10:07:22] Received FunctionLoadRequest,function ID: somecode
[22.07.2020 10:09:32]  INFO: Successfully processed FunctionLoadRequest,function ID: somecode
[22.07.2020 10:09:35] Successfully processed FunctionLoadRequest,request ID: 6somecode,function ID: somecode

我启动了一个将遥测消息发送到集线器的c#模拟器,我可以看到在Azure门户中收到的消息,但是该功能没有显示任何logg。我已经尝试了4天,但没有找到成功解决此类问题的任何示例或解决方案。我希望你能帮助我。

iCMS 回答:不知道Azure函数是否正在记录任何事件,Python中的本地开发VS代码

更新。我也检查了门户,但遇到了同样的问题。我意识到我的IoT中心有一条到存储Blob的路由,并读到此article,如果存在现有路由,则该中心中的内置终结点将不起作用。我禁用了到存储的路由,并且能够使用该功能记录来自IoT中心的消息。在门户和vs代码中。我在python代码上有一些错误的引用,但是我尝试使用c#脚本(我做了更多工作),并且能够看到我的日志!希望对您有所帮助。我认为我应该在EventGrid中创建一个主题,以与存储路由并行地调用我的函数。enter image description here

本文链接:https://www.f2er.com/1887490.html

大家都在问