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

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

问题描述

我有一个事件驱动架构,其中 A 等待 B 的更改,B 等待 C 的更改,C 等待 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.

现在,如果 B 发生变化,则 A 向 C 触发一个事件,C 触发事件,B 触发事件,A 触发事件,C 触发事件......无限.

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?

推荐答案

循环依赖真的很糟糕.在我觉得有意义之前,我不得不根据 A、B 和 C 写下您的帖子.我认为你应该摆脱它.如果你把自己逼到绝境,这可能比循环依赖可能遇到的问题要好得多.

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.

你也绝对可以避免这种情况.A、B 和 C 确实是紧耦合的.我认为你需要重新考虑他们的责任.也许有一个通用的 D 元素可以减轻您的设计压力.

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.

我想到的其他东西是建筑分层.如果您可以将 A 置于 B 之上,并且需要与 B 交谈的任何人进行通信以通过 A 并向下传递,那么您可能会更轻松.再说一次,我对你的问题不太了解,所以这些只是粗略的建议.

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.

祝你好运!

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

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