【问题标题】:Endpoint info in the request-handler-advice-chain请求处理程序建议链中的端点信息
【发布时间】:2016-09-20 15:44:52
【问题描述】:

我的要求是计算外部资源(如 jdbc、web 服务等)消耗的总时间,

我在所需的端点中添加了 request-handler-advice-chain 并计算了时间。它完美地工作。 我还必须添加端点组件的标识符。有什么方法可以通过建议类获取端点 ID。

例如:

    <int-jdbc:stored-proc-outbound-gateway id="myProcID" request-channel="myChannel" data-source="dataSource"
....
        <int-jdbc:request-handler-advice-chain>
             <ref bean="statsAdvice" />
        </int-jdbc:request-handler-advice-chain> 
    </int-jdbc:stored-proc-outbound-gateway>

我可以在建议类中获取 jdbc 端点 ID 吗?请建议。 提前致谢。

Advice 类扩展 AbstractRequestHandlerAdvice 并且当我尝试强制转换时 NamedComponent 组件 = (NamedComponent) 目标;

我收到以下异常 - org.springframework.messaging.MessageHandlingException: error occurred in message handler [org.springframework.integration.jdbc.StoredProcOutboundGateway#0]; nested exception is java.lang.ClassCastException: org.springframework.integration.handler.AbstractReplyProducingMessageHandler$AdvisedRequestHandler

修复在 4.3.2 版本中运行良好:

((AbstractReplyProducingMessageHandler.RequestHandler) target).getAdvisedHandler().getComponentName();

【问题讨论】:

    标签: spring-integration


    【解决方案1】:

    如果您的建议扩展 AbstractRequestHandlerAdvice,则目标对象可用作 doInvoke 中的参数 - 请参阅 the javadocs

    将其发送至NamedComponent 并致电getComponentName()

    如果您直接实现了MethodInterceptor,请使用invocation.getThis() 获取对处理程序的引用。

    【讨论】:

    • 非常感谢您的帮助。
    • 哦,是的;对不起;我忘记了那个包装器——我们应该提供对其委托的访问;请打开改进JIRA Issue
    • 请找到jira请求:jira.spring.io/browse/…
    • 它在 4.3.2 版本中运行良好。我已经更新了问题中的语法以供其他人参考。
    猜你喜欢
    • 2021-08-26
    • 2014-09-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-31
    • 1970-01-01
    • 2018-12-04
    相关资源
    最近更新 更多