我已实现Spring (boot) integration
,我有一个InboundChannelAdapter
,此方法通过RestTemplate发送Web请求,并将结果传递给Splitter,Filter,最后传递给ServiceActivator,ServiceActivator将数据保存到数据库中。
我希望将消息传递给新的“InboundChannelAdapter
”,以便在将数据保存到数据库后对消息进行一些额外的处理,我该怎么做才能实现这一点?
我的解决方案是正确的吗?
@InboundChannelAdapter(value = "channel1", poller = @Poller("downloadTrigger"))
public ResponseEntity<AppsItemParser[]> download()
{
String url = config.getUrl();
// Call a rest webservice
return responseEntity;
}
@Splitter(inputChannel = "channel1", outputChannel = "channel2")
public List<AppsItemParser> scrape(ResponseEntity<AppsItemParser[]> payload)
{
return new ArrayList<AppsItemParser>(Arrays.asList(payload.getBody()));
}
@Transformer(inputChannel = "channel2", outputChannel = "channel3")
public App convert(AppsItemParser payload)
{
App app = new App();
app.setAddDate(payload.getAddDate());
app.setSize(payload.getSize());
return app;
}
@Filter(inputChannel = "channel3", outputChannel = "channel4")
public boolean filter(App app)
{
final Set<ConstraintViolation<App>> violations = validator.validate(app);
if (violations != null && !violations.isEmpty())
{
return false;
}
return true;
}
@ServiceActivator(inputChannel = "channel4")
public void save(App app)
{
appRepository.save(app);
//Send message to another spring integration flow
}
答案 0 :(得分:2)
入站通道适配器定义流的开始;他们不接收来自其他组件的消息;相反,让您的服务返回结果......
@ServiceActivator(inputChannel = "channel4", outputChannel="next")
public App save(App app)
{
appRepository.save(app);
return app;
}
或
@ServiceActivator(inputChannel = "channel4", outputChannel="next")
public SomeResult save(App app)
{
appRepository.save(app);
return new SomeResult(...);
}