@Bean public IntegrationFlow webSocketFlow(EchoService echoService) { return (IntegrationFlowDefinition<?> integrationFlowDefinition) -> { Function<String, Object> splitter = (String messagePayload) -> { // convert the payload String echoValue = echoService.echo(messagePayload); // for each of the active WS sessions, // build a Message destined for that session containing the // input message return serverWebSocketContainer() .getSessions() .keySet() .stream() .map( s -> MessageBuilder.withPayload(echoValue) .setHeader(SimpMessageHeaderAccessor.SESSION_ID_HEADER, s) .build()) .collect(Collectors.toList()); }; integrationFlowDefinition .split(String.class, splitter) .channel(c -> c.executor(Executors.newCachedThreadPool())) .handle(webSocketOutboundAdapter()); }; }
@GET public String echo(@QueryParam("s") String s) { return echoService.echo(s); }