Class Responder

java.lang.Object
org.acemq.amqp.core.Responder
All Implemented Interfaces:
AutoCloseable

public final class Responder extends Object implements AutoCloseable
The other end of Requester: reads a request, computes an answer, sends it back.

 try (Responder responder = mq.respond("pricing", Quote.class, Price.class, quote -> price(quote))) {
     // serving until closed
 }
 

The reply goes wherever the request asked, and carries the request's correlation id back unchanged. Neither is the handler's problem. A request names its reply queue twice — the acemq-reply-to header and AMQP's own reply-to property, always the same value — and this reads the header first and the property second, so a caller that wrote only one of them is still answered.

A handler that throws is answered too: the reply carries the failure in the acemq-error header, the caller's Requester raises ResponderFailedException at once instead of waiting out its timeout, and the request is rejected to the dead-letter queue rather than retried. The other four libraries do the same, so the pairing works whichever language either end is written in.

  • Method Details

    • answered

      public long answered()
      How many requests were answered, counted before each reply left.

      A caller holding a reply can rely on this having counted it: the increment happens before the publish, so there is no interleaving in which the answer is visible and the number is not. A publish that fails takes its increment back, so this counts replies that were sent rather than replies that were attempted. Neither number needs a wait before it can be trusted, and code that sleeps before reading one is working around a defect that is fixed.

      Returns:
      how many requests were answered
    • unanswerable

      public long unanswerable()
      How many arrived with no reply-to, counted before the delivery is acknowledged.

      Anything above zero means a caller is publishing where it means to request.

      Returns:
      how many could not be answered
    • isRunning

      public boolean isRunning()
      Returns:
      whether this responder is still serving
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable