首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >发布到事件网格时将标头内容-类型更改为应用程序/cloudevents+json

发布到事件网格时将标头内容-类型更改为应用程序/cloudevents+json
EN

Stack Overflow用户
提问于 2020-03-06 15:13:49
回答 1查看 1.6K关注 0票数 0

我使用触发器“当接收到HTTP请求时”,然后使用“发布事件”操作将多个事件发布到事件网格。For循环可以很好地拆分获得并创建要发布的事件的JSON,但是发布仍然会失败。

代码语言:javascript
复制
{
  "error": {
    "code": "UnsupportedMediaType",
    "message": "The Content-Type header is either missing or it doesn't have a valid value. The content type header must either be application/cloudevents+json; charset=utf-8 or application/cloudevents-batch+json; charset=UTF-8. Report 'edf36bbd-9221-4882-8a29-2264ffb16d72:3:3/6/2020 2:18:20 PM (UTC)' to our forums for assistance or raise a support ticket.",
    "details": [
      {
        "code": "InvalidContentType",
        "message": "The Content-Type header is either missing or it doesn't have a valid value. The content type header must either be application/cloudevents+json; charset=utf-8 or application/cloudevents-batch+json; charset=UTF-8. Report 'edf36bbd-9221-4882-8a29-2264ffb16d72:3:3/6/2020 2:18:20 PM (UTC)' to our forums for assistance or raise a support ticket."
      }
    ]
  }
}

我假设发布时使用了输入的头部,所以我尝试在发布时更改Publish_Event块中的标头,如下所示(直接在代码视图中,因为它在UI中不受支持),因此我得到了以下内容(添加了header部分):

代码语言:javascript
复制
"Publish_Event": {
    "inputs": {
        "body": [
            {
                "data": "@items('For_each_2')",
                "eventType": "company-location",
                "id": "ID : @{items('For_each')['businessId']}",
                "subject": "Company Location changed"
            }
        ],
        "headers": {
            "Content-Type": "application/cloudevents+json; charset=utf-8"
        },
        "host": {
            "connection": {
                "name": "@parameters('$connections')['azureeventgridpublish']['connectionId']"
            }
        },
        "method": "post",
        "path": "/eventGrid/api/events"
    },
    "runAfter": {},
    "type": "ApiConnection"
}

但这也不起作用。没有找到行动来做改变。

我的全部流程如下:

作为测试数据,我使用以下JSON与postman一起发送(稍微简化了一点):

代码语言:javascript
复制
[
    {
        "id": 3603,
        "businessId": "QQTADOSH",
        "locations": [
            {
                "id": 5316,
                "businessId": "A-yelr3g"
            },
            {
                "id": 5127,
                "businessId": "A-c7i8gd"
            },
            {
                "id": 5403,
                "businessId": "A-fjdd2y"
            },
            {
                "id": 6064,
                "businessId": "A-rqvhz8"
            }
        ]
    },
    {
        "id": 3118,
        "businessId": "Cr11_Macan_111qa",
        "locations": [
            {
                "id": 4563,
                "businessId": "A-3bv860"
            }
        ]
    }
]
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-03-09 10:36:00

看来正式事件网格发布连接器不支持云事件模式

您可以将主题设置为接受事件网格模式,但我相信这只有在创建时才有可能。

最好打开一个UserVoice上的特征请求来添加对此的支持,同时,解决方法是使用HTTP行动张贴到自定义主题

但是确实注意到,解决方法需要构建要发送的事件有效负载(以及获取访问键从钥匙库而不是直接存储在工作流中)。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60566882

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档