【问题标题】:How to view actual Azure Event Grid message?如何查看实际的 Azure 事件网格消息?
【发布时间】:2021-01-20 20:38:47
【问题描述】:

我有一个由EventGridEvents 触发的 Azure 函数。

  • function.json 相应设置:
{
    "scriptFile": "__init__.py",
    "bindings": [{
        "name": "event",
        "type": "eventGridTrigger",
        "direction": "in"
    }]
}
  • __init__.py 拨入(此处仅显示 sn-p):
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
        })
  • 函数部署成功
  • EventGrid 触发器创建成功
  • 我在这里成功发布了EventGrid消息:

  • 但函数从未触发。

我现在想查看实际的EventGrid 消息并调试函数未触发的原因,但我找不到查看消息的位置!

我等了大约 30 分钟,多次刷新,甚至正在观看 AppInsights 实时日志,没有触发。

  1. EventGrid 消息成功发布后在哪里查看
  2. 我应该如何调试这个函数?

编辑 1:

挖掘了一段时间,我发现了另一个显示 0 Delivered Events

的“指标”

事件如何“发布”而不是“交付”?

【问题讨论】:

  • 你在关注下面的教程吗?因为您的问题似乎是您的函数没有监控正确的 Eventhub,所以 Message 或 FunctionName 是错误的。 BindingTutorialCode Sample

标签: azure-functions azure-eventgrid


【解决方案1】:

我做了一个测试。在我这边似乎没有问题。

也许你和我的有些不同。

请检查:

_init_.py

import json
import logging

import azure.functions as func


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('Python EventGrid trigger processed an event: %s', result)

function.json

{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "type": "eventGridTrigger",
      "name": "event",
      "direction": "in"
    }
  ]
}

这是我的 eventgrid 订阅:(我将 blob 添加到特定容器并删除它。请注意,eventgrid 订阅的指标可能需要大约 5 分钟才能显示。但它会立即触发您的端点功能。)

这是我的 eventgrid 订阅的过滤器:

我希望在测试容器中创建和删除的 blob 以触发端点 azure 功能,因此我将 /blobServices/default/containers/test 添加到“主题开始于”部分。

然后我的功能可以正常工作:

【讨论】:

  • 谢谢@BowmanZhu,这很有帮助。我的主要问题是,我在哪里可以查看已发送的事件网格消息?我可以在 Azure 门户的哪个位置查看历史事件消息?
猜你喜欢
  • 1970-01-01
  • 2023-03-23
  • 2012-07-07
  • 2011-03-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多