Azure Event Hubs自定义消息内容类型设置问题咨询
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
Correct Your Content-Type Header Format
Follow the standard custom media type pattern: prependapplication/to your value, making itapplication/vnd.mytype.v1+json. This aligns with RFC specifications and ensures Event Hubs parses it correctly.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"}'Verify the Parsed Content Type on the Receiving End
When you retrieve the message via SDK, thecontentTypeobject will now reflect your custom value:typewill beapplicationsubtypewill bevnd.mytype.v1+json
You can use thesubtypefield 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.

