gpt4 book ai didi

java - 将消息从 ServiceActivator 传递到新的 InboundChannelAdapter

转载 作者:行者123 更新时间:2023-12-02 02:36:21 25 4
gpt4 key购买 nike

我已经实现了Spring(启动)集成,我有一个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
}

最佳答案

入站 channel 适配器定义流的开始;它们不接收来自其他组件的消息;相反,让您的服务返回结果...

@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(...);
}

关于java - 将消息从 ServiceActivator 传递到新的 InboundChannelAdapter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46263173/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com