EggBornJS adds a Queue mechanism to allow tasks to be executed in a queue way

Declaration of Queue

src/module/test-party/backend/src/config/config.js

module.exports = appInfo => {
  const config = {};

  // queues
  config.queues = {
    queueTest: {
      path: 'test/feat/queue',
    },
  };

  return config;
};
Name Description
queueTest Queue Name
path API Route to be performed

Declaration of API Route

src/module/test-party/backend/src/routes.js

{ method: 'post', path: 'test/queue', controller: test, middlewares: 'inner' }
Name Description
middlewares Specify the middleware inner, only allowed performed inner access

Controller Action

src/module/test-party/backend/src/controller/test/feat/queue.js

async queue() {
  const message = this.ctx.config.message;
  this.ctx.success(message);
}

Usage of Queue

Return Value

src/module/test-party/backend/src/controller/test/feat/queue.js

async pushAsync() {
  const res = await this.ctx.app.meta.queue.pushAsync({
    subdomain: this.ctx.subdomain,
    module: 'test-party',
    queueName: 'queueTest',
    data: { a: 1, b: 2 },
  });
  assert.equal(res, 3);
  this.ctx.success();
}
Name Description
queue.pushAsync Method Name
subdomain The corresponding subdomain name of the current instance, so as to return to the running environment of the current instance correctly when executing the queue task
module Module Name
queueName Queue Name
data Parameters passed to the queue task

No value returned

src/module/test-party/backend/src/controller/test/feat/queue.js

async push() {
  this.ctx.app.meta.queue.push({
    subdomain: this.ctx.subdomain,
    module: 'test-party',
    queueName: 'queueTest',
    data: { a: 1, b: 2 },
  });
  this.ctx.success();
}