rsocket - 如何重现 RSocket Kotlin 的错误
问题描述
如何使用 RSocket Kotlin 重现错误以提交错误或在 StackOverflow 上提问。
解决方案
在 Intellij 中创建一个 Kotlin 脚本,将其放在任何源文件夹之外,并确保它以.main.kts
文件名结尾。
例子.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())
}
}
这 #!行意味着它也会像 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)
...
推荐阅读
- angular - Angular 7:如何重写嵌套订阅?
- angular - 角度通知未显示本机弹出窗口询问权限
- php - Symfony 4 - 带有多数组的 in_array
- com - 当标记为 ComVisible 的 C# 类抛出异常时,C++ 会看到什么异常类型?
- javascript - 如何修复:使用 ElectronJS 的 Waze Iframe API 上的“Uncaught SyntaxError: Unexpected token ...”
- java - Android:如何关联来自同一拖动动作的 ACTION_DOWN 和 ACTION_MOVE 事件
- python - 计算图像中不同颜色的面积比例
- node.js - node.js 文件告诉我导出未定义
- python - 如果我打开文件而不分配文件,它会保持打开状态吗?
- django - 带有子对象的石墨烯 Django 突变返回对象失败