加入 CCR 中的 PortSet
我有 4 个服务,每个服务都有一个具有如下签名的方法:
PortSet<Response1, Exception> GetData1(Request1 request);
PortSet<Response2, Exception> GetData2(Request2 request);
PortSet<Response3, Exception> GetData3(Request3 request);
PortSet<Response4, Exception> GetData4(Request4 request);
我需要同时运行它们,并分别连接来自每个端口的最终结果、处理结果和异常。你能建议我该怎么做吗?
我只能找到加入来自 Port 的结果的可能性,而不是来自 PortSet 的结果。
谢谢
I have 4 services, each has a method with the signature like this:
PortSet<Response1, Exception> GetData1(Request1 request);
PortSet<Response2, Exception> GetData2(Request2 request);
PortSet<Response3, Exception> GetData3(Request3 request);
PortSet<Response4, Exception> GetData4(Request4 request);
I need to run them concurrently and join the final result, processing result and exception that comes from each port separately. Could you please suggest how do I do this?
I was able to find only possibility to join the results from the Port's, not from PortSet's.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的解决方案在某种程度上受到所涉及的类数量的限制。我建议在每个
PortSet
上激活Choice
接收器,并在每个处理程序中激活Post
到完成端口。在完成端口上,当它们全部完成时,您可以使用Join
。所以,我突然想到,假设您是从CcrServiceBase
派生的(否则您将需要使用Arbiter.Activate
而不是简洁的Activate
):如果您有一个通用的
Response
类型,则可以将您的调用构造为如下所示:因此,您无需使用
GetData
调用创建新的PortSet
,而是提供一个通用的PortSet
并将其提供给GetData方法。
现在,您可以执行多项接收:
Your solution is somewhat limited by the number of classes involved. I'd suggest activating
Choice
receivers on eachPortSet
, and in each handler toPost
to a completion port. On the completion port, you could use aJoin
when they all complete.So, off the top of my head, and assuming you are deriving fromCcrServiceBase
(otherwise you'll need to useArbiter.Activate
instead of the terserActivate
):If instead you had a common
Response
type, you could instead structure your calls as follows:so instead of the
GetData
call creating a newPortSet
, you provide a commonPortSet
and supply it to theGetData
methods.Now, you can perform a multiple item receive: