Interface MessageChannel<P extends ChannelPayload>

Type Parameters:
P - the type of payload handled by this channel; must extend ChannelPayload

public interface MessageChannel<P extends ChannelPayload>
A typed communication pipe for sending and receiving messages across the CommandBridge network.

A MessageChannel is bound to a specific payload type P, providing type-safe message routing. Target one or more servers with to(java.util.Collection), broadcast to all connected servers with toAll(), or subscribe to incoming messages with listen(dev.objz.commandbridge.api.message.MessageListener).

All send operations return CompletableFuture and are non-blocking.

To send a payload to a specific server:


 channel.to(List.of(Platform.backend("survival-1")))
         .send(payload);
 

To broadcast to every connected server:


 channel.toAll().send(payload);
 

To subscribe to incoming messages and cancel the listener later:


 Subscription sub = channel.listen((ctx, payload) ->
         System.out.println("From " + ctx.from().id()));
 sub.cancel();
 
See Also: