如何在WebUI(ktor + freemarker)中呈现StreamObserver

时间:2018-12-03 09:45:16

标签: kotlin freemarker ktor

如何在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()

        } 

0 个答案:

没有答案