标签:load log eve tor 处理 demo tps ret header
cloudevents 目前官方提供了不同语言的sdk,以下是js 的简单学习试用,从目前来说更新不是很好
git clone https://github.com/cloudevents/sdk-javascript.git
cd express-ex
yarn
yarn start
demo 的readme 已经提供了比较全的操作说明,我们可以结合这个学习指南
curl -X POST \
-d‘@../payload/v03/structured-event-0.json‘ \
-H‘Content-Type:application/cloudevents+json‘ \
http://localhost:3000/v03
效果
curl -X POST \
-d‘@../payload/v03/structured-event-0.json‘ \
-H‘Content-Type:application/cloudevents+json‘ \
http://localhost:3000/v03
{"specversion":"0.3","id":"b25e2717-a470-45a0-8231-985a99aa9416","type":"com.github.pull.create","source":"https://github.com/cloudevents/spec/pull/123","time":"2019-07-04T17:31:00.000Z","datacontenttype":"application/json","data":{"much":"wow"}}%
curl -X POST \
-d‘@../payload/v03/structured-event-1.json‘ \
-H‘Content-Type:application/cloudevents+json‘ \
http://localhost:3000/v03
效果
curl -X POST \
-d‘@../payload/v03/structured-event-1.json‘ \
-H‘Content-Type:application/cloudevents+json‘ \
http://localhost:3000/v03
{"specversion":"0.3","id":"70d3c768-63f8-40e7-aa9d-d197d530586b","type":"com.github.pull.create","source":"https://github.com/cloudevents/spec/pull/123","time":"2019-07-04T17:31:00.000Z","datacontenttype":"application/json","data":{"much":"wow"},"my-extension":{"some":"thing"}}%
curl -X POST \
-d‘@../payload/data-1.txt‘ \
-H‘Content-Type:application/json‘ \
-H‘ce-specversion:0.3‘ \
-H‘ce-type:com.github.pull.create‘ \
-H‘ce-source:https://github.com/cloudevents/spec/pull/123‘ \
-H‘ce-id:45c83279-c8a1-4db6-a703-b3768db93887‘ \
-H‘ce-time:2019-06-21T17:31:00Z‘ \
-H‘ce-datacontentencoding:base64‘ \
http://localhost:3000/v03
效果
curl -X POST \
-d‘@../payload/data-1.txt‘ \
-H‘Content-Type:application/json‘ \
-H‘ce-specversion:0.3‘ \
-H‘ce-type:com.github.pull.create‘ \
-H‘ce-source:https://github.com/cloudevents/spec/pull/123‘ \
-H‘ce-id:45c83279-c8a1-4db6-a703-b3768db93887‘ \
-H‘ce-time:2019-06-21T17:31:00Z‘ \
-H‘ce-datacontentencoding:base64‘ \
http://localhost:3000/v03
{"specversion":"0.3","id":"45c83279-c8a1-4db6-a703-b3768db93887","type":"com.github.pull.create","source":"https://github.com/cloudevents/spec/pull/123","time":"2019-06-21T17:31:00.000Z","datacontenttype":"application/json","datacontentencoding":"base64","data":{"much":"wow"}}%
const v03 = require("cloudevents-sdk/v03");
var unmarshaller03 = new v03.HTTPUnmarshaller();
?
const v02 = require("cloudevents-sdk/v02");
var unmarshaller02 = new v02.HTTPUnmarshaller();
?
app.post("/v03", function (req, res) {
console.log(req.headers);
console.log(req.body);
?
unmarshaller03.unmarshall(req.body, req.headers)
.then(cloudevent => {
// pretty print
console.log("Accepted event:");
console.log(JSON.stringify(cloudevent.format(), null, 2));
?
res.status(201)
.json(cloudevent.format());
})
.catch(err => {
console.error(err);
res.status(415)
.header("Content-Type", "application/json")
.send(JSON.stringify(err));
});
});
let ce =
v03.event()
.type("com.github.pull.create")
.source("urn:event:from:myapi/resourse/123");
目前js sdk 分装了部分简单编码处理,比如二进制,base64 。。,其他格式的暂时还没有,
https://github.com/cloudevents/sdk-javascript
标签:load log eve tor 处理 demo tps ret header
原文地址:https://www.cnblogs.com/rongfengliang/p/11629646.html