Class OutboxRecord

java.lang.Object
org.acemq.amqp.api.OutboxRecord

public final class OutboxRecord extends Object
One message waiting in the outbox: where it is going, what it says, and how it has fared.

The payload is text rather than bytes, which is a deliberate choice with a cost. The cost is that a binary codec cannot use this store as it stands. The gain is that the outbox table can be read with SQL, and an operator asking "why has this order not been published?" at three in the morning can answer it with a select rather than a hex dump. Every codec AceMQ ships today produces text, so nothing is lost yet, and a bytes column can be added beside this one when that changes.

The envelope is reduced to its identifying fields — id, type, correlation and causation — rather than stored whole. Arbitrary headers would need a serialisation format, and inventing one here to avoid depending on a codec would be the worse trade. Until the JSON codec lands, a message published through the outbox carries these four fields and no custom headers.

  • Constructor Details

    • OutboxRecord

      public OutboxRecord(String id, String exchange, String routingKey, String type, String payload, @Nullable String correlationId, @Nullable String causationId, Instant createdAt, int attempts, @Nullable String lastError)
      Full constructor, used when reading a record back out of storage.
      Parameters:
      id - message identifier, unique across the outbox
      exchange - exchange to publish to; empty string for the default exchange
      routingKey - routing key to publish with
      type - logical message type
      payload - encoded message body
      correlationId - correlation identifier, or null
      causationId - causation identifier, or null
      createdAt - when the record was written
      attempts - how many publish attempts have been made
      lastError - why the last attempt failed, or null
  • Method Details

    • of

      public static OutboxRecord of(String exchange, String routingKey, Envelope envelope, String payload)
      A new record for a message that has not been attempted yet.
      Parameters:
      exchange - exchange to publish to; empty string for the default exchange
      routingKey - routing key to publish with
      envelope - envelope the message will carry; its id becomes the record's id
      payload - encoded message body
      Returns:
      the record to hand to OutboxStore.add(org.acemq.amqp.api.OutboxRecord)
    • envelope

      public Envelope envelope()
      Rebuilds the envelope this record should be published with.

      The identifier is carried through rather than regenerated, so a relay that publishes the same record twice — which it will, if it dies between the broker's confirm and the database commit — sends the same identifier both times and an idempotent consumer can recognise the second as a duplicate.

      Returns:
      the envelope to publish with
    • id

      public String id()
      Returns:
      message identifier, unique across the outbox
    • exchange

      public String exchange()
      Returns:
      exchange to publish to; empty string for the default exchange
    • routingKey

      public String routingKey()
      Returns:
      routing key to publish with
    • type

      public String type()
      Returns:
      logical message type
    • payload

      public String payload()
      Returns:
      encoded message body
    • correlationId

      public Optional<String> correlationId()
      Returns:
      correlation identifier, if the message carries one
    • causationId

      public Optional<String> causationId()
      Returns:
      causation identifier, if the message carries one
    • createdAt

      public Instant createdAt()
      Returns:
      when the record was written
    • attempts

      public int attempts()
      Returns:
      how many publish attempts have been made
    • lastError

      public Optional<String> lastError()
      Returns:
      why the last attempt failed, if one has
    • equals

      public boolean equals(Object other)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object