Reactor core 3 , webflux & websocket, send to specific session id

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


Reactor core 3 , webflux & websocket, send to specific session id



Every session data passed into the socket is broadcasted to all users since every session subscribes to the UnicastProcessor eventPublisher.



How can I send by event data to a single session id and not to all of them?


@Override
public Mono<Void> handle(WebSocketSession session) {
WebSocketMessageSubscriber subscriber = new WebSocketMessageSubscriber(eventPublisher);
session.receive()
.map(WebSocketMessage::getPayloadAsText)
.map(this::toEvent)
.subscribe(subscriber::onNext, subscriber::onError, subscriber::onComplete);
return session.send(outputEvents.map(session::textMessage));
}



My use-case requires me to include both options for broadcasting any changed state with any client to all sockets connected plus the abillity to send response to a specific client (sessionId) that send a request within a specific event



Github link



or should It be routed to 2 different handlers from the mapping bean?


@Bean
public HandlerMapping webSocketMapping(UnicastProcessor<Event> eventPublisher, Flux<Event> events) {
Map<String, Object> map = new HashMap<>();
map.put("/websocket/chat", new ChatSocketHandler(eventPublisher, events));
SimpleUrlHandlerMapping simpleUrlHandlerMapping = new SimpleUrlHandlerMapping();
simpleUrlHandlerMapping.setUrlMap(map);

//Without the order things break :-/
simpleUrlHandlerMapping.setOrder(10);
return simpleUrlHandlerMapping;
}



if so would be glad to see an example of such solution





A tip for making your question answerable: we can't read an entire github project. Find the part in that project where the broadcast is made, and how it's connected to the project, then paste it here with some example. Then I bet we can help you easly ;)
– Leviand
2 hours ago





thanks for the tip, updated the post with speific .java file and line number. thumbs up :)
– USS-Montana
1 hour ago











By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Visual Studio Code: How to configure includePath for better IntelliSense results

Spring cloud config client Could not locate PropertySource

Makefile test if variable is not empty