Interface MessageAcknowledger

All Known Implementing Classes:
DefaultMessageAcknowledger

public interface MessageAcknowledger
Interface for acknowledging messages.

Implements the acknowledgment protocol for reliable message delivery. When a message with requiresAck=true is received, the receiver must acknowledge it using this interface.

Usage Example


 // Sender side
 AcknowledgedMessage msg = AcknowledgedMessage.of(message, Duration.ofSeconds(10));
 CompletableFuture<AckResult> future = acknowledger.sendWithAck(msg);

 future.thenAccept(result -> {
     if (result.isAcknowledged()) {
         System.out.println("Message delivered!");
     }
 });

 // Receiver side (in message handler)
 if (message.getSpec().containsKey("correlationId")) {
     acknowledger.acknowledge((String) message.getSpec().get("correlationId"));
 }
 
See Also:
  • Method Details

    • sendWithAck

      Sends a message and waits for acknowledgment.
      Parameters:
      message - the acknowledged message to send
      Returns:
      a future that completes when acknowledgment is received or timeout occurs
    • acknowledge

      void acknowledge(String correlationId)
      Sends a positive acknowledgment for the given correlation ID.
      Parameters:
      correlationId - the correlation ID of the message being acknowledged
    • acknowledge

      default void acknowledge(String correlationId, Map<String,Object> metadata)
      Sends a positive acknowledgment with additional metadata.
      Parameters:
      correlationId - the correlation ID
      metadata - additional acknowledgment metadata
    • negative

      void negative(String correlationId, String reason)
      Sends a negative acknowledgment (NACK) for the given correlation ID.
      Parameters:
      correlationId - the correlation ID
      reason - the reason for the negative acknowledgment
    • isPending

      boolean isPending(String correlationId)
      Checks if an acknowledgment is pending for the given correlation ID.
      Parameters:
      correlationId - the correlation ID
      Returns:
      true if acknowledgment is still pending
    • cancel

      boolean cancel(String correlationId)
      Cancels a pending acknowledgment.
      Parameters:
      correlationId - the correlation ID
      Returns:
      true if the pending acknowledgment was cancelled
    • getPendingCount

      int getPendingCount()
      Returns the number of pending acknowledgments.
      Returns:
      count of pending acks
    • getStatistics

      Returns statistics about acknowledgments.
      Returns:
      acknowledgment statistics