Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Azure functions 事件网格触发函数在函数成功运行后是否继续触发?_Azure Functions_Azure Eventgrid - Fatal编程技术网

Azure functions 事件网格触发函数在函数成功运行后是否继续触发?

Azure functions 事件网格触发函数在函数成功运行后是否继续触发?,azure-functions,azure-eventgrid,Azure Functions,Azure Eventgrid,我有一个由事件网格事件触发的Azure函数。仅当blob上载到存储帐户时,才会创建事件网格事件 虽然出于某种原因,该函数一直被同一事件触发,即使它已成功处理,但它现在已部署并运行良好 示例: def main(event: func.EventGridEvent): result = json.dumps({ 'id' : event.id, 'data' : event.get_json(), 'topi

我有一个由事件网格事件触发的Azure函数。仅当blob上载到存储帐户时,才会创建事件网格事件

虽然出于某种原因,该函数一直被同一事件触发,即使它已成功处理,但它现在已部署并运行良好

示例:

def main(event: func.EventGridEvent):

        result = json.dumps({
            'id' : event.id,
            'data' : event.get_json(),
            'topic' : event.topic,
            'subject' : event.subject,
            'event_type' : event.event_type
        })

        logging.info('EventGrid trigger processing an event: %s', result)

        credential = DefaultAzureCredential()

        download_start_time = datetime.datetime.now()
        logging.info(f'######## Starting downloading blob from storage at ' + str(download_start_time) + ' ########')

        # =============================
        # Download blob from storage container:
        # =============================

        blob_client = BlobClient.from_blob_url(event.get_json()["url"], credential)
        blob_data = blob_client.download_blob().readall()
        blob_byte_stream = io.BytesIO(blob_data)
  • 昨天,8次成功测试;一切都好:

  • 今天我查看了日志,该功能继续执行

  • 错误:“Blob不存在”

  • 在昨天的最后一次测试之后,我删除了这个blob。为什么事件网格仍在启动?

代码片段:

def main(event: func.EventGridEvent):

        result = json.dumps({
            'id' : event.id,
            'data' : event.get_json(),
            'topic' : event.topic,
            'subject' : event.subject,
            'event_type' : event.event_type
        })

        logging.info('EventGrid trigger processing an event: %s', result)

        credential = DefaultAzureCredential()

        download_start_time = datetime.datetime.now()
        logging.info(f'######## Starting downloading blob from storage at ' + str(download_start_time) + ' ########')

        # =============================
        # Download blob from storage container:
        # =============================

        blob_client = BlobClient.from_blob_url(event.get_json()["url"], credential)
        blob_data = blob_client.download_blob().readall()
        blob_byte_stream = io.BytesIO(blob_data)
编辑1:这种情况仍在发生,这次有点不同。

  • 现在,EventGrid在成功传递消息和函数运行后继续启动
我如何调试它?


我终于找到了问题所在…使用
BlobClient。在使用Azure Storage Explorer测试blob上载时,from\u blob\u url
方法运行良好。但是当使用Azure Data Factory时,会使用不同的API,EventGrid消息中的
Data.url
属性不是实际的blob url(包含
dfs
而不是
blob

奇怪的是,在我将这个问题提交给支持团队后不久,一个新的
blobUrl
属性被添加到EventGrid
data
对象中

在我的代码中,我简单地将“url”更改为“blobUrl”,方法成功了。(我还改进了Python代码的错误处理,以在将来适应此类错误。)

EventGrid消息(截至2020年10月12日):

def main(event: func.EventGridEvent):

        result = json.dumps({
            'id' : event.id,
            'data' : event.get_json(),
            'topic' : event.topic,
            'subject' : event.subject,
            'event_type' : event.event_type
        })

        logging.info('EventGrid trigger processing an event: %s', result)

        credential = DefaultAzureCredential()

        download_start_time = datetime.datetime.now()
        logging.info(f'######## Starting downloading blob from storage at ' + str(download_start_time) + ' ########')

        # =============================
        # Download blob from storage container:
        # =============================

        blob_client = BlobClient.from_blob_url(event.get_json()["url"], credential)
        blob_data = blob_client.download_blob().readall()
        blob_byte_stream = io.BytesIO(blob_data)
  • blobUrl
    属性
现在收到的实际事件网格消息:

def main(event: func.EventGridEvent):

        result = json.dumps({
            'id' : event.id,
            'data' : event.get_json(),
            'topic' : event.topic,
            'subject' : event.subject,
            'event_type' : event.event_type
        })

        logging.info('EventGrid trigger processing an event: %s', result)

        credential = DefaultAzureCredential()

        download_start_time = datetime.datetime.now()
        logging.info(f'######## Starting downloading blob from storage at ' + str(download_start_time) + ' ########')

        # =============================
        # Download blob from storage container:
        # =============================

        blob_client = BlobClient.from_blob_url(event.get_json()["url"], credential)
        blob_data = blob_client.download_blob().readall()
        blob_byte_stream = io.BytesIO(blob_data)
  • 注意,
    blobUrl
    已添加到架构中
这里还有一个警告……注意上面消息中的
内容长度

  • CreateFile
    API不是指示已创建blob的实际消息
  • FlushWithClose
    API是
文档中有一条关于这一点的注释。因此,我还必须设置一个EventGrid高级过滤器,该过滤器仅在生成
FlushWithClose
事件时触发(!)


您的堆栈似乎有问题。您正在使用虚拟环境吗?你可以发布一些详细信息,比如你的测试代码吗?我在本地dev env中使用了
.venv
,但是这个函数是托管的,并在Azure中触发,而不是本地。我没有任何测试代码可以共享。该函数现在已停止触发,但我想了解将来如何调试此问题。好的……由于我们无法看到您的代码,我不确定原因。但是我看到有一个_download.py文件,你是想下载已经删除的blob吗?也许您应该检查一下。@EricOnline出于测试目的:设置maxDeliveryAttempts=3和死信,这将为您提供有关失败传递的更多详细信息,但这种情况仍在发生。这很烦人(特别是因为我们每个函数调用都要收费)。为什么EventGrid在成功传递消息后会一直启动?