@Singleton @Requires(beans=WebSocketSessionRepository.class) public class NettyServerWebSocketBroadcaster extends Object implements WebSocketBroadcaster
WebSocketBroadcaster
.Constructor and Description |
---|
NettyServerWebSocketBroadcaster(WebSocketMessageEncoder webSocketMessageEncoder,
WebSocketSessionRepository webSocketSessionRepository) |
Modifier and Type | Method and Description |
---|---|
<T> Publisher<T> |
broadcast(T message,
MediaType mediaType,
Predicate<WebSocketSession> filter)
When used on the server this method will broadcast a message to all open WebSocket connections that match the given filter.
|
<T> void |
broadcastSync(T message,
MediaType mediaType,
Predicate<WebSocketSession> filter)
When used on the server this method will broadcast a message to all open WebSocket connections.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
broadcast, broadcast, broadcast, broadcastAsync, broadcastAsync, broadcastAsync, broadcastAsync, broadcastSync, broadcastSync, broadcastSync
public NettyServerWebSocketBroadcaster(WebSocketMessageEncoder webSocketMessageEncoder, WebSocketSessionRepository webSocketSessionRepository)
webSocketMessageEncoder
- A instance of WebSocketMessageEncoder
responsible of encoding WebSocket messages.webSocketSessionRepository
- A instance of WebSocketSessionRepository
. Defines a ChannelGroup repository to handle WebSockets.public <T> void broadcastSync(T message, MediaType mediaType, Predicate<WebSocketSession> filter)
WebSocketBroadcaster
broadcastSync
in interface WebSocketBroadcaster
T
- The message typemessage
- The messagemediaType
- The media type of the message. Used to lookup an appropriate codec via the MediaTypeCodecRegistry
.filter
- The filterpublic <T> Publisher<T> broadcast(T message, MediaType mediaType, Predicate<WebSocketSession> filter)
WebSocketBroadcaster
Publisher
does not start sending until subscribed to.
If you return it from Micronaut annotated methods such as OnOpen
and OnMessage
,
Micronaut will subscribe to it and send the message without blocking.broadcast
in interface WebSocketBroadcaster
T
- The message typemessage
- The messagemediaType
- The media type of the message. Used to lookup an appropriate codec via the MediaTypeCodecRegistry
.filter
- The filter to applyPublisher
that either emits an error or emits the message once it has been published successfully.