[英]RX IObservable as a Pipeline
Currently, I'm using the RX Framework to implement a workflow-like message handling pipeline. 目前,我正在使用RX Framework来实现类似工作流的消息处理管道。 Essentially I have a message producer (deserializes network messages and calls OnNext() on a Subject) and I have several consumers.
基本上我有一个消息生成器(反序列化网络消息并在Subject上调用OnNext())我有几个消费者。
NOTE: If and transform are extension methods I have coded that simply return an IObservable. 注意:如果和transform是扩展方法,我编写的只是返回一个IObservable。
A consumer does something like the following: 消费者会执行以下操作:
var commerceRequest = messages.Transform(x => GetSomethingFromDatabase(x)
.Where(y => y.Value > 5)
.Select(y => y.ComplexObject)
.If(z => z.IsPaid, respond(z))
.Do(z => SendError(z));
commerceRequest
is then consumed by another similar pipeline and this continues up until the top where it ends with someone calling Subscribe()
on the final pipeline. 然后,另一个类似的管道消耗了
commerceRequest
,并且这种情况一直持续到顶部,并且最终管道上有人调用了Subscribe()
。 The issue I'm having is that the messages from the base don't propagate up unless subscribe is called on messages directly somewhere. 我遇到的问题是来自基站的消息不会传播,除非直接在某处调用消息。
How can I push the messages up to the top of the stack? 如何将消息推送到堆栈顶部? I know this is an unorthodox approach but I feel it makes the code very simple to understand what is occurring to a message.
我知道这是一种非正统的方法,但我觉得它使代码很容易理解消息发生了什么。 Can anyone suggest another way of doing the same if you feel this is a totally terrible idea?
如果你认为这是一个非常可怕的想法,有人可以提出另一种方法吗?
Why should they go through the pipeline if there are no subscribers? 如果没有订户,他们为什么要通过管道呢? If one of your intermediate steps is useful for their side-effects (You want them to run even if there are no other subscribers), you should rewrite the side-effect operation to be a subscriber.
如果你的一个中间步骤对它们的副作用很有用(即使没有其他订阅者,你希望它们运行),你应该将副作用操作重写为订阅者。
You could also make the step with a side-effect as a pass-through operation (or tee, if you will) if you wanted to continue the chain. 如果你想继续使用链条,你也可以使用副作用作为传递操作(或tee,如果你愿意)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.