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

[RFC] 需要有更合理的多 Trigger 方案 #165

Closed
whxaxes opened this issue Aug 9, 2022 · 11 comments · Fixed by #188
Closed

[RFC] 需要有更合理的多 Trigger 方案 #165

whxaxes opened this issue Aug 9, 2022 · 11 comments · Fixed by #188
Assignees
Labels
enhancement New feature or request

Comments

@whxaxes
Copy link
Member

whxaxes commented Aug 9, 2022

背景

目前 Trigger 与 ArtusApplication 是一对一的关系,会导致应用如果只有一个 ArtusApplication 实例的情况下,只能有一个上层协议封装,当使用 DefineTrigger 在不同插件中定义了多个 Trigger ,后加载的会直接覆盖掉前面的。

比如:https://github.com/whxaxes/artus-demo/tree/trigger-bug 这个 demo 中同时实现了 http-triggerws-trigger ,如果两个插件同时开启的情况下,只有 ws-trigger 生效( 因为会比 http-trigger 后加载 )。

多 Trigger 在很多业务场景下应该都是很通用的,复杂一些的应用中可能都会同时用到 http 协议、rpc 协议、消息、websocket 等两种以上 trigger 类型的中间件。而目前的设计明显不是很满足场景。

可能的解法

内部沟通后也讨论了一些可能的解法,先列出来:

创建多个 ArtusApplication

由于 Trigger 与 ArtusApplication 的 container 绑定,所以创建 ArtusApplication 可以变相创建多个 Trigger 。

但是由于 ArtusApplication 的创建一般是由工具链或者上层封装框架创建,如果通过多个 ArtusApplication 的方式会导致上层框架或者工具链要去感知插件是否定义了 Trigger ,这个行为会非常割裂。而且如何感知插件中定义的 Trigger 这个实现逻辑也可能会很恶心( 扫描 or 约定? )。

支持多流水线

让 ArtusApplication 与 Trigger 解绑,改成一对多的关系,插件中定义的 Trigger ,能够在 Lifecycle 实例中 Inject 。

Reference:#146

@whxaxes whxaxes changed the title [RFC] 需要有更合理的多 Trigger 模式方案 [RFC] 需要有更合理的多 Trigger 方案 Aug 9, 2022
@whxaxes whxaxes added the enhancement New feature or request label Aug 9, 2022
@whxaxes
Copy link
Member Author

whxaxes commented Sep 5, 2022

让 ArtusApplication 与 Trigger 解绑,改成一对多的关系,插件中定义的 Trigger ,能够在 Lifecycle 实例中 Inject 。

这个目前其实是已经支持,就差将 pipeline 中的 DefineTrigger 和 ArtusApplication 中的 trigger 移除即可

@hyj1991
Copy link
Member

hyj1991 commented Sep 5, 2022

如果只是移除,Trigger 这个基类其实也没有什么存在的必要了,透出一个 interface,给上层自己 implements 其实就行,否则滞留一个单独的 trigger class export 看起来也比较奇怪

@hyj1991
Copy link
Member

hyj1991 commented Sep 5, 2022

现在唯一需要控制用户的其实是 pipline 中需要初始化一个 execution container,不过从另外的角度说,或者 core 不内置 pipeline,让用户自己决定用什么 pipeline 好像也可以

@whxaxes
Copy link
Member Author

whxaxes commented Sep 5, 2022

如果只是移除,Trigger 这个基类其实也没有什么存在的必要了,透出一个 interface,给上层自己 implements 其实就行,否则滞留一个单独的 trigger class export 看起来也比较奇怪

主要是需要实例化一个 execution container ,还有 startPipeline 的逻辑,如果不提供个基类,那就每个都得自己实现了。

@whxaxes
Copy link
Member Author

whxaxes commented Sep 5, 2022

提供个基类我觉得不奇怪把,毕竟 Application 也可以看成是一个基类

@hyj1991
Copy link
Member

hyj1991 commented Sep 5, 2022

Application 是一个主类,trigger 移除掉后,没有和 core 其他部分相关的引用了,单纯一个类 export 出来,稍微有点奇怪

@atian25
Copy link
Member

atian25 commented Sep 5, 2022

想了下,多 Trigger 触发一个 Pipeline 的场景,也许不多。

多 Trigger 触发同个 Pipeline 的场景,我目前想到的只有 Function RPC 场景,即不管前面用户的请求是 http 还是 wgw 过来的,在中间某个阶段都会被抹平掉协议信息,然后丢给这个 Pipeline 后续的用户 Middleware 去处理,响应的时候又封装回协议信息。

这种场景应该不多,绝大部分场景, ws 和 http 可能就是完全不同的 2 个 Pipeline 了,用户有复用的诉求时,他们可以放在 service 里面,然后在 Middleware 里面自行调用。

@whxaxes
Copy link
Member Author

whxaxes commented Sep 5, 2022

就像 Application 是 artus/core 的主类,Trigger 就是 pipeline 的主类,artus/pipeline 感觉不需要内置到 core 里

@hyj1991
Copy link
Member

hyj1991 commented Sep 5, 2022

也可以先只移除引用和装饰器,不移除掉内置的基类,简单验证下 cc @DuanPengfei @noahziheng

@atian25
Copy link
Member

atian25 commented Sep 5, 2022

现在我们都是 RFC 讨论,不用 Discussion 么?

https://github.com/artusjs/spec/discussions 这里的

@hyj1991
Copy link
Member

hyj1991 commented Sep 5, 2022

现在我们都是 RFC 讨论,不用 Discussion 么?

https://github.com/artusjs/spec/discussions 这里的

好习惯没有在一开始养成

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants