Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add Subscription #1469

Merged
merged 4 commits into from
Oct 20, 2017
Merged

feat: add Subscription #1469

merged 4 commits into from
Oct 20, 2017

Conversation

popomore
Copy link
Member

@popomore popomore commented Sep 27, 2017

Checklist
  • npm test passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)
Description of change

Ref #1468

@atian25
Copy link
Member

atian25 commented Oct 17, 2017

@popomore 这个也要发掉了,不然 egg-schedule 的新用户按文档写会报错

@atian25
Copy link
Member

atian25 commented Oct 18, 2017

ping

@popomore popomore force-pushed the Subscription branch 2 times, most recently from 43f0d5c to 1b121dc Compare October 19, 2017 06:16
@codecov-io
Copy link

codecov-io commented Oct 19, 2017

Codecov Report

Merging #1469 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1469      +/-   ##
==========================================
+ Coverage   99.71%   99.72%   +<.01%     
==========================================
  Files          29       29              
  Lines         714      715       +1     
==========================================
+ Hits          712      713       +1     
  Misses          2        2
Impacted Files Coverage Δ
index.js 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7fb9bbf...9878128. Read the comment docs.

@popomore
Copy link
Member Author

@atian25 看看

const Subscription = require('egg').Subscription;
class Schedule extends Subscription {
// This method should be implemented
* subscribe() {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里可以是 generator / promise / async 吧?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是的

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

嗯,所以文档要注明下?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

subscribe could be generator / async function

@@ -270,6 +270,22 @@ module.exports = {

我们可以在 Controller 和 Service 实例上通过 `this.logger` 获取到它们,它们本质上就是一个 Context Logger,不过在打印日志的时候还会额外的加上文件路径,方便定位日志的打印位置。

## Subscription

Subscription 是一种订阅模型,消息中间件的消费者或调度任务都属于这种模式。
Copy link
Member

@atian25 atian25 Oct 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

订阅模型是一种比较常见的开发模式,譬如消息中间件的消费者或调度任务。因此我们提供了 Subscription 基类来规范化这个模式。

使用方式如下:
...
...
...

开发者可以根据自己的需求,基于它定制特定的订阅规范,如 [定时任务](./schedule.md) 就是使用这种模式实现的,建议开发者可以参考来实现自己的消息中间件。

Copy link
Member

@atian25 atian25 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@popomore popomore merged commit 46ed6fa into master Oct 20, 2017
@popomore popomore deleted the Subscription branch October 20, 2017 11:25
popomore pushed a commit that referenced this pull request Oct 20, 2017
feat: add Subscription (#1469)

Ref #1468
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants