我想使用Knative序列来链接几个ksvcs,但失败了。可以触发第一步ksvc,但不能触发其余步骤。
在我的ksvc(Node.js)中,我使用了CloudEvent js-sdk。我想我需要在收到CloudEvent后返回一个新的new。下面是我的代码:
app.post('/', (req, res)=>{
const event = HTTP.toEvent({ headers: req.headers, body: req.body });
// respond as an event
const responseEventMessage = new CloudEvent({
source: '/',
type: 'event:response',
...event
});
responseEventMessage.data = {
hello: 'world'
};
res.status(201).json(responseEventMessage);
})发布于 2021-01-25 18:28:16
我认为应该使用HTTP.binary()或HTTP.structured()将事件转换为headers和body。
const responseEventMessage = new CloudEvent({
...receivedEvent,
source: '/',
type: 'event:response'
});
// const message = HTTP.binary(responseEventMessage)
const message = HTTP.structured(responseEventMessage)
res.set(message.headers)
res.send(message.body)编辑:可能需要设置body-parser。
const bodyParser = require('body-parser')
app.post("/", bodyParser.json(), (req, res) => {})此外,最好使用cloneWith(),而不是传播。
const responseEventMessage = receivedEvent.cloneWith({
source: '/',
type: 'event:response'
});发布于 2021-01-25 18:15:02
嗨,很抱歉给你带来了麻烦。
我对js不是很熟悉,但我们在这里使用的示例是:https://github.com/knative/docs/blob/master/docs/serving/samples/cloudevents/cloudevents-nodejs/index.js#L64
使用.send()而不是.json()
至于配置序列,希望这些示例可以帮助正确配置序列:https://knative.dev/docs/eventing/flows/sequence/
序列状态是否显示任何错误?
最后,您是否在日志中看到任何错误?根据您安装的组件,这可能会有所不同,但如果您运行的是内核,并且使用InMemoryChannel,那么日志将位于knative event命名空间中,并且您将看到imc-dispatcher-* pod,它将在事件构造不正确时提供线索。
https://stackoverflow.com/questions/65854143
复制相似问题