0

我有一项服务可以从许多客户端获取请求,并在经过一些处理后向客户端发送响应。我使用 ThreadPoolExecutor (threadExecuterClient) 来处理客户端请求并将它们放在 BlockingQueue (requestQueue) 中。许多客户端可以发送并发请求。我有另一个 ThreadPoolExecutor (threadExecuterServer) 处理 requestQueue 中的请求。此处理基本上包括将该请求发送到服务器并获得响应。处理后,我需要将该响应发送给发出该请求的客户端。我很难跟踪哪个客户提出了哪个请求。我基本上需要找到一种将客户端请求映射到处理结果的方法。该服务就像一个网关。

任何处理此问题的想法表示赞赏。

谢谢

4

1 回答 1

0

I assume your service accepts requests via HTTP ? Accept the request from your service and send back a HTTP 202 response. This response means that the request was accepted for processing. When you send the response, send the Location header to tell the client which URL to invoke to ascertain the status of your request. The client can poll this URL for status and a result.

The URL should contain a unique ID for each request. Your server can track that and populate a response when it is ready.

于 2013-03-05T17:59:31.503 回答