Class Topology.Builder

java.lang.Object
org.acemq.amqp.api.Topology.Builder
Enclosing class:
Topology

public static final class Topology.Builder extends Object
Builds a Topology.
  • Constructor Details

    • Builder

      public Builder()
  • Method Details

    • exchange

      public Topology.Builder exchange(String name, String type)
      Parameters:
      name - exchange name
      type - direct, topic, fanout or headers
      Returns:
      this builder
    • queue

      public Topology.Builder queue(String name)
      A durable quorum queue, which is the default everywhere in this library.
      Parameters:
      name - queue name
      Returns:
      this builder
    • classicQueue

      public Topology.Builder classicQueue(String name, Map<String,Object> arguments)
      Parameters:
      name - queue name
      arguments - broker-specific arguments
      Returns:
      this builder
    • queueWithDeadLetter

      public Topology.Builder queueWithDeadLetter(String name)
      A durable quorum queue that dead-letters, together with the two queues its dead letters end up in and the exchange they are reached through.

      The queue is declared with x-dead-letter-exchange set to Topology.DEAD_LETTER_EXCHANGE and x-dead-letter-routing-key set to {name}.dlq, and {name}.dlq and {name}.parked are declared and bound to that exchange on their own names. Several declarations as one call, because they are only correct together: a queue whose dead-letter exchange nothing declares, or one with no queue bound to it, throws messages away exactly as if dead-lettering had never been configured, and nothing reports it.

      The routing key matters as much as the exchange. A message the broker dead-letters keeps the routing key it arrived under, so without it a message published as order.placed would reach acemq.dlx under that key, match no binding, and be dropped — the silent loss this method exists to prevent.

      This is a backstop, not a replacement for what the consumer already does. A handler that fails is dead-lettered by this library itself: republished to {name}.dlq with the reason recorded on the envelope, and only then acknowledged, which is how the reason survives at all — the broker's own dead-lettering carries an x-death header and no idea why the message failed. Both paths stay. The broker-side route catches what the library never sees: a message expiring under the source queue's own x-message-ttl, an overflow under x-max-length, a reject from some other consumer of the same queue. Without these arguments those messages vanish; with them they land in the same queue an operator is already watching. Neither path is dead code.

      Neither {name}.dlq nor {name}.parked dead-letters in turn. A dead-letter queue that dead-letters is a loop, and a loop is how a poison message becomes an outage.

      Parameters:
      name - queue name
      Returns:
      this builder
    • classicQueueWithDeadLetter

      public Topology.Builder classicQueueWithDeadLetter(String name, Map<String,Object> arguments)
      A classic queue that dead-letters, with arguments of its own.

      The same arrangement as queueWithDeadLetter(String), for a queue that needs a time-to-live, a length limit or any other argument alongside it.

      Parameters:
      name - queue name
      arguments - broker-specific arguments, which must not set either dead-letter argument
      Returns:
      this builder
      Throws:
      IllegalArgumentException - when the arguments already set x-dead-letter-exchange or x-dead-letter-routing-key
    • bind

      public Topology.Builder bind(String queue, String exchange, String routingKey)
      Parameters:
      queue - queue to bind
      exchange - exchange to bind it to
      routingKey - routing key or pattern
      Returns:
      this builder
    • build

      public Topology build()