Interface MessagingService
public interface MessagingService
Service for cross-proxy messaging via pub/sub.
Provides publish/subscribe functionality for communication between proxy instances in a distributed deployment. The underlying implementation typically uses Redis, but the API is backend-agnostic.
Thread Safety
All methods are thread-safe. Message handlers are invoked on a dedicated thread pool and should not block.
Connection State
The service handles connection failures gracefully. When disconnected, publish operations fail fast and subscriptions are restored on reconnection.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionbooleanCheck if the messaging service is connected and operational.publish(MessageChannel channel, ChannelMessage message) Publish a message to a channel.publishPlugin(String pluginId, String channel, Object data) Publish a plugin-specific message to other proxies.registerListener(Object listener) Register a listener object containing @Subscribe-annotated methods.registerListener(Object listener, Object plugin) Register a listener object with explicit plugin context.<T> voidregisterTypeAdapter(TypeAdapter<T> adapter) Register a custom type adapter for message serialization.<T extends ChannelMessage>
Subscriptionsubscribe(MessageChannel channel, Class<T> messageType, MessageHandler<T> handler) Subscribe to messages of a specific type on a channel.subscribe(MessageChannel channel, MessageHandler<ChannelMessage> handler) Subscribe to messages on a channel.subscribeIncludingSelf(MessageChannel channel, MessageHandler<ChannelMessage> handler) Subscribe to messages on a channel, including messages from the local proxy.<T> SubscriptionsubscribePlugin(String pluginId, String channel, Class<T> dataType, PluginMessageHandler<T> handler) Subscribe to plugin-specific messages with automatic deserialization.voidunregisterListener(Object listener) Unregister a listener previously registered withregisterListener(Object).voidunregisterTypeAdapter(Class<?> type) Unregister a type adapter.voidunsubscribeAll(MessageChannel channel) Unsubscribe all handlers from a channel.
-
Method Details
-
isConnected
boolean isConnected()Check if the messaging service is connected and operational.- Returns:
- true if connected to the messaging backend
-
publish
@Nonnull CompletableFuture<Void> publish(@Nonnull MessageChannel channel, @Nonnull ChannelMessage message) Publish a message to a channel.- Parameters:
channel- the channel to publish tomessage- the message to publish- Returns:
- a future that completes when the message is sent
-
publishPlugin
@Nonnull CompletableFuture<Void> publishPlugin(@Nonnull String pluginId, @Nonnull String channel, @Nonnull Object data) Publish a plugin-specific message to other proxies.- Parameters:
pluginId- your plugin's unique identifierchannel- the sub-channel within your plugindata- the data object to send (will be serialized to JSON)- Returns:
- a future that completes when the message is sent
-
subscribe
@Nonnull Subscription subscribe(@Nonnull MessageChannel channel, @Nonnull MessageHandler<ChannelMessage> handler) Subscribe to messages on a channel.- Parameters:
channel- the channel to subscribe tohandler- the handler to invoke for each message- Returns:
- a subscription that can be used to unsubscribe
-
subscribe
@Nonnull <T extends ChannelMessage> Subscription subscribe(@Nonnull MessageChannel channel, @Nonnull Class<T> messageType, @Nonnull MessageHandler<T> handler) Subscribe to messages of a specific type on a channel.- Type Parameters:
T- the message type- Parameters:
channel- the channel to subscribe tomessageType- the message type to filter forhandler- the handler to invoke for matching messages- Returns:
- a subscription that can be used to unsubscribe
-
subscribeIncludingSelf
@Nonnull Subscription subscribeIncludingSelf(@Nonnull MessageChannel channel, @Nonnull MessageHandler<ChannelMessage> handler) Subscribe to messages on a channel, including messages from the local proxy.- Parameters:
channel- the channel to subscribe tohandler- the handler to invoke for each message- Returns:
- a subscription that can be used to unsubscribe
-
subscribePlugin
@Nonnull <T> Subscription subscribePlugin(@Nonnull String pluginId, @Nonnull String channel, @Nonnull Class<T> dataType, @Nonnull PluginMessageHandler<T> handler) Subscribe to plugin-specific messages with automatic deserialization.- Type Parameters:
T- your custom data type- Parameters:
pluginId- the plugin identifier to listen forchannel- the sub-channel within the plugindataType- the class of your custom data typehandler- the handler to invoke with deserialized data- Returns:
- a subscription that can be used to unsubscribe
-
unsubscribeAll
Unsubscribe all handlers from a channel.- Parameters:
channel- the channel to unsubscribe from
-
registerListener
Register a listener object containing @Subscribe-annotated methods.- Parameters:
listener- the listener object- Returns:
- a composite subscription that can unsubscribe all methods at once
-
registerListener
Register a listener object with explicit plugin context.- Parameters:
listener- the listener objectplugin- the plugin instance (must have @Plugin annotation)- Returns:
- a composite subscription that can unsubscribe all methods at once
-
unregisterListener
Unregister a listener previously registered withregisterListener(Object).- Parameters:
listener- the listener to unregister
-
registerTypeAdapter
Register a custom type adapter for message serialization.- Type Parameters:
T- the type handled by the adapter- Parameters:
adapter- the type adapter to register
-
unregisterTypeAdapter
Unregister a type adapter.- Parameters:
type- the type to unregister the adapter for
-