Class NettyServerWebSocketBroadcaster
java.lang.Object
io.micronaut.http.netty.websocket.NettyServerWebSocketBroadcaster
- All Implemented Interfaces:
WebSocketBroadcaster
@Singleton
@Requires(beans=WebSocketSessionRepository.class)
public class NettyServerWebSocketBroadcaster
extends Object
implements WebSocketBroadcaster
Netty implementation of
WebSocketBroadcaster
.- Since:
- 1.0
- Author:
- sdelamo
-
Constructor Summary
ConstructorDescriptionNettyServerWebSocketBroadcaster
(WebSocketMessageEncoder webSocketMessageEncoder, WebSocketSessionRepository webSocketSessionRepository) -
Method Summary
Modifier and TypeMethodDescription<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.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.micronaut.websocket.WebSocketBroadcaster
broadcast, broadcast, broadcast, broadcastAsync, broadcastAsync, broadcastAsync, broadcastAsync, broadcastSync, broadcastSync, broadcastSync
-
Constructor Details
-
NettyServerWebSocketBroadcaster
public NettyServerWebSocketBroadcaster(WebSocketMessageEncoder webSocketMessageEncoder, WebSocketSessionRepository webSocketSessionRepository) - Parameters:
webSocketMessageEncoder
- An instance ofWebSocketMessageEncoder
responsible for encoding WebSocket messages.webSocketSessionRepository
- An instance ofWebSocketSessionRepository
. Defines a ChannelGroup repository to handle WebSockets.
-
-
Method Details
-
broadcastSync
Description copied from interface:WebSocketBroadcaster
When used on the server this method will broadcast a message to all open WebSocket connections.- Specified by:
broadcastSync
in interfaceWebSocketBroadcaster
- Type Parameters:
T
- The message type- Parameters:
message
- The messagemediaType
- The media type of the message. Used to lookup an appropriate codec via theMediaTypeCodecRegistry
.filter
- The filter
-
broadcast
public <T> Publisher<T> broadcast(T message, MediaType mediaType, Predicate<WebSocketSession> filter) Description copied from interface:WebSocketBroadcaster
When used on the server this method will broadcast a message to all open WebSocket connections that match the given filter. The resultingPublisher
does not start sending until subscribed to. If you return it from Micronaut annotated methods such asOnOpen
andOnMessage
, Micronaut will subscribe to it and send the message without blocking.- Specified by:
broadcast
in interfaceWebSocketBroadcaster
- Type Parameters:
T
- The message type- Parameters:
message
- The messagemediaType
- The media type of the message. Used to lookup an appropriate codec via theMediaTypeCodecRegistry
.filter
- The filter to apply- Returns:
- A
Publisher
that either emits an error or emits the message once it has been published successfully.
-