Package com.tnsai.protocols.annotations
Annotation 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 acceptAgentMessage as parameter.
Optional: return AgentMessage for reply.- Author:
- TnsAI Team
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumError handling strategies. -
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionString[]Sender IDs to accept messages from.booleanWhether handler runs asynchronously.booleanWhether to acknowledge message after handling.String[]Channels to listen on.Message content filter (regex pattern).Error handling strategy.intHandler priority (higher = handled first).intTimeout for handler execution in milliseconds.String[]Topics to subscribe to (for pub/sub).String[]Message types to handle.
-
Element Details
-
types
String[] typesMessage types to handle.Empty means handle all types.
- Returns:
- message type names
- Default:
{}
-
channels
String[] channelsChannels to listen on.Empty means listen on default channel.
- Returns:
- channel names
- Default:
{}
-
topics
String[] topicsTopics to subscribe to (for pub/sub).- Returns:
- topic patterns
- Default:
{}
-
filter
String filterMessage content filter (regex pattern).Only messages matching pattern are handled.
- Returns:
- filter pattern
- Default:
""
-
priority
int priorityHandler priority (higher = handled first).Range: 1-100, default 50.
- Returns:
- priority value
- Default:
50
-
async
boolean asyncWhether handler runs asynchronously.- Returns:
- true for async execution
- Default:
false
-
timeout
int timeoutTimeout for handler execution in milliseconds.0 means no timeout.
- Returns:
- timeout in ms
- Default:
0
-
autoAck
boolean autoAckWhether to acknowledge message after handling.- Returns:
- true to auto-acknowledge
- Default:
true
-
onError
MessageHandler.ErrorStrategy onErrorError handling strategy.- Returns:
- error strategy
- Default:
LOG_AND_CONTINUE
-
allowedSenders
String[] allowedSendersSender IDs to accept messages from.Empty means accept from all senders.
- Returns:
- allowed sender IDs
- Default:
{}
-