-
Notifications
You must be signed in to change notification settings - Fork 631
Content type conversion matrix
Oleg Zhurakousky edited this page Jan 25, 2018
·
18 revisions
This page documents the expectation one must have when producing and consuming messages via Spring Cloud Stream channel-based binders (i.e., Kafka, Rabbit)
- The payloads of messages "on-the-wire" is represented as
byte[]while "in-binder/in-jvm" it could be anything.-
toMessage(..) -
<T> -> byte[] -
fromMessage(..) -
byte[] -> <T>
-
toMessage(..) -
- Binders perform serialization (producer) and deserialization (consumer) of payload to/from
byte[]utilizing MessageConverters. - Default content-type is application/json
- Content-type can be set per binding or as Message header
-
--spring.cloud.stream.default.contentType=- default binding -
--spring.cloud.stream.bindings.<bindingName>.contentType=- per-binding name
-
- Content-type set as Message header takes precedence over content-type set per binding
- Content-type headers are NOT propagated to preserve flexibility of (re)setting in/out content-type at the handler level (via MessageHeaders) or binding level.
Below is the list of content types supported by the provided MessageConverters
- application/json application/octet-stream
-
application/x-java-object (must contain
typeattribute with FQN of the actual type:application/x-java-object; type=foo.bar.MyClass) - DEPRECATED - application/x-java-serialized-object - DEPRECATED
- application/x-spring-tuple - DEPRECATED
| Inbound content-type | Supported Handler payload type | Outbound content-type | MessageConverter |
|---|---|---|---|
| - | byte[], String, POJO (json friendly) | application/json | ApplicationJsonMessageConverter |
| application/json | byte[], String, POJO (json friendly) | application/json | ApplicationJsonMessageConverter |
| text/* | byte[], String | text/* . | ObjectStringMessageConverter |
| application/x-java-object | byte[], POJO (Kryo) | text/* . | |
| application/x-java-serialized-object | byte[], POJO | application/x-java-serialized-object | |
| application/octet-stream | byte[] | application/octet-stream |