Apache Camel 拦截 - 捕获输出. [英] Apache Camel Intercept - Capture Output.

查看:17
本文介绍了Apache Camel 拦截 - 捕获输出.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 spring.xml 文件中使用 Apache Camel Interceptor 来捕获传入请求和传出响应,如下所示:

I am attempting to use Apache Camel Interceptor in the spring.xml file to capture incoming requests and outgoing responses, like this:

    <bean id="InterceptProcessor" class="CaptureProcessor"/>
<camel:camelContext id="camel">
    <camel:jmxAgent id="agent" disabled="true" />
    <camel:intercept>
        <camel:process ref="InterceptProcessor"></camel:process>
    </camel:intercept>
    <camel:route id="Resource.rConnect.rconnect" autoStartup="false">
        <camel:from
            uri="cxfjetty:${Resource.rConnect.rconnect.baseUrl}?urlTemplateRef=#URLTemplateRef.Resource.rConnect.rconnect&amp;
            convertAttachments=true" />
        <camel:to
            uri="sonicesb://Process/rConnect?bindingStrategy=#ExposeBindingStrategy.Resource.rConnect.rconnect&amp;headerFilterStrategy=#ExposeHeaderFilterStrategy.Resource.rConnect.rconnect&amp;esbConfig=#ExposeEsbConfig.Resource.rConnect.rconnect" />
    </camel:route>
    <camel:route autoStartup="false">
        <camel:from
            uri="directsonicesb:Resource.rConnect.rconnect?bindingStrategy=#InvokeBindingStrategy.Resource.rConnect.rconnect&amp;headerFilterStrategy=#InvokeHeaderFilterStrategy.Resource.rConnect.rconnect&amp;uriTemplate=#URITemplate.Resource.rConnect.rconnect" />
        <camel:to uri="sonicesb://Process/rConnect" />
    </camel:route>
</camel:camelContext>

关注这篇文章.

但是CaptureProcessor"只在输入周期被调用一次.

But the "CaptureProcessor" is only called once on the input cycle.

如何让它也捕获输出?

推荐答案

根据Camel doc,这对于 intercept 是不可能的:

According to the Camel doc, this is not possible with intercept:

发生的情况是Exchange在每个处理步骤之前被拦截,这意味着它会在之前被拦截

What happens is that the Exchange is intercepted before each processing step, that means that it will be intercepted before

因此,不可能在每个步骤之后拦截处理.但是,有一个针对此要求的开放式 Jira 票证:CAMEL-6901

Thus, it is not possible to intercept the processing after each step. However, there's an open Jira ticket for this requirement: CAMEL-6901

或者,您可以使用 onCompletion,它类似于一个完成后的回调,可以为每条路由定义或为整个 Camel 上下文全局定义:

Alternatively, you may use onCompletion that is like an after completion callback which can be defined for each route or globally for the whole Camel context:

<onCompletion>
    <log message="${body}" />
</onCompletion>

有关这种可能性的更多信息,请参阅 Camel 文档.

See the Camel docs for more information about this possibility.

这篇关于Apache Camel 拦截 - 捕获输出.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆