您如何使用 JPA 数据库 table 动态管理 IntegrationFlow Spring bean?

How might you manage IntegrationFlow Spring beans dynamically using a JPA database table?

我有一个场景,我希望根据 JPA 数据库的内容注册 IntegrationFlow Spring bean table。

例如,table 看起来像:

@Entity
class IntegrationFlowConfig {
  private long id;
  private String local;
  private String remote;

}

并且我希望为在上述 table 定义中找到的每个条目将 IntegrationFlow 注册为 Spring bean。增加一行时,注册一个新的bean,删除一行时,销毁对应的bean。

我考虑过为上述实体创建一个 EntityListener,其中@PostPersist 和@PostRemove 将通过 IntegrationFlowContext create/destroy IntegrationFlow beans,但这个解决方案似乎有点笨拙,我想知道是否有任何现有的功能都可以更简化地解决上述问题。也许某种行映射功能可以将 spring bean 映射到 JPA 数据库行等?

如有任何帮助,我们将不胜感激!

谢谢,

和尚

好吧,这样的想法过去曾多次闪过我的脑海。但是,即使 XML 配置很容易序列化为数据库并反序列化为 Integration Flow (XML one) in its own child ApplicationContext, we still ended up with the problem that some beans have to be provided with their Java code. Even if we opted out for Groovy scripts,可以在运行时解析和加载,一些 Java 代码仍然需要编译。最后,当我们为客户发布一些解决方案时,他们的操作员如何编写这些动态流程变得非常混乱,容易出错。

你当然可以有一些外部配置选项,可以有条件逻辑,但是代码仍然必须提前编译,没有任何办法让逻辑(不是数据)在运行时被序列化和反序列化。

可能这不是您正在寻找的答案,但是没有这样的序列化解决方案并且可能根本不会完成,因为动态应用这些是一种反模式(恕我直言)我们可以简单地处理简短的微服务甚至功能的日子。