【问题标题】:Camel restlet terminate after POST rather than return bodyCamel restlet 在 POST 后终止而不是返回正文
【发布时间】:2015-09-19 09:32:08
【问题描述】:

我正在使用蓝图开发一个骆驼restlet项目以部署在Fuse上。这是一个非常简单的带有简单文本正文的 HTTP POST。我将交换模式设置为Inonly

但是,我预计连接会在实际发布后终止,但我收到了 200 OK,正文中填充了最终处理中的最终正文。

这就是它的工作方式吗?因此我需要手动清理尸体吗?

另外,如果处理是一个长时间运行的进程,会发生什么?我希望在数据发布后直接终止,而不是等到上下文内的完整处理。

我的蓝图是这样的:

 <camelContext xmlns="http://camel.apache.org/schema/blueprint">
  <route id="timerToLog">
    <from uri="restlet:http://localhost:7070/arena?restletMethod=POST&amp;exchangePattern=inOnly"/>
    <process ref="marcformatreader"/>
    <log message="${body}" loggingLevel="INFO"/>
    <process ref="marcformatwriter"/>
    <log message="${body}" loggingLevel="INFO"/>
    <to pattern="InOnly" uri="file:C:/Camel/output?fileName=output.mrc"/>
  </route>
</camelContext>

【问题讨论】:

    标签: java apache-camel restlet jbossfuse blueprint


    【解决方案1】:

    一种解决方案是使用WireTap pattern 并像这样立即返回响应(注意!我没有执行该代码,所以请注意可能的拼写错误)。

    <camelContext xmlns="http://camel.apache.org/schema/blueprint">
        <route id="timerToLog">
            <from uri="restlet:http://localhost:7070/arena?restletMethod=POST&amp;exchangePattern=inOnly"/>
            <wireTap uri="direct:tap" copy="true"></wireTap>
            <transform>
                <constant>OK</constant>
            </transform>
        </route>
    
        <route id="wireTapToLog">
            <from uri="direct:tap"/>
            <process ref="marcformatreader"/>
            <log message="${body}" loggingLevel="INFO"/>
            <process ref="marcformatwriter"/>
            <log message="${body}" loggingLevel="INFO"/>
            <to pattern="InOnly" uri="file:C:/Camel/output?fileName=output.mrc"/>
        </route>
    
    </camelContext>
    

    使用 WireTap,Camel 将继续在另一个线程中处理交换,因此 POST 方法将立即返回文本“OK”。

    【讨论】:

    • 啊哈,听起来很有趣,我会试一试并测试它并返回结果。希望将来您可以设置简单的参数来启用此功能。
    • 您的代码几乎是正确的。我还必须添加属性 copy="true" 。我会编辑你的帖子来澄清一下。
    • 唯一奇怪的是,您实际上并没有看到这反映了带有节点的图形布局。您在 xml 文件中看到它,但节点没有反映,我猜这是因为您不能在单个路由文件中有多个源。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多