如何使用 rsocket 在 spring 引导中配置 SSL/TLS?

How to config SSL/TLS in spring boot with rsocket?

我已阅读. However, the answer only tell how to config about auth check. I need to encrpt all transferred data with rsocket in spring boot. How can I use tls in spring boot with SSL/TLS. I can't find any supported method when I init my rsocket client as shown below, although I know that rsocket it self can support SSL/TLS. I find some examples: The example

        this.rsocketRequester = rsocketRequesterBuilder.setupRoute("sidecar-client")
            .setupData("test_data")
            .rsocketConnector(connector -> connector.acceptor(responder))
            .connectTcp("localhost", 7000)
            .block();

Summary of my question:
1. Does rsocket in springboot support SSL/TLS ?
2. If spring boot support rsocket with SSL/TLS, are there any examples can be referenced

是,正在修改您的示例

安全 TCP (SSL)

this.rsocketRequester = rsocketRequesterBuilder.setupRoute("sidecar-client")
            .setupData("test_data")
            .rsocketConnector(connector -> connector.acceptor(responder))
            .connect(TcpClientTransport.create(TcpClient.create().secure().host("localhost").port(7000)))
            .block();

或安全网络套接字

this.rsocketRequester = rsocketRequesterBuilder.setupRoute("sidecar-client")
            .setupData("test_data")
            .rsocketConnector(connector -> connector.acceptor(responder))
                  .connectWebSocket(URI.create("https://rsocket-demo.herokuapp.com/rsocket"))
            .block();
  1. spring引导中的rsocket是否支持SSL/TLS?

是 - 无论是否使用 rsocket,您都需要像往常一样配置 SSL/TLS。

在您的 application.yml 中添加以下行:

server:
  port: 8443
  ssl:
    enabled: true
    client-auth: none
    protocol: "TLS"
    key-store: "classpath:certs/local/server.jks"
    key-store-type: "JKS"
    key-store-password: "changeit"
    trust-store: "classpath:certs/trust.jks"
    trust-store-password: "changeit"

spring:
  rsocket:
    server:
      mapping-path: "/"
      transport: websocket

并且在客户端使用 wss 而不是 ws

const _rSocketClient = function()
{
   return  new RSocketClient({
       setup: {
           // ms btw sending keepalive to server
           keepAlive: 60000,
           // ms timeout if no keepalive response
           lifetime: 180000,
           // format of `data`
           dataMimeType: 'application/json',
           // format of `metadata`
           metadataMimeType: MESSAGE_RSOCKET_COMPOSITE_METADATA.string,
       },
       transport: new RSocketWebSocketClient(
           {
               // Connect as secure websocket
               url : "wss://" + R_SOCKET_HOST + ":" + R_SOCKET_PORT,
               debug: true
           },
           BufferEncoders
       ),
   });
}
  1. 如果spring boot support rsocket with SSL/TLS,有没有例子可以参考

我也没找到例子,只好自己动手学习了。您会发现的大多数 RSocket 示例都使用现已弃用的 RSocketFactory,并且 api 不断变化 - 因此请始终获取最新版本并自己尝试。