我已经用 Spring Integration 定义了一个很好的流程,在名义上它可以按照我的意愿工作。
但是我还没有想出一种方法来定义处理错误的行为(即将输入行标记为失败)
这是我得到的错误:
[ask-scheduler-2] cMessagingTemplate$TemporaryReplyChannel : Reply message received but the receiving thread has exited due to an exception while sending the request message:ErrorMessage [payload=org.springframework.messaging.MessageHandlingException: error occurred in message handler [outboundGateway]; nested exception is...
这是我的流程配置(简化):
@Configuration
@EnableIntegration
public class IntegrationConfig {
@Autowired
private DataSource dataSource;
@Bean
public IntegrationFlow mainFlow() {
//noinspection unchecked
return IntegrationFlows.from(jdbcMessageSource(),
c -> c.poller(Pollers.fixedRate(5000)
.transactional(transactionManager())))
.split()
.enrich(e -> e
.requestChannel(subChannel())
.requestPayload(Message::getPayload)
.propertyExpression("fooId", "payload.id"))
.handle(barHandler())
.get();
}
@Bean
public IntegrationFlow enricherFlow() {
return IntegrationFlows.from(subChannel())
.handle(outboundGateway())
.get();
}
@Bean
public MessageChannel subChannel() {
return new DirectChannel();
}
@Bean
public MessageSource<Object> jdbcMessageSource() {
return new JdbcPollingChannelAdapter(this.dataSource,
"select * from FOO");
}
@Bean
public JdbcOutboundGateway outboundGateway() {
...
}
@Bean
public JdbcMessageHandler barHandler() {
return new JdbcMessageHandler(dataSource,
"INSERT INTO BAR ...");
}
@Bean
public PlatformTransactionManager transactionManager() {
return new DataSourceTransactionManager(dataSource);
}
}
我原以为我可以在默认的 errorChannel 上得到错误并在那里执行必要的任务,但我还没有找到方法来完成这项工作。
任何想法和帮助都非常感谢!