Skip to content
New issue

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

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

Already on GitHub? # to your account

如何 自定义携程任务 #62

Open
zhaocy opened this issue Aug 3, 2020 · 2 comments
Open

如何 自定义携程任务 #62

zhaocy opened this issue Aug 3, 2020 · 2 comments
Labels

Comments

@zhaocy
Copy link

zhaocy commented Aug 3, 2020

@lonng 消息默认转发给全局携程处理,如何根据业务请求自定义携程。有没有示例

@zhaocy zhaocy added the question label Aug 3, 2020
@lonng
Copy link
Owner

lonng commented Aug 3, 2020

@zhaocy 可以把消息转发给自定义的携程处理,只需要对应的服务实现 Scheduler 接口就可以了。
参考 https://github.com/lonng/nano/blob/master/cluster/handler.go#L452

@lonng
Copy link
Owner

lonng commented Aug 3, 2020

简单来说就是注册 service 的时候为这个 service 指定一个 scheduler name (https://github.com/lonng/nano/blob/master/component/options.go#L50),然后讲这个 scheduler 绑定要 session。

  1. component.WithSchedulerName(xx)
  2. session.Set("xx", scheduler)

然后对应服务的消息就会让这个 scheduler 调度,而不是全家调度。

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

No branches or pull requests

2 participants