Class PublishContext

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

public final class PublishContext extends Object
A message about to be published, as an interceptor sees it.

Immutable, and changed by withEnvelope(org.acemq.amqp.api.Envelope), which returns a new context. An interceptor that mutated what it was handed would be invisible to the one after it and impossible to reason about when two of them touch the same header.

The payload is the application's object, before encoding. That is deliberate: an interceptor that needs to look at what is being sent should see an OrderPlaced, not a byte array it would have to decode again to understand.

  • Constructor Details

    • PublishContext

      public PublishContext(String exchange, String routingKey, Envelope envelope, Object payload)
      Parameters:
      exchange - target exchange
      routingKey - routing key
      envelope - the envelope as it stands
      payload - the application object being sent, before encoding
  • Method Details

    • exchange

      public String exchange()
      Returns:
      target exchange, empty when publishing straight to a queue
    • routingKey

      public String routingKey()
      Returns:
      the routing key
    • envelope

      public Envelope envelope()
      Returns:
      the envelope, including headers an interceptor may have added
    • payload

      public Object payload()
      Returns:
      the application object being published, before encoding
    • withEnvelope

      public PublishContext withEnvelope(Envelope replacement)
      Parameters:
      replacement - the envelope to carry on with
      Returns:
      a copy of this context with a different envelope
    • toString

      public String toString()
      Overrides:
      toString in class Object