@5app/region-sync 中文文档教程

发布于 4年前 浏览 25 项目主页 更新于 3年前

region sync

已知漏洞CircleCI

用我们用于在区域之间同步数据的一些样板逻辑包装 SNS/SQS:

SNS+SQS:

  1. structure all messages with date, fromRegion and JSON encoded payload.

SQS:

  1. prevents handlers being called if source + dest regions are the same
  2. deletes messages after handler has handled (if successful)
  3. sets up the continuous long poll

SQS usage:

const {createHandler} = require('@5app/region-sync');
const queueUrl = 'http://localhost:4576/000000000000/fooq';
const handler = createHandler({
    backoffSeconds: 4,
    longPollSeconds: 1,
    currentRegion: 'us-east-1',
});

handler.addQueueHandler(queueUrl, async function (msg) {
    // handle it, but if promise rejects, the message wont be removed.
});

SNS usage:

const {createPublisher} = require('@5app/region-sync');
const payload = {foo: 'bar'};
const publisher = createPublisher({
    currentRegion: 'us-east-1',
    snsRegion: 'us-east-1',
});
await publisher.publish(topicArn, payload);

testing

LOGS_LEVEL=info npm test

region sync

Known VulnerabilitiesCircleCI

Wraps SNS/SQS with some boilerplate logic we use for syncing data between regions:

SNS+SQS:

  1. structure all messages with date, fromRegion and JSON encoded payload.

SQS:

  1. prevents handlers being called if source + dest regions are the same
  2. deletes messages after handler has handled (if successful)
  3. sets up the continuous long poll

SQS usage:

const {createHandler} = require('@5app/region-sync');
const queueUrl = 'http://localhost:4576/000000000000/fooq';
const handler = createHandler({
    backoffSeconds: 4,
    longPollSeconds: 1,
    currentRegion: 'us-east-1',
});

handler.addQueueHandler(queueUrl, async function (msg) {
    // handle it, but if promise rejects, the message wont be removed.
});

SNS usage:

const {createPublisher} = require('@5app/region-sync');
const payload = {foo: 'bar'};
const publisher = createPublisher({
    currentRegion: 'us-east-1',
    snsRegion: 'us-east-1',
});
await publisher.publish(topicArn, payload);

testing

LOGS_LEVEL=info npm test
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文