Class MessagingService
java.lang.Object
dev.ua.theroer.magicutils.messaging.MessagingService
- All Implemented Interfaces:
AutoCloseable
High-level entry point for MagicUtils cross-server messaging.
Owns a MessageBus over a chosen MessageTransport and is the
component registered with a MagicRuntime. The transport is selected at
build time: when Redis is enabled in RedisConfig.Redis a
RedisMessageTransport is used; otherwise the platform's default
plugin-messaging transport is used, so the network runs without Redis.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBuilder that wires the transport and bus together. -
Method Summary
Modifier and TypeMethodDescriptionvoidBroadcasts a payload on a channel.static MessagingService.Builderbuilder(MessageSource self) Creates a service builder.bus()Returns the underlying bus.voidclose()booleanReturns whether the active transport is currently connected.voidPublishes a payload on a channel to a target.subscribe(String channel, Class<T> type, MessageHandler<T> handler) Subscribes a typed handler to a channel.Returns the name of the active transport ("redis" or "plugin-messaging" etc.).
-
Method Details
-
builder
Creates a service builder.- Parameters:
self- this member's identity- Returns:
- builder
-
bus
-
transportName
Returns the name of the active transport ("redis" or "plugin-messaging" etc.).- Returns:
- transport name
-
isConnected
public boolean isConnected()Returns whether the active transport is currently connected.- Returns:
- true when connected
-
publish
-
broadcast
-
subscribe
Subscribes a typed handler to a channel. Delegates to the bus.- Type Parameters:
T- payload type- Parameters:
channel- channel nametype- payload typehandler- handler- Returns:
- subscription handle
-
close
public void close()- Specified by:
closein interfaceAutoCloseable
-