事件驱动架构...无限循环 [英] Event driven architecture...infinite loop

查看:178
本文介绍了事件驱动架构...无限循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个事件驱动架构,其中A正在等待B中的更改,B等待C中的更改,C等待从A更改,形成一个循环。现在,如果B改变了,那么A将一个事件触发到C,它触发到B,它触发到A,它触发到C ... ad infinitum。



我现在可以改变我的程序,不包含这个循环,但我担心的是,我可以在稍后的时间把自己放在一个角落。

解决方案

循环依赖是非常糟糕的。我不得不在A,B和C方面写下你的文章,甚至对我来说是有意义的。我想你应该摆脱它。如果你把自己放在一个角落,这可能比循环依赖的问题好多了。



你也可以避免这种情况。 A,B和C真的很紧密。我想你需要重新考虑他们的责任。也许有一个常见的D元素会使你的设计压力很大。



其他想法是建筑分层。如果您可以在B上层A,并且要求任何与B通话的人进行通信,通过A和下层,您可以给自己一个更容易的时间。再次,我不太了解你的问题,所以这些只是广泛的建议。



最后一个选择,我最不喜欢的是在每个的三个组成部分。当每个被访问时,要求每个组件添加到消息中已经看到该消息。那么获取消息的下一个组件就有关于谁看到它的信息。类似注册表。但再次,最不喜欢。尝试别的东西。



祝你好运!


I have an event driven architecture where A is waiting for a change from B and B is waiting for a change from C and C is waiting for a change from A, forming a cycle.

Now, if B changes, then A fires an event to C, which fires to B, which fires to A, which fires to C...ad infinitum.

I can change my program right now to not contain this cycle, but I am concerned I may put myself into a corner at a later time where I cannot. How does one keep such things from happening when designing event based systems?

解决方案

Cyclic dependencies are really bad. I had to write down your post in terms of A, B, and C before it even made sense to me. I think you should get rid of it. If you're putting yourself in a corner, it's probably a whole lot better than the problems you can run into with cyclic dependencies.

You can definitely avoid this, too. A, B, and C are really tightly coupled. I think you need to rethink their responsibilities. Perhaps there's a common D element that'll take a lot of your design-stress away.

Something else that comes to mind is architectural Layering. If you can layer A over B, and require communication by anyone speaking to B to go through A and down the layers, you might give yourself an easier time. Again, I don't know much about your problem, so these are just broad suggestions.

One final option, and my least favorite, is to pass a message between each of the three components. As each is visited, require that each component add to the message that it has seen the message. Then the next component to get the message has information about who's seen it. Kind of like a sign up sheet. But again, least favorite. Try something else first.

Good luck!

这篇关于事件驱动架构...无限循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆