Package org.acemq.amqp.api
Interface Codec
- All Known Implementing Classes:
AvroCodec,BytesCodec,ClaimCheckCodec,CompositeCodec,EncryptedCodec,JsonCodec,ProtobufCodec,StringCodec,TomlCodec,XmlCodec,YamlCodec
public interface Codec
Turns payloads into bytes and back.
Selected by content type, so a queue can carry more than one representation and a consumer can be migrated to a new format without a flag day.
-
Method Summary
Modifier and TypeMethodDescriptionboolean<T> Tdefault <T> TDecodes a received message, told what the sender said it was.byte[]
-
Method Details
-
contentType
String contentType()- Returns:
- the content type this codec produces, for example
application/json
-
encode
- Parameters:
payload- object to encode; nevernull- Returns:
- encoded bytes
- Throws:
AceMqException- if the payload cannot be encoded
-
decode
- Type Parameters:
T- target type- Parameters:
body- encoded bytestarget- type to produce- Returns:
- the decoded payload
- Throws:
AceMqException- if the bytes cannot be decoded, which the engine treats as a poison message rather than a retryable failure
-
decode
Decodes 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.
- Type Parameters:
T- target type- Parameters:
body- encoded bytestarget- type to producecontentType- content type the message arrived with, ornullwhen the sender did not set one- Returns:
- the decoded payload
- Throws:
AceMqException- if the bytes cannot be decoded
-
canDecode
- Parameters:
contentType- content type of a received message, ornullwhen the sender did not set one- Returns:
- whether this codec can decode it
-