发布到事件网格时将 header Content-Type 更改为 application/cloudevents+json
change the header Content-Type to application/cloudevents+json when publishing to event grid
我使用触发器 "When a HTTP request is received" 然后使用 "Publish Event" 操作将多个事件发布到事件网格。 For 循环可以很好地拆分进入的 JSON 并创建要发布的事件,但发布仍然失败
{
"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."
}
]
}
}
我假设在发布时使用了输入中的 header,所以我尝试在发布时通过更改 Publish_Event 块中的 header 来更改 header如下(直接在代码视图中,因为它在 UI 中不受支持)所以我得到以下内容(添加了 headers 部分):
"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 我用邮递员发送(有点简化):
[
{
"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"
}
]
}
]
看起来像 Official Event Grid Publish Connector doesn't support Cloud Events Schema。
您可以设置主题接受Event Grid Schema,但我相信这只有在创建时才有可能。
最好打开一个feature request on UserVoice to add support for this and in the meantime, a workaround would be to use an HTTP Action to Post to Custom Topic。
但 请注意,解决方法将涉及构建要发送的事件负载(以及获取访问密钥 from Key Vault 而不是直接将其存储在您的工作流程中).
我使用触发器 "When a HTTP request is received" 然后使用 "Publish Event" 操作将多个事件发布到事件网格。 For 循环可以很好地拆分进入的 JSON 并创建要发布的事件,但发布仍然失败
{
"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."
}
]
}
}
我假设在发布时使用了输入中的 header,所以我尝试在发布时通过更改 Publish_Event 块中的 header 来更改 header如下(直接在代码视图中,因为它在 UI 中不受支持)所以我得到以下内容(添加了 headers 部分):
"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 我用邮递员发送(有点简化):
[
{
"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"
}
]
}
]
看起来像 Official Event Grid Publish Connector doesn't support Cloud Events Schema。
您可以设置主题接受Event Grid Schema,但我相信这只有在创建时才有可能。
最好打开一个feature request on UserVoice to add support for this and in the meantime, a workaround would be to use an HTTP Action to Post to Custom Topic。
但 请注意,解决方法将涉及构建要发送的事件负载(以及获取访问密钥 from Key Vault 而不是直接将其存储在您的工作流程中).