[英]Using HTTP2 directly in NestJS
Is there any way to use http2 directly in NestJs?有没有办法直接在 NestJs 中使用 http2? (methods like
pushStream
etc) or should i use express for this kind of features? (像
pushStream
等方法)还是我应该使用 express 来实现这种功能?
No. There is none so far.没有。到目前为止还没有。 But as long as you have the latest nodejs, you may use the http2 libraries.
但是只要你有最新的 nodejs,你就可以使用 http2 库。
You have 2 options:您有 2 个选择:
const http2 = require('http2')
const session = http2.connect('http://localhost:8088')
session.on('error', (err) => console.error(err))
const body = {
sql: "SELECT * FROM SIGNALS EMIT CHANGES;",
properties: {"ksql.streams.auto.offset.reset": "latest"}
}
const req = session.request({
':method': 'POST',
':path': '/query-stream',
'Content-Type': 'application/json'
})
req.write(JSON.stringify(body), 'utf8')
req.end()
req.on('response', (headers) => {
// we can log each response header here
for (const name in headers) {
console.log("a header: " + '${name}: ${headers[name]}')
}
})
req.setEncoding('utf8')
let data = ''
req.on('data', (chunk) => {
data += chunk
console.log('\n${data}')
})
req.on('end', () => {
console.log('\n${data}')
session.close()
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.