Spring集成-包括错误中的有效负载

扬·弗拉基米尔·莫斯特(Jan Vladimir Mostert)

我试图将inputMessage有效内容包含在错误中,但似乎从未传递过,并且充实似乎也不起作用。

我有一个目录轮询服务:

<file:inbound-channel-adapter
        id="incomingFiles"
        auto-startup="true"
        auto-create-directory="false"
        channel="myFiles"
        filename-pattern="${directory.local.pattern}"
        directory="file:${directory.local}">
    <int:poller id="poller" fixed-delay="${directory.local.poll}"/>
</file:inbound-channel-adapter>

这些文件然后通过SFTP上传:

<sftp:outbound-channel-adapter
        id="sftpOutboundAdapter"
        channel="myFiles"
        charset="UTF-8"
        remote-directory="${directory.remote}"
        session-factory="sftpSessionFactory">
    <sftp:request-handler-advice-chain>
        <bean class="org.springframework.integration.handler.advice.ExpressionEvaluatingRequestHandlerAdvice">
            <property name="onSuccessExpression" value="payload.delete()"/>
            <property name="successChannel" ref="successChannel"/>
            <property name="onFailureExpression" value="payload.renameTo(payload.absolutePath + '.error')"/>
            <property name="failureChannel" ref="failChannel" />
        </bean>
    </sftp:request-handler-advice-chain>
</sftp:outbound-channel-adapter>

在成功通道上,我将其记录并通过successChannel发送和发送,在该通道上另一个服务将其拾取并发送电子邮件,这可以100%起作用:

    <!-- Log Channel -->
    <int:logging-channel-adapter id="logChannel" level="INFO"/>

    <!-- Success Endpoint -->
    <int:channel id="successChannel">
        <int:interceptors>
            <int:wire-tap channel="successLogChannel"/>
        </int:interceptors>
    </int:channel>

    <!-- Success Logging -->
    <int:channel id="successLogChannel"/>
    <int:transformer
            input-channel="successLogChannel"
            output-channel="logChannel"
            expression="'Successfully transferred ' + inputMessage.payload.absolutePath"/>

    <!-- Send success email -->
    <int:chain input-channel="successChannel">
        <int:header-enricher>
            <int:header name="to" value="${success.email.to}"/>
            <int:header name="from" value="${success.email.from}" />
            <int:header name="subject" value="${success.email.subject}"/>
            <int:header name="filename" expression="inputMessage.payload.absolutePath"/>
        </int:header-enricher>
        <int:service-activator ref="Email" method="sendSuccessMail"/>
    </int:chain>

org.springframework.integration.handler.LoggingHandler-成功传输/tmp/test-file.dat

现在,当我尝试完全相同的错误时,表达式inputMessage.payload.filename无法求值。

    <!-- Fail Endpoint -->
    <int:channel id="failChannel">
        <int:interceptors>
            <int:wire-tap channel="failLogChannel"/>
        </int:interceptors>
    </int:channel>

    <!-- Fail Logging -->
    <int:channel id="failLogChannel"/>
    <int:transformer
            input-channel="failLogChannel"
            output-channel="logChannel"
            expression="'Failed to transfer ' + inputMessage.payload.absolutePath"/>

    <!-- Send fail email -->
    <int:chain input-channel="failChannel">
        <int:header-enricher>
            <int:header name="to" value="${fail.email.to}"/>
            <int:header name="from" value="${fail.email.from}" />
            <int:header name="subject" value="${fail.email.subject}"/>
            <int:header name="filename" expression="inputMessage.payload.absolutePath"/>
        </int:header-enricher>
        <int:service-activator ref="Email" method="sendFailMail"/>
    </int:chain>

错误org.springframework.integration.handler.LoggingHandler-org.springframework.integration.transformer.MessageTransformationException:org.springframework.integration.MessageHandlingException:表达式求值失败:'无法传输'+ inputMessage.payload.absolutePath

我曾尝试添加标头增强器,但是当出现错误时,似乎有效负载甚至都不会脱离SFTP出站通道:

    <!-- Fail Endpoint -->
    <int:channel id="failChannel"/>
    <int:chain input-channel="failChannel" output-channel="failChannelEnriched">
        <int:header-enricher>
            <int:header name="to" value="${fail.email.to}"/>
            <int:header name="from" value="${fail.email.from}"/>
            <int:header name="subject" value="${fail.email.subject}"/>
            <int:header name="filename" expression="inputMessage.payload.absolutePath"/>
        </int:header-enricher>
    </int:chain>


    <int:channel id="failChannelEnriched">
        <int:interceptors>
            <int:wire-tap channel="failLogChannel"/>
        </int:interceptors>
    </int:channel>

    <!-- Fail Logging -->
    <int:channel id="failLogChannel"/>
    <int:transformer
            input-channel="failLogChannel"
            output-channel="logChannel"
            expression="'Failed to transfer ' + headers['filename']"/>

    <!-- Send fail email -->
    <int:chain input-channel="failChannelEnriched">
        <int:service-activator ref="Email" method="sendFailMail"/>
    </int:chain>

错误org.springframework.integration.handler.LoggingHandler-org.springframework.integration.transformer.MessageTransformationException:org.springframework.integration.MessagingException:无法转换消息头

...

由以下原因引起:org.springframework.expression.spel.SpelEvaluationException:EL1008E :(位置0):在类型为“ org.springframework.integration.message.ErrorMessage”的对象上找不到字段或属性“ inputMessage”

在org.springframework.expression.spel.ast.PropertyOrFieldReference.readProperty(PropertyOrFieldReference.java:246)处

查看spring文档,可以看到它org.springframework.integration.message.ErrorMessage确实接受标头,但是不知何故没有设置标头。

有什么建议吗?

加里·罗素

为了成功,将特别节目AdviceMessage发送给频道;具有inputMessage属性(有效负载是表达式求值的结果)。

对于错误情况,将法线ErrorMessage发送到通道;否则,向通道发送法线其有效负载是MessagingException具有正常属性的:(cause发生的异常)和failedMessage

实际的例外是MessageHandlingExpressionEvaluatingAdviceException它具有evaluationResult包含表达式评估结果的附加属性

因此,您需要针对失败案例使用不同的表达式payload.failedMessage.payload.absolutePath

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

在调试级别从Spring集成日志中删除有效负载

来自分类Dev

在Spring集成中,将多个有效负载嵌入“消息”对象中的最佳方法是什么?

来自分类Dev

Spring集成出站通道,供Gemfire存储有效负载

来自分类Dev

通过有效负载的部分类型进行Spring集成消息路由

来自分类Dev

RestEasy Spring集成错误

来自分类Dev

Spring集成聚合错误

来自分类Dev

带有集成器的spring集成sftp

来自分类Dev

从http入站网关提取XML有效负载,并提供给xslt转换器spring集成

来自分类Dev

请求有效负载中的字段在 spring 启动资源中显示为空

来自分类Dev

如何从Spring Cloud Stream kafka的ErrorMessage中的有效负载中获取failedMessage?

来自分类Dev

带有注解的 Spring 集成窃听(4.3 Spring 集成)

来自分类Dev

Spring MVC中的Elasticsearch集成?

来自分类Dev

Spring集成中的串行处理

来自分类Dev

Spring集成中的串行处理

来自分类Dev

Spring中的SimpleTriggerFactoryBean与javaconfig集成

来自分类Dev

Spring集成中的Bean定义

来自分类Dev

如何处理spring集成中的错误

来自分类Dev

如何从 Spring Integration int-http:outbound-gateway 中的 byte[] 消息中获取有效负载值?

来自分类Dev

Spring集成错误通道在JUnit中没有消息

来自分类Dev

Spring Integration在有效负载表达式中结合了路径变量和帖子主体

来自分类Dev

Spring Integration:http:入站通道适配器-未在有效负载中获取json对象

来自分类Dev

Spring Hibernate集成错误,属性转换错误

来自分类Dev

带有注释的JDBC Spring集成

来自分类Dev

带有注释的JDBC Spring集成

来自分类Dev

带有JDBC集成的Spring会话

来自分类Dev

没有SpringBoot的Spring缓存Caffeine集成

来自分类Dev

带有JDBC集成的Spring会话

来自分类Dev

401中的Spring Boot集成测试结果

来自分类Dev

在Spring集成中限制jsch的输出

Related 相关文章

  1. 1

    在调试级别从Spring集成日志中删除有效负载

  2. 2

    在Spring集成中,将多个有效负载嵌入“消息”对象中的最佳方法是什么?

  3. 3

    Spring集成出站通道,供Gemfire存储有效负载

  4. 4

    通过有效负载的部分类型进行Spring集成消息路由

  5. 5

    RestEasy Spring集成错误

  6. 6

    Spring集成聚合错误

  7. 7

    带有集成器的spring集成sftp

  8. 8

    从http入站网关提取XML有效负载,并提供给xslt转换器spring集成

  9. 9

    请求有效负载中的字段在 spring 启动资源中显示为空

  10. 10

    如何从Spring Cloud Stream kafka的ErrorMessage中的有效负载中获取failedMessage?

  11. 11

    带有注解的 Spring 集成窃听(4.3 Spring 集成)

  12. 12

    Spring MVC中的Elasticsearch集成?

  13. 13

    Spring集成中的串行处理

  14. 14

    Spring集成中的串行处理

  15. 15

    Spring中的SimpleTriggerFactoryBean与javaconfig集成

  16. 16

    Spring集成中的Bean定义

  17. 17

    如何处理spring集成中的错误

  18. 18

    如何从 Spring Integration int-http:outbound-gateway 中的 byte[] 消息中获取有效负载值?

  19. 19

    Spring集成错误通道在JUnit中没有消息

  20. 20

    Spring Integration在有效负载表达式中结合了路径变量和帖子主体

  21. 21

    Spring Integration:http:入站通道适配器-未在有效负载中获取json对象

  22. 22

    Spring Hibernate集成错误,属性转换错误

  23. 23

    带有注释的JDBC Spring集成

  24. 24

    带有注释的JDBC Spring集成

  25. 25

    带有JDBC集成的Spring会话

  26. 26

    没有SpringBoot的Spring缓存Caffeine集成

  27. 27

    带有JDBC集成的Spring会话

  28. 28

    401中的Spring Boot集成测试结果

  29. 29

    在Spring集成中限制jsch的输出

热门标签

归档