From a3f6407d70345fbe12c84b0bad454f01966c7b6c Mon Sep 17 00:00:00 2001 From: popomore Date: Thu, 19 Oct 2017 15:54:47 +0800 Subject: [PATCH] f --- docs/source/en/basics/objects.md | 16 ++++++++++++++++ docs/source/zh-cn/basics/objects.md | 16 ++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/docs/source/en/basics/objects.md b/docs/source/en/basics/objects.md index bbe71048e6..6d326d12e4 100644 --- a/docs/source/en/basics/objects.md +++ b/docs/source/en/basics/objects.md @@ -270,6 +270,22 @@ We can get it via `ctx.coreLogger`, the difference between the Context Logger is We can get them via `this.logger` in Controller and Service instance, they are essentially a Context Logger, but additional file path will be added to logs, easy to locate the log print location. +## Subscription + +Subscription is the model for subscribing, including consumer in message broker or schedule. + +The base class of Subscription is exported by egg. + +```js +const Subscription = require('egg').Subscription; +class Schedule extends Subscription { + // This method should be implemented + * subscribe() {} +} +``` + +[Schedule](./schedule.md) is implemented using the model,also recommend the plugin for message broker. + [Koa]: http://koajs.com [Koa.Application]: http://koajs.com/#application [Koa.Context]: http://koajs.com/#context diff --git a/docs/source/zh-cn/basics/objects.md b/docs/source/zh-cn/basics/objects.md index eec9fcb3a9..023a973ca2 100644 --- a/docs/source/zh-cn/basics/objects.md +++ b/docs/source/zh-cn/basics/objects.md @@ -270,6 +270,22 @@ module.exports = { 我们可以在 Controller 和 Service 实例上通过 `this.logger` 获取到它们,它们本质上就是一个 Context Logger,不过在打印日志的时候还会额外的加上文件路径,方便定位日志的打印位置。 +## Subscription + +Subscription 是一种订阅模型,消息中间件的消费者或调度任务都属于这种模式。 + +可以通过以下方式来引用 Subscription 基类: + +```js +const Subscription = require('egg').Subscription; +class Schedule extends Subscription { + // 是需要实现此方法 + * subscribe() {} +} +``` + +[定时任务](./schedule.md)使用这种模式实现,也建议使用此模型实现消息中间件。 + [Koa]: http://koajs.com [Koa.Application]: http://koajs.com/#application [Koa.Context]: http://koajs.com/#context