Class ClaimCheckCodec
- All Implemented Interfaces:
Codec
Codec checked = ClaimCheckCodec.wrapping(new JsonCodec(), store);
mq.publisher("policies", "document.stored", Document.class).as(checked);
mq.consume("policies.documents", Document.class, checked, m -> read(m.payload()));
A scanned medical report is tens of megabytes. Putting it on a queue is possible and is a
mistake: it fills the broker's memory, it is copied to every bound queue, it makes a
dead-letter queue impossible to inspect, and it turns a broker into a filesystem with worse
tools. What travels instead is a claim check — the payload goes to a
ClaimCheckStore, and the message carries the key.
Only when it is worth it
Below the threshold the payload travels inline, exactly as it would without this codec. That matters more than it sounds: offloading a two-hundred-byte message turns one broker round trip into a store round trip and a broker round trip, so an unconditional claim check makes the common case slower to fix the rare one.
The framing therefore says which of the two it is, and a consumer handles both without being told. That is what allows the threshold to be changed, or this codec to be introduced, without a flag day: messages written before the change are still readable after it.
What is on the wire
0xAC 0x01 0x00 payload inline, and identical to what the delegate wrote 0xAC 0x01 0x01 key a claim check
The content type is the delegate's, unchanged — unlike encryption, where the bytes really are something else. A claim-checked message is still a document; it is a document that is somewhere else, and a consumer that lacks the store gets a clear failure rather than a parser error.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intBelow this, payloads travel inline. -
Method Summary
Modifier and TypeMethodDescriptionboolean<T> Tdelegate()byte[]static @Nullable StringkeyOf(byte[] body) Reads the key a message refers to, without fetching it.toString()static ClaimCheckCodecwrapping(Codec delegate, ClaimCheckStore store) static ClaimCheckCodecwrapping(Codec delegate, ClaimCheckStore store, int threshold)
-
Field Details
-
DEFAULT_THRESHOLD
public static final int DEFAULT_THRESHOLDBelow this, payloads travel inline.64 KiB: comfortably above an ordinary event and comfortably below the size at which a broker starts to care. RabbitMQ will accept far larger, which is the problem — nothing refuses a 40 MB message, it simply makes everything worse afterwards.
- See Also:
-
-
Method Details
-
wrapping
- Parameters:
delegate- the codec that turns objects into bytesstore- where large payloads go- Returns:
- a codec offloading anything above
DEFAULT_THRESHOLD
-
wrapping
- Parameters:
delegate- the codec that turns objects into bytesstore- where large payloads gothreshold- payloads of at least this many bytes are offloaded; zero offloads everything, which is occasionally what a store-backed audit trail wants- Returns:
- a codec offloading anything at or above the threshold
-
contentType
- Specified by:
contentTypein interfaceCodec- Returns:
- the content type this codec produces, for example
application/json
-
encode
-
decode
-
canDecode
-
keyOf
Reads the key a message refers to, without fetching it.For the operator looking at a dead-letter queue: which object does this need, and is it still in the store? Answering that from the message alone is the difference between a five-minute check and restoring a backup.
- Parameters:
body- a message body- Returns:
- the key, or
nullwhen the payload travelled inline or this codec did not write the message
-
delegate
- Returns:
- the wrapped codec, whose output is what gets stored or inlined
-
toString
-