【问题标题】:executing requests parallelly with http-outbound-gateway与 http-outbound-gateway 并行执行请求
【发布时间】:2014-07-24 08:35:20
【问题描述】:

我需要在具有不同查询参数的特定域上执行大量 http 请求,我计划使用 spring 集成的 outbound-gateway 配置类似于下面的 sn-p:

<int-http:outbound-gateway id="httpOutboundGateway" request-channel="requestChannel"
        url="http://www.google.com" http-method="GET" reply-channel="responseChannel"
        expected-response-type="java.lang.String" charset="UTF-8" reply-timeout="5000"
        message-converters="" >
</int-http:outbound-gateway>

我想使用一些线程池并行执行请求通道中的请求。在这种情况下,我有以下问题:

  1. 将请求通道配置为 ExecutorChannel 会自动并行执行请求。
  2. 如果问题 1 的答案是肯定的,那么它是否是 http:outbound-gateway 线程安全的。
  3. 如果问题1的答案是否定的,如何配置并行执行http请求

【问题讨论】:

    标签: java spring spring-integration


    【解决方案1】:

    其实取决于上游的流量。如果您在同一线程的循环中从代码发送到requestChannel,您的所有请求都将被逐个处理。

    如果所有传入请求都来自 Web 的最终用户,则每个请求都将在该线程内完成。

    如果您的上游流是多线程的,则无需继续使用 ExecutorChannelThreadPool

    所有 Spring 集成组件都是线程安全的。我们整天都在为这些东西而战。由于 Spring Integration 用于消息传递,我们没有上下文,所有这些组件都是 stateless

    HTH

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-09
      • 1970-01-01
      相关资源
      最近更新 更多