Class EnvelopeCodec

java.lang.Object
com.babelqueue.EnvelopeCodec

public final class EnvelopeCodec extends Object
Builds, encodes and decodes the canonical BabelQueue envelope — the single Java implementation of the wire format. The shape is frozen as {job, trace_id, data, meta, attempts} (schema version 1) so a Java service interoperates byte-for-byte with the PHP/Laravel, Python, Go and Node SDKs over any broker. Pure JDK — no dependencies.

Full spec: babelqueue.com

  • Field Details

    • SCHEMA_VERSION

      public static final int SCHEMA_VERSION
      The wire envelope schema version this core implements.
      See Also:
    • SOURCE_LANG

      public static final String SOURCE_LANG
      The value stamped into meta.lang for envelopes produced here.
      See Also:
  • Method Details

    • make

      public static Envelope make(String urn, Map<String,Object> data)
      Build the canonical envelope for a (urn, data) pair on the default queue.
    • make

      public static Envelope make(String urn, Map<String,Object> data, String queue, String traceId)
      Build the canonical envelope for a (urn, data) pair. A fresh trace id is minted unless traceId is non-blank (trace continuation); attempts starts at 0 and meta is stamped with a unique id, the source language, the schema version and a millisecond timestamp.
      Throws:
      BabelQueueException - if urn is null or blank
    • fromMessage

      public static Envelope fromMessage(PolyglotMessage message)
      Build the envelope from a PolyglotMessage on the default queue.
    • fromMessage

      public static Envelope fromMessage(PolyglotMessage message, String queue)
      Build the envelope from a PolyglotMessage. If the message also implements HasTraceId and returns a non-empty value, that trace id is reused.
    • encode

      public static String encode(Envelope envelope)
      Encode the envelope as compact UTF-8 JSON. Slashes and non-ASCII are left unescaped, matching the other SDK cores; the field order is canonical.
    • decode

      public static Envelope decode(String raw)
      Parse a raw JSON body into an Envelope. Malformed or non-object input yields an empty envelope (so accepts(com.babelqueue.Envelope) returns false); the urn inbound alias is resolved into job. Does not validate the contents — call accepts(com.babelqueue.Envelope) first.
    • urn

      public static String urn(Envelope envelope)
      The message URN — the canonical job, with the urn alias resolved by decode(java.lang.String).
    • accepts

      public static boolean accepts(Envelope envelope)
      Whether a consumer should accept this envelope: rejects a missing URN, an unsupported meta.schema_version, missing data or a blank trace_id — the consumer-side counterpart to the producer JSON Schema.