Class AcknowledgedMessage

java.lang.Object
com.tnsai.communication.AcknowledgedMessage

public class AcknowledgedMessage extends Object
A message that requires acknowledgment from the receiver.

Wraps an AgentMessage with acknowledgment metadata including correlation ID, timeout, and retry configuration.

Usage Example


 // Create an acknowledged message
 AcknowledgedMessage ackMsg = AcknowledgedMessage.builder()
     .message(originalMessage)
     .timeout(Duration.ofSeconds(30))
     .maxRetries(3)
     .build();

 // Send with acknowledgment
 CompletableFuture<AckResult> future = agent.sendWithAck(ackMsg);
 future.thenAccept(result -> {
     if (result.isAcknowledged()) {
         System.out.println("Message acknowledged!");
     }
 });
 
See Also:
  • Method Details

    • getCorrelationId

      public String getCorrelationId()
      Returns the correlation ID for tracking this acknowledgment.
      Returns:
      the correlation ID
    • getMessage

      public AgentMessage getMessage()
      Returns the underlying agent message.
      Returns:
      the wrapped message
    • getTimeout

      public Duration getTimeout()
      Returns the acknowledgment timeout duration.
      Returns:
      the timeout
    • getMaxRetries

      public int getMaxRetries()
      Returns the maximum number of retries on timeout.
      Returns:
      max retries (0 means no retries)
    • getCreatedAt

      public Instant getCreatedAt()
      Returns when this message was created.
      Returns:
      creation timestamp
    • getExpiresAt

      public Instant getExpiresAt()
      Returns when this message expires (createdAt + timeout).
      Returns:
      expiration timestamp
    • getAckSpec

      public Map<String,Object> getAckSpec()
      Returns additional acknowledgment metadata.
      Returns:
      acknowledgment metadata
    • isExpired

      public boolean isExpired()
      Checks if this message has expired (timeout exceeded).
      Returns:
      true if expired
    • getRemainingTime

      public Duration getRemainingTime()
      Returns remaining time before timeout.
      Returns:
      remaining duration, or Duration.ZERO if expired
    • builder

      public static AcknowledgedMessage.Builder builder()
      Creates a new builder for AcknowledgedMessage.
      Returns:
      a new builder
    • of

      public static AcknowledgedMessage of(AgentMessage message)
      Creates an AcknowledgedMessage wrapping the given message with default settings.
      Parameters:
      message - the message to wrap
      Returns:
      a new AcknowledgedMessage
    • of

      public static AcknowledgedMessage of(AgentMessage message, Duration timeout)
      Creates an AcknowledgedMessage with a specific timeout.
      Parameters:
      message - the message to wrap
      timeout - the acknowledgment timeout
      Returns:
      a new AcknowledgedMessage
    • toMessageWithCorrelation

      public AgentMessage toMessageWithCorrelation()
      Returns the wrapped message with correlation ID added to metadata.
      Returns:
      message with correlation metadata
    • toString

      public String toString()
      Overrides:
      toString in class Object