2014-12-02 23 views
0

我有一個帶有Web服務的Spring應用程序Endpoint,它在收到呼叫時將請求有效載荷傳遞給彈性集成MessagingGateway進行EIP處理。Tomcat上的Spring Web服務端點 - 併發調用配置

我的應用程序部署在Tomcat 7容器上,並使用Spring 4 API構建。

我試圖運行一個性能測試,我對Web服務進行多個併發調用。當我執行這個測試時,每個請求都會被正確處理,並且每個請求都會成功接收響應,但Spring應用程序似乎只處理兩個請求。即一旦第二請求的響應被髮送回客戶端,第三請求就僅由應用程序處理。 (在調試時,我可以看到只有兩個線程處理請求)

我想知道我的Spring應用程序的執行線程配置應該在哪裏完成,以支持同時處理多個Web服務客戶端請求(例如10 +併發線程)。這應該在Tomcat容器的配置中完成嗎? Web Service配置中的某處? Spring Integration的Messaging網關配置? Spring Integration的請求集成流程配置?一些這些配置的組合?或者完全在其他地方?

我的堆棧是:

Tomcat 7.0.55 
Spring/Integration 4 APIs 
Spring Java DSL 1 API 

對於我的測試,我使用了SoapUI 4.5.0,我用下面的配置進行負載測試:

Threads: 10, Strategy: Thread, Start Threads: 10, End Threads: 10, Limit 1 Runs per thread.

我假設此配置對於測試10個併發呼叫到Web服務URL是否正確...

* UPDATED TO INC路得當前配置*

端點配置:

@Endpoint 
@EnableIntegration 
@IntegrationComponentScan(basePackages = "com.company.test.gateway") 
@ComponentScan(basePackages = "com.company.test.gateway") 
public class TestServiceEndpoint { 

    private static final String NAMESPACE_URI = "http://www.company.com/test"; 

    private static final Logger logger = LogManager.getLogger(); 

    @Autowired 
    private TestGateway gateway; 

    @PayloadRoot(namespace = NAMESPACE_URI, localPart = "test") 
    @ResponsePayload 
    public TestResponse process(
      @RequestPayload TestRequest request) throws Exception { 

     TestResponse response = gateway.process(request); 

     return response; 
    } 
} 

網關配置:

@MessagingGateway 
@EnableIntegration 
@IntegrationComponentScan 
@ComponentScan 
public interface TestGateway { 

    @Gateway(requestChannel = "test.request.ch", replyChannel = "test.response.ch") 
    TestResponse process(TestRequest request); 
} 

整合配置:

@Configuration 
public class IntegrationConfig { 

    @Bean(name = "test.request.ch") 
    public DirectChannel testRequestCh() { 
     return new DirectChannel(); 
    } 

    @Bean(name = "test.response.ch") 
    public DirectChannel testResponseCh() { 
     return new DirectChannel(); 
    } 

    @Bean 
    public Executor taskExecutor() { 
     ThreadPoolExecutor executor = (ThreadPoolExecutor) Executors 
       .newFixedThreadPool(10); 
     return executor; 
    } 

    @Bean 
    public IntegrationFlow requestFlow() { 

     return IntegrationFlows 
       .from("test.request.ch") 
       .enrichHeaders(
         m -> { 
          m.header(MessageHeaders.ERROR_CHANNEL, 
            "test.error.ch", true); 
         }) 
       .handle("testSplitter", "split") 
       .channel(MessageChannels.executor("requestSplitterFlowExecutor", 
         this.taskExecutor())) 
       .route("testRouter", "route") 
         .get(); 
    } 

    ... 
} 

乾杯, PM

+0

您需要顯示您的集成配置。如果你在整個使用'DirectChannel's,整合流程將運行在tomcat http線程上,它不應該被限制爲2. – 2014-12-02 17:17:40

+0

嗨加里,與網關直接相關的通道是'DirectChannel's。然而,隨着流程的進一步發展,取決於消息如何路由,情況會變得更復雜一些。在我正在運行的性能測試中,'testRouter'會將有效負載路由到'PublishSubscribeChannel',其中負載放置在MQ隊列中。這是一個pub-sub頻道的原因是,一旦我們知道有效載荷已成功放入隊列中,我們就會做其他工作。此後,響應最終通過「JMS入站適配器」到達併發送到'test.response.ch'回到網關。 – 2014-12-02 18:05:38

+0

那麼框架中沒有什麼東西可以限制你的線程。我建議你打開DEBUG日誌並按照消息流;請確保包含線程名稱(如果使用log4j,則使用'%t'),這樣您就可以看到發生了什麼。 – 2014-12-02 18:20:37

回答

1

應用程序當時只處理兩條消息(有時甚至只有一條消息!)的原因並不是因爲Spring配置或Tomcat配置中存在問題,而是因爲測試工具SoapUI 4.5中的一個錯誤0.0。見limited threads in soapUI free version

更新SoapUI並重新運行後,現在可以看到消息一次由多個線程處理。