[英]How to Send a list in spring webflux Reactive websockets
im working with spring websockets , i want to return a list of items from repository我正在使用 spring websockets,我想从存储库中返回一个项目列表
List<Items> nameList = itemsService.getItems ();
how can i send this list in a websocket session我如何在 websocket 会话中发送这个列表
public Mono<Void> handle(WebSocketSession webSocketSession) {
System.out.println (webSocketSession.getId () + "sessionId" );
List<Items> nameList = itemsService.getItems ();
Flux<Items> output = Flux.fromIterable (nameList);
Mono<Void> send = webSocketSession.
send (output.map ((Items s) -> webSocketSession.binaryMessage (s)));
return send;
this is my handler method how to send the list of items to the websocket这是我的处理程序方法如何将项目列表发送到 websocket
Flux<Items> flux = Flux.fromIterable (nameList);
Flux<WebSocketMessage> webSocketMessageFlux = flux
.map(itm ->convertIemsToString(itm)).map (item -> webSocketSession.textMessage (item));
return webSocketSession.send (webSocketMessageFlux);
so first i converted the List to flux then convert it to websocketMessage then send the websocket message to the seesion where it would be pushed to the clients所以首先我将列表转换为通量,然后将其转换为 websocketMessage,然后将 websocket 消息发送到将被推送到客户端的seesion
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.