【问题标题】:How to put object to Gemfire Cache in Spring Integration DSL?如何在 Spring Integration DSL 中将对象放入 Gemfire 缓存?
【发布时间】:2018-08-16 11:24:43
【问题描述】:
我有集成流程,我想在步骤之间将流程中的实体写入我的 Gemfire 缓存,但我不知道该怎么做。
@Bean
public IntegrationFlow myFlow(CacheEntityDAL cacheDAL,Transformer t,
MyFilter f) {
return IntegrationFlows.from("inChannel")
.transform(t) //returns the entity
//I want to put to my cacheDAL.put(entity) here
.filter(f)
.channel("outChannel")
.get();
}
谢谢
【问题讨论】:
标签:
java
spring-data
spring-integration
gemfile
spring-integration-dsl
【解决方案1】:
要写入 Gemfire 缓存,您需要使用来自 Spring Integration Gemfire 支持的 CacheWritingMessageHandler。
但是由于这个是one-way,它只是为了写,没有直接的方法将它插入到流程的中间。另一方面,您只想存储并使用相同的有效负载继续下游。为此,我建议使用PublishSubscribeChannel 和两个订阅者:一个提到的CacheWritingMessageHandler,然后是其余的流程。像这样的:
return IntegrationFlows.from("inChannel")
.transform(t) //returns the entity
.publishSubscribeChannel(c -> c
.subscribe(sf -> sf
.handle(new CacheWritingMessageHandler(gemfireRegion()))
.filter(f)
.channel("outChannel")
.get();
所以,这样你发送到 Gemfire 并移动到主流程,下一个 filter()
将成为第二个订阅者,直到 Gemfire 的第一个订阅者成功。