问题描述
在 Maven 多模块项目中使用 Spring-boot 时,我一直试图找出一种模式来满足 SOLID 依赖倒置原则。目标是在我的消息提供者和消费者之间建立一个抽象层。这样我就可以轻松地更换我的消息提供程序并保持松散耦合。
ModuleA -> Spring-boot Kafka Consumer(应该很容易更换)
ModuleB -> 抽象消息提供者(应该能够转换消息)
ModuleC -> MyMessage Processor(应该能够将转换后的消息用于业务逻辑)
根据SOLID原则:
ModuleC 应该依赖于 ModuleB
模块 A 应该依赖于模块 B
在 Maven 多模块项目中使用带有依赖项注入的 Spring-boot 使这件事变得复杂。
In ModuleA I receive messages using Apache Kafka libraries,all contained in its own maven module.
In ModuleB I expose a Java LinkedBlockingQueue that ModuleA can fill with messages as they come in.
It's here that I transform the message. To make the messages available to ModuleC I expose an
Observable Class as a Spring @Component.
In ModuleC I Inject the ModuleB Component and add an Observer to detect new messages.
这一切都有效,这里是 code 供所有人查看。
这是错误的吗?有没有正确的Spring方法来做到这一点?虽然它有效,但对我来说,它闻起来有些不对劲。
谢谢。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)