我按照 spring-rsocket-demo 项目完成我的代码。我在服务器端代码中添加了一些身份验证逻辑,如下所示。您可以看到我在身份验证逻辑“CLIENT.add(requester)”之后引发了异常。我在 spring-rsocket-demo 项目中执行名为“testRequestGetsResponse”的测试方法,我发现我无法收到异常。如何在 @ConnectMapping 注释方法中处理设置有效负载并在需要时返回 RejectedSetupException。
requester.rsocket()
.onClose()
.doFirst(() -> {
// Add all new clients to a client list
log.info("Client: {} CONNECTED.", client);
//throw Exception during process setup payload
//my authentication code.
try {
// CLIENTS.add(requester);
throw new RuntimeException();
} catch (Exception exception) {
throw exception;
}
})
.doOnError(error -> {
// Warn when channels are closed by clients
log.warn("Channel to client {} CLOSED", client);
})
.doFinally(consumer -> {
// Remove disconnected clients from the client list
CLIENTS.remove(requester);
log.info("Client {} DISCONNECTED", client);
})
.subscribe();