我使用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上出错并在那里执行必要的任务,但是我还没有办法让这个工作。
非常感谢任何想法和帮助!
答案 0 :(得分:1)
您知道我们似乎错过了在Java DSL中为errorChannel
公开EnricherSpec
- 请随时就此问题提出JIRA issue。但无论如何,我们可以访问该属性:
.enrich(e -> {
ContentEnricher contentEnricher =
e.requestChannel(subChannel())
.requestPayload(Message::getPayload)
.propertyExpression("fooId", "payload.id"))
.get().getT2();
contentEnricher.setErrorChannel(enricherErrorChannel());
})
现在,您可以向.handle()
添加任意enricherErrorChannel()
流,并在捕获时处理ErrorMessage
。例如,ErrorMessage
通常payload
包含MessagingException
,failedMessage
我们有payload
属性。确切地说,其中包含有关原始headers
和 function validarRut(textBox) {
var resultado;
$.ajax({
type: "POST",
url: "AgendarInduccion.aspx/validarRut",
data: "{rut:" + JSON.stringify(textBox) + "}",
contentType: "application/json; charset=utf-8",
dataType: "json",
async: false,
success: function(response){
alert("valido");
},
failure: function (response) {
alert("ERROR");
}
});
}
的信息: