spring - 如何将部分源数据属性发送到不同的目标
问题描述
我正在建立一个源和两个目标之间的集成,这里源数据对象有 10 个属性,其中一个目标需要大约 6 个属性,另一个目标只需要 4 个属性,感谢任何关于我如何使用 spring 实现的帮助
解决方案
您可以配置源以将消息发送到PublishSubscribeChannel
.
然后配置两个Transformer订阅这个 pub-sub 频道。其中一个转换器将消息转换为 6 个属性版本,而另一个转换为 4 个属性版本。然后两个转换器将转换后的消息发送到一个单独的通道。两个目标系统将查找发送到这些分离通道的消息并处理它们。
在注解配置方面,如下所示:(假设源发出的消息是Foo
)
@Bean
public MessageChannel pubSubChannel() {
return new PublishSubscribeChannel();
}
@Bean
public MessageChannel outputChannelWith4Attributes() {
return new DirectChannel();
}
@Bean
public MessageChannel outputChannelWith6Attributes() {
return new DirectChannel();
}
@Component
public class MyTransformer {
@Transformer(inputChannel = "pubSubChannel", outputChannel = "outputChannelWith4Attributes")
public Foo transformTo4Attribute(Foo foo) {
//do the transformation logic here
return result;
}
@Transformer(inputChannel = "pubSubChannel", outputChannel = "outputChannelWith6Attributes")
public Foo transformTo6Attribute(Foo foo) {
//do the transformation logic here
return result;
}
}
并配置源以将带有有效负载的消息发送Foo
到。还pubSubChannel
配置目标以处理来自outputChannelWith4Attributes
和的消息outputChannelWith6Attributes
。
推荐阅读
- python - 如何使用 psycopg 将时间戳字符串插入 postgres db?
- java - 如何从可选映射中获取值?
- sqlite - 我想知道我的查询是否会起作用,因为它与解决方案不同,而且它只是一个没有数据库的理论任务
- reactjs - 在 Typescript 中为 React Bootstrap DropdownItem 正确声明回调方法
- java-8 - CompletableFuture - 如何在未来结果中使用局部变量
- css - 使用 Material UI 和 CSS 隐藏曲线标题下的抽屉
- amazon-web-services - 加速 AWS Lambda 执行
- flutter - 如何从用户那里获取正确的家庭住址?
- dll - 如何解决错误 0xc0000139
- python-3.x - “gym.envs.box2d”的 COLAB 上的 RL 问题没有属性“LunarLander”