nano icon indicating copy to clipboard operation
nano copied to clipboard

如何 自定义携程任务

Open zhaocy opened this issue 4 years ago • 2 comments

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

zhaocy avatar Aug 03 '20 01:08 zhaocy

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

lonng avatar Aug 03 '20 06:08 lonng

简单来说就是注册 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 调度,而不是全家调度。

lonng avatar Aug 03 '20 06:08 lonng