【问题标题】:Secure websockets with Lagom使用 Lagom 保护 websocket
【发布时间】:2018-07-31 04:42:07
【问题描述】:

使用lightbend Lagom 框架,我正在尝试连接到 Binance 的 websocket api。

但是,我在连接时不断收到以下错误:

400 普通 HTTP 请求已发送到 HTTPS 端口

是否可以从 Lagom 连接到安全的 websocket 服务?那么使用 WebSocketClient 呢? 我有以下代码:

trait BinanceStreamingService extends Service {
    def depthStream(symbol: String): ServiceCall[NotUsed, Source[DepthEvent, NotUsed]]

    override final def descriptor = {
        import Service._
        import me.koopal.crypto.api.BinanceModelsMarshallers._

        named("depth-stream")
            .withCalls(
                restCall(GET, "/ws/:symbol@deth", depthStream _)
            )
     }
} 

private val binanceStreamApplication = new LagomClientApplication("binance-ws") with StaticServiceLocatorComponents with AhcWSComponents {
    override def staticServiceUri = URI.create("wss://stream.binance.com:9443")
}

override def stream = ServiceCall { _ =>
    binanceStreamClient.depthStream("bnbbtc")
        .invoke()
        .map { s =>
            s.runForeach(e => println(e))
        }.onComplete {
            case Success(x) => println("success", x)
            case Failure(ex) => println("failure", ex)
        }

        Future.successful("test")
}

可以在此处找到运行代码示例:https://github.com/stijnkoopal/lagom-binance-websockets

【问题讨论】:

    标签: scala websocket lagom


    【解决方案1】:

    Lagom 的 WebSocket 客户端还不支持 TLS。使用 Akka HTTP 重新实现客户端存在一个未解决的问题,这将启用 TLS 支持:https://github.com/lagom/lagom/issues/895

    同时,最好的方法是使用Akka HTTP Client-Side WebSocket Support 或其他支持安全连接的 WebSocket 客户端库来实现您的客户端。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-05-07
      • 2016-04-17
      • 2016-08-25
      • 1970-01-01
      • 2015-01-31
      • 2017-01-27
      • 1970-01-01
      • 2020-11-20
      相关资源
      最近更新 更多