事件网关客户端
通过事件网关服务发送消息的库.
怎样用
要使用此库, 您只需遵循以下步骤 安装 npm 的库
npm install @condor-labs/ec-events-gateway
导入库
const { events } = require('@condor-labs/ec-events-gateway');
使用ES6:
import { events } from '@condor-labs/ec-events-gateway':
环境变量
在您中定义变量 .env 数据 带有以下名称的事件网关 api URL 的文件 :
EVENTS_GATEWAY_URL
这就是你需要开始发送数据 到事件网关api.
作为替代,您可以通过一个事件网关 api url 作为参数 :
events.save({payload, type, topic, schema, headers, url: 'http://localhost'});
所需数据
要通过事件网关客户端发送事件, 您必须发送一些所需的字段 :
- 类型:字符串,
- 主题:字符串,
- 有效载荷:物体
客户端Schema
@hapi/joi 不再有效使用 乔 换成
您可以定义一个有效的Joi(Joi QQ17.9.2) schema来验证您发送到事件网关服务的事件数据 .
示例
const schema = {
firstName: Joi.number().required()
};
您可以在Joi API 文档中看到更多实例 网站。 。 。 .
然后把这个计划通过 保存 函数作为参数.
events.save({payload, type, topic, schema, headers, url: 'http://localhost'});
标题 :
您应该定义标题, 以将密钥传递给 Amazon 服务 :
headers: {
'x-api-key': 'value'
}
最大有效载荷大小
请确保有效载荷数据少于 250kb (中文(简体) )