Class CompositeCodec
- All Implemented Interfaces:
Codec
This is what makes changing format survivable. A queue during a cutover holds messages written by the old producers and the new ones at the same time, and a consumer that understands only one of them either loses the others or has to be deployed in lockstep with every producer. Reading both for a while, and writing only the new one, turns a flag day into two ordinary releases: deploy the consumers that read both, then the producers that write the new format, then drop the old codec once the queue has drained.
Encoding always uses the first codec, and there is no way to configure otherwise. Choosing an encoding per message would need a rule for choosing, and every such rule turns into a question the caller has to answer at each publish; one format out, several in, is the shape that migrations actually need.
A message whose content type matches nothing is offered to every codec in turn, because a sender that set no content type has told us nothing rather than told us it is unreadable, and something on the wire is usually still readable by one of them.
-
Method Summary
Modifier and TypeMethodDescriptionbooleancodecs()<T> T<T> TDecodes a received message, told what the sender said it was.byte[]static CompositeCodectoString()
-
Method Details
-
of
- Parameters:
codecs- codecs to read with; the first is also the one written with- Returns:
- a codec that writes the first format and reads any of them
-
contentType
- Specified by:
contentTypein interfaceCodec- Returns:
- the content type this codec produces, for example
application/json
-
encode
-
decode
-
decode
Description copied from interface:CodecDecodes a received message, told what the sender said it was.The engine calls this one, because a codec that dispatches between several formats cannot choose without knowing the content type. A codec that handles a single format has no use for it and need not override this.
-
canDecode
-
codecs
- Returns:
- the codecs this one reads with, in the order they are tried
-
toString
-