Annotation Interface MessageHandler


@Documented @Retention(RUNTIME) @Target(METHOD) public @interface MessageHandler
Marks a method as a message handler for agent communication.

Message handlers process incoming messages from other agents, broadcasts, pub/sub topics, or direct messages.

Usage


 @MessageHandler(
     types = {MessageType.TASK_REQUEST, MessageType.QUERY},
     channels = {"research-requests"},
     priority = 10
 )
 public void handleResearchTask(AgentMessage message) {
     String topic = message.getContent();
     // Process research request...
 }
 

Method Signature

Handler methods should accept AgentMessage as parameter. Optional: return AgentMessage for reply.
Author:
TnsAI Team
See Also:
  • Element Details

    • types

      String[] types
      Message types to handle.

      Empty means handle all types.

      Returns:
      message type names
      Default:
      {}
    • channels

      String[] channels
      Channels to listen on.

      Empty means listen on default channel.

      Returns:
      channel names
      Default:
      {}
    • topics

      String[] topics
      Topics to subscribe to (for pub/sub).
      Returns:
      topic patterns
      Default:
      {}
    • filter

      String filter
      Message content filter (regex pattern).

      Only messages matching pattern are handled.

      Returns:
      filter pattern
      Default:
      ""
    • priority

      int priority
      Handler priority (higher = handled first).

      Range: 1-100, default 50.

      Returns:
      priority value
      Default:
      50
    • async

      boolean async
      Whether handler runs asynchronously.
      Returns:
      true for async execution
      Default:
      false
    • timeout

      int timeout
      Timeout for handler execution in milliseconds.

      0 means no timeout.

      Returns:
      timeout in ms
      Default:
      0
    • autoAck

      boolean autoAck
      Whether to acknowledge message after handling.
      Returns:
      true to auto-acknowledge
      Default:
      true
    • onError

      Error handling strategy.
      Returns:
      error strategy
      Default:
      LOG_AND_CONTINUE
    • allowedSenders

      String[] allowedSenders
      Sender IDs to accept messages from.

      Empty means accept from all senders.

      Returns:
      allowed sender IDs
      Default:
      {}