Skip to content

Content type conversion matrix

Oleg Zhurakousky edited this page Jan 29, 2018 · 18 revisions

Introduction

This page documents the expectation one must have when producing and consuming messages via Spring Cloud Stream channel-based binders (i.e., Kafka, Rabbit)

Assumptions and expectations

  • 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>
  • 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. This means that the content set on the inbound binding or inbound message header will not be propagated to the outbound message and instead must be explicitly set on the outbound binding and/or message header.

Supported Content-Types

Below is the list of content types supported by the provided MessageConverters

  • application/json application/octet-stream
  • application/x-java-object (must contain type attribute 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
Content-type Supported Handler argument type (all handlers support Message<T> as an argument type where T is the type) MessageConverter
- byte[], String, POJO (json friendly) ApplicationJsonMessageConverter
application/json byte[], String, POJO (json friendly) ApplicationJsonMessageConverter
text/* byte[], String ObjectStringMessageConverter
application/x-java-object byte[], POJO (Kryo) KryoMessageConverter
application/x-java-serialized-object byte[], POJO JavaSerializationMessageConverter
application/octet-stream byte[] ByteArrayMessageConverter