微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何复制 RSocket Kotlin 的错误

如何解决如何复制 RSocket Kotlin 的错误

如何使用 RSocket Kotlin 重现错误以在 StackOverflow 上提交错误或提出问题。

解决方法

在 Intellij 中制作 Kotlin 脚本,将其放在任何源文件夹之外,并确保它以 .main.kts 文件名结尾。

example.main.kts

#!/usr/bin/env kotlin

@file:Repository("https://repo1.maven.org/maven2/")
@file:Repository("https://jcenter.bintray.com/")
@file:DependsOn("io.rsocket.kotlin:rsocket-core:0.12.0")
@file:DependsOn("io.rsocket.kotlin:rsocket-core-jvm:0.12.0")
@file:DependsOn("io.rsocket.kotlin:rsocket-transport-ktor:0.12.0")
@file:DependsOn("io.rsocket.kotlin:rsocket-transport-ktor-jvm:0.12.0")
@file:DependsOn("io.rsocket.kotlin:rsocket-transport-ktor-client:0.12.0")
@file:DependsOn("io.rsocket.kotlin:rsocket-transport-ktor-client-jvm:0.12.0")
@file:DependsOn("io.ktor:ktor-client-okhttp:1.4.3")
@file:CompilerOptions("-jvm-target","1.8","-Xopt-in=kotlin.RequiresOptIn")
@file:OptIn(ExperimentalTime::class)

import io.ktor.client.HttpClient
import io.ktor.client.engine.okhttp.OkHttp
import io.ktor.client.features.websocket.WebSockets
import io.rsocket.kotlin.RSocket
import io.rsocket.kotlin.core.RSocketConnector
import io.rsocket.kotlin.keepalive.KeepAlive
import io.rsocket.kotlin.payload.Payload
import io.rsocket.kotlin.payload.PayloadMimeType
import io.rsocket.kotlin.transport.ktor.client.RSocketSupport
import io.rsocket.kotlin.transport.ktor.client.rSocket
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.take
import kotlinx.coroutines.runBlocking
import kotlin.time.ExperimentalTime
import kotlin.time.seconds

runBlocking {
  val client = HttpClient(OkHttp) {
    install(WebSockets)
    install(RSocketSupport) {
      connector = RSocketConnector {
        connectionConfig {
          // setupPayload(setupPayload)
          keepAlive = KeepAlive(5.seconds)
          payloadMimeType = PayloadMimeType("application/json","application/json")
        }
      }
    }
  }

  // connect to some url
  val rSocket: RSocket = client.rSocket("wss://rsocket-demo.herokuapp.com/rsocket")

  // request stream
  val stream: Flow<Payload> = rSocket.requestStream(Payload.Empty)

  // take 5 values and print response
  stream.take(5).collect { payload: Payload ->
    println(payload.data.readText())
  }
}

enter image description here

#! line 表示它也将像 shell 脚本一样运行

$ ./example.main.kts
0
1
2
3
4
Exception in thread "DefaultDispatcher-worker-3" java.lang.IllegalArgumentException: End gap 8 is too big: capacity is 7
    at io.ktor.utils.io.core.BufferKt.endGapReservationFailedDueToCapacity(Buffer.kt:463)
    at io.ktor.utils.io.core.Buffer.reserveEndGap(Buffer.kt:220)
    at io.ktor.utils.io.core.AbstractOutput.appendNewChunk(AbstractOutput.kt:195)
    at io.ktor.utils.io.core.AbstractOutput.prepareWriteHead(AbstractOutput.kt:497)
    at io.ktor.utils.io.core.OutputPrimitivesKt.writeIntFallback(OutputPrimitives.kt:133)
    at io.ktor.utils.io.core.OutputPrimitivesKt.writeInt(OutputPrimitives.kt:22)
...
,

运行 rsocket-cli 以向 rsocket 服务器发送测试请求

$ brew install yschimke/tap/rsocket-cli
$ rsocket-cli wss://rsocket-demo-1.ew.r.appspot.com/rsocket --route timer --stream -i '{"a": "b"}' --requestn 5
0
1
2

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?