You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure Event Hubs自定义消息内容类型设置问题咨询

Can I Use a Custom Content-Type with Azure Event Hubs via REST API?

Yes, you absolutely can use custom content types with Azure Event Hubs' REST API—your issue is likely due to a formatting misstep in your request header. Let me break this down:

Why You’re Seeing the Default contentType Structure

The auto-generated {"type":"application", "subtype":"json", ...} object you’re getting suggests Event Hubs is falling back to a default because your Content-Type header doesn’t follow HTTP’s media type specification. HTTP requires Content-Type headers to use a main-type/subtype format, and your current value (vnd.mytype.v1+json) is missing the required main type (like application/).

How to Fix It

  1. Correct Your Content-Type Header Format
    Follow the standard custom media type pattern: prepend application/ to your value, making it application/vnd.mytype.v1+json. This aligns with RFC specifications and ensures Event Hubs parses it correctly.

  2. Test with a Valid Request
    Here’s an example curl command to verify the setup (replace placeholders with your Event Hub details):

    curl -X POST "https://<your-namespace>.servicebus.windows.net/<your-eventhub>/messages" \
      -H "Authorization: SharedAccessSignature sr=<your-namespace>.servicebus.windows.net&sig=<your-signature>&se=<expiry>&skn=<policy-name>" \
      -H "Content-Type: application/vnd.mytype.v1+json" \
      -d '{"payload": "test"}'
    
  3. Verify the Parsed Content Type on the Receiving End
    When you retrieve the message via SDK, the contentType object will now reflect your custom value:

    • type will be application
    • subtype will be vnd.mytype.v1+json
      You can use the subtype field to distinguish your custom message types from others.

Alternative: Use Custom Message Properties

If you need to bypass the standard media type format for some reason, you can pass a custom identifier via user properties. Add a header like x-ms-user-property-CustomContentType: vnd.mytype.v1+json to your request. On the receiving side, access this value from the message’s user properties collection instead of the built-in contentType field. That said, sticking to the standard Content-Type format is better for compatibility with Event Hubs' native behavior.

内容的提问来源于stack exchange,提问作者Vince V.

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.12 03:53:57