如何在Spring中将多个消息相继推送或发布到同一个Web-socket Session?
public Flux<WebSocketSession> openWebSocket() {
Flux<String> input = Flux.just("{\"action\":\"auth\",\"params\":\"SomeKEY AUTH\"}\n",
"{{\"action\":\"subscribe\", \"params\":\"subcriptionmessage.*\"}");
Flux<String> input1 = Flux.just("{{\"action\":\"subscribe\", \"params\":\"AM.*\"}");
Flux<String> input2 = Flux.just("{\"action\":\"auth\",\"params\":\"SomeKEY AUTH\"}\n");
ReplayProcessor<Object> output = ReplayProcessor.create(100);
try {
webSocketClient.execute(new URI("wss://***"),
session -> {
log.debug("Starting to send messages");
return session
.send(input.doOnNext(s -> log.debug("outbound " + s)).map(session::textMessage))
.thenMany(session.receive().map(WebSocketMessage::getPayloadAsText))
.delayUntil(i -> Mono.delay(Duration.ofSeconds(5)))
.doOnNext(s -> log.debug("inbound " + s))
.subscribeWith(output).then();
}).block();
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
return null;
}
1条答案
按热度按时间zpgglvta1#
我纠正了我的有效载荷和它的作品这是一个问题的有效载荷,有无效的json输入字符串
实际:“{{“action”:“subscribe”,“params”:“subcriptionmessage."}”
应为:“{“action”:“subscribe”,“params”:“subcriptionmessage."}”