[英]Secure websockets with Lagom
使用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")
}
可以在這里找到一個ruuning代碼示例: https : //github.com/stijnkoopal/lagom-binance-websockets
Lagom的WebSocket客戶端尚不支持TLS。 使用Akka HTTP重新實現客戶端存在一個開放的問題,它將啟用TLS支持: https : //github.com/lagom/lagom/issues/895
同時,最好的方法是使用Akka HTTP客戶端WebSocket支持或支持安全連接的另一個WebSocket客戶端庫來實現客戶端。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.