kotlin - 如何在 WebUI 中渲染 StreamObserver (ktor + freemarker)
问题描述
如何在 freemarker 中处理 StreamObserver 的输出?我有以下控制器代码以便订阅流频道。
else -> {
try {
//jsonResponse = gnhc.getRequestJsonOutput(pathlist,pretty = true)
jsonResponseRaw = gnhc.subscribev1(pathlist, subId, writer).toString()
jsonResponse = jsonResponseRaw
application.log.debug("SDN_JSON_PROCESSOR: ${jsonResponse}")
} catch (e: Exception) {
jsonResponse = e.toString()
application.log.error("Failed to set channel", e)
} finally {
gnhc.shutdownNow()
}
}
}
call.respond(FreeMarkerContent("subscribe.ftl", mapOf("hostname" to hostname, "port" to port, "cmd" to cmd, "result" to jsonResponse,"rawresult" to jsonResponseRaw, "pathlist" to pathlist, "error" to error), etag = "e"))
}
观察者在这里声明:
try {
// simple observer without writer and subId
val sr: StreamObserver<Gnmi.SubscribeRequest> = stub.subscribe(GnmiStreamObserver(this))
// Writer + Id
//val sr: StreamObserver<Gnmi.SubscribeRequest> = stub.subscribe(StreamResponseWriter(_path,_id,_writer))
sr.onNext(subRequest)
waitCompleted()
sr.onCompleted()
}
解决方案
推荐阅读
- javascript - 向上滚动查看每篇文章
- case - 将 CASE 用于 DATETIME 数据工作室
- mysql - 彼此之间最多 20 秒创建的组记录 - MySql
- kubernetes - cronjob 无法删除失败的 pod
- r - DESeq2 GlimmaMA 图“组的长度必须等于计数中的列数”
- installation - 启动反应引擎抛出错误“java.lang.ClassNotFoundException:com.romix.akka.serialization.kryo.KryoSerializer”
- python - 单元测试:修补 os join 会覆盖测试文件中的 os join
- r - 具有不平衡嵌套数据的 Tidymodels 中的 R 多级预测
- graph - 如何使用邻接矩阵进行广度优先搜索和搜索连接组件?
- python - 同时从多个进程记录到标准输出与记录到文件