【问题标题】:Spring Integration Transform Failure rolling back JMS and not forwarding to error channelSpring Integration Transform 失败回滚 JMS 并且不转发到错误通道
【发布时间】: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


    【解决方案1】:

    您需要将.errorChannel(...) 添加到消息驱动的通道适配器中。

    【讨论】:

    • 感谢您的回复。我应该更多地关注参考文档中的第 23.2.1 节。我只是假设它适用于 JMS 调用中的有效负载转换,而不是更进一步的流程。
    • 如果检测到暂时性错误,错误流会抛出异常,消息会被重新排队。
    猜你喜欢
    • 1970-01-01
    • 2016-07-19
    • 1970-01-01
    • 2019-07-20
    • 2017-12-13
    • 2015-02-14
    • 1970-01-01
    • 1970-01-01
    • 2018-11-22
    相关资源
    最近更新 更多