【发布时间】:2020-05-04 11:01:14
【问题描述】:
使用 Boot 2.2.2 和 Integration 5.2.2 - 当 XML 消息来自 File 并且解组失败(即它不是 XML)时,消息会按预期继续到 errorChannel。但是,当消息来自 JMS,通过相同的通道路由并且解组失败时,它不路由到 errorChannel,并且消息回滚到 JMS。之后,对于同一条消息,我陷入了SAXParseException 的无限循环。
我从 Proper ultimate way to migrate JMS event listening to Spring Integration with Spring Boot
开始关注这个例子。是否有一些我没有考虑的隐含交易控制?如何让 Spring Integration 将消息转发到 errorChannel 并从传入队列提交“get”?
代码概要如下;
@Bean
public IntegrationFlow fileReader() {
return IntegrationFlows
.from(
Files
.inboundAdapter( ... )
...
.get(), e -> e.poller(Pollers.fixedDelay(1000))
)
.transform(new FileToStringTransformer())
.channel("backUpChannel")
.get();
}
@Bean
public IntegrationFlow getMessageFromJms(ConnectionFactory connectionFactory, @Value("${queues.myQueue}") String myQueue) {
return IntegrationFlows.from(
Jms
.messageDrivenChannelAdapter(connectionFactory)
.destination(myQueue)
)
.channel("backUpChannel")
.get();
}
@Bean
public IntegrationFlow doBackUp() {
return IntegrationFlows
.from("backUpChannel")
.<String>handle((payload, headers) -> {
String uuid = headers.get(MessageHeaders.ID).toString();
File backUpFile = new File("c:/backup/" + uuid + ".txt");
byte[] payloadContent = payload.getBytes();
try {
java.nio.file.Files.write(backUpFile.toPath(), payloadContent);
} catch (IOException e) {
e.printStackTrace();
}
return payload;
})
.channel("XXX")
.get();
}
@Bean
public Jaxb2Marshaller unmarshaller() {
Jaxb2Marshaller unmarshaller = new Jaxb2Marshaller();
unmarshaller.setClassesToBeBound(MyClass.class);
return unmarshaller;
}
@Bean
public IntegrationFlow handleParseXml() {
return IntegrationFlows
.from("XXX")
.transform(new UnmarshallingTransformer(unmarshaller()))
.channel("YYY")
.get();
}
【问题讨论】:
标签: spring-integration spring-jms