Class Codecs

java.lang.Object
org.acemq.amqp.core.Codecs

public final class Codecs extends Object
Finds the codecs on the classpath and names the ones used by default.

Formats are discovered rather than listed, for the same reason transports are: the core cannot depend on an XML library, an Avro library and a Protobuf library at once, and should not try. Each format is a module that announces itself, and asking for one that is not there produces an error naming the artifact to add rather than a missing class.

The defaults are deliberately asymmetric. Publishing uses JSON and nothing else, because a queue carrying two formats at once is a queue no consumer can be written against, and the format on the wire is a contract with services that are not being redeployed. Consuming uses every codec on the classpath, because a consumer that refuses a message it could have read has turned somebody else's deployment into its own outage.

Write one format, read all of them. That asymmetry is what makes changing format two ordinary releases instead of a flag day.

  • Field Details

    • DEFAULT_FORMAT

      public static final String DEFAULT_FORMAT
      The format published in unless the application says otherwise.
      See Also:
  • Method Details

    • byName

      public static Codec byName(String name)

      string is accepted as another name for text, which stays the canonical one: it is what the .NET and Ruby libraries call the same codec, and a name copied from one of them should not fail here.

      Parameters:
      name - short format name, such as json or xml
      Returns:
      a codec for that format
      Throws:
      AceMqException - if no module on the classpath provides it
    • forPublishing

      public static Codec forPublishing()
      Returns:
      the codec used to publish when the application has not chosen one
    • forConsuming

      public static Codec forConsuming()
      Every codec on the classpath, in the order they should be tried.

      What a consumer reads with. A message that names its format goes to the codec that claims it; a message that names none is offered to each in turn, which is the only useful answer when a sender has told us nothing.

      Returns:
      a codec that reads any known format and writes the default one
    • names

      public static List<String> names()
      Returns:
      the format names available on this classpath, in the order they are tried