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