【问题标题】:Triggering a long operation using camel rest service使用骆驼休息服务触发长时间操作
【发布时间】:2017-03-22 05:19:20
【问题描述】:

我想使用骆驼休息调用来触发长时间操作。由于该操作需要大量时间,因此请求将超时并在客户端显示错误消息。我不希望这种情况发生。

所以,我正在尝试使用队列来解决这个问题,如下所示:

<bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
   <property name="brokerURL" value="tcp://0.0.0.0:61616" />
   <property name="userName" value="admin"/>
   <property name="password" value="admin"/>
</bean>

<camelContext xmlns="http://camel.apache.org/schema/blueprint" trace="true">
    <route>
        <from uri="cxfrs:bean:rsprovider" />
        <setBody>
             <simple>${header.operationName}</simple>
        </setBody>
        <to uri="activemq:queue:myqueue"/>
        <!-- Send immediate response to client as, the processing will take a while -->
        <setBody>
            <simple>Received feeder service request to ${header.operationName}. Request will be processed soon.</simple>
        </setBody>
    </route>

    <route>
      <from uri="activemq:queue:myqueue"/>
      <convertBodyTo type="java.lang.String"/>
      <recipientList>
            <simple>direct-vm:operation-${body}</simple>
        </recipientList>
    </route>
</camelContext>

但是,添加到队列似乎是同步的,并且没有按时收到响应。我怎样才能使这个队列异步?我尝试将?jms.useAsyncSend=true 附加到队列网址。但这没有用。

【问题讨论】:

    标签: apache-camel activemq jbossfuse


    【解决方案1】:

    你应该试试asyncConsumer

     <from uri="activemq:queue:myqueue?asyncConsumer=true"/>
    

    Camel 2.9:JmsConsumer 是否处理 Exchange 异步。如果启用,那么 JmsConsumer 可能会拾取下一个 来自 JMS 队列的消息,而上一条消息正在 异步处理(由异步路由引擎)。这 意味着消息可能不是 100% 严格按顺序处理的。如果 禁用(默认),则 Exchange 在 JmsConsumer 将从 JMS 队列中提取下一条消息。注意:如果 已启用事务,然后asyncConsumer=true 不运行 异步,因为事务必须同步执行(Camel 3.0 可能支持异步事务)。

    同时检查异步请求回复 API

    http://camel.apache.org/async.html

    Future<Object> future = template.asyncRequestBody("activemq:queue:myqueue", "<YOUR_MESSAGE>");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-06-29
      • 2019-07-07
      • 1970-01-01
      • 1970-01-01
      • 2019-12-16
      • 2014-01-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多