あなたの質問は非常に自由形式なので、私はあなたの要件についていくつかの仮定をします。
リクエストの想定:あるイベントで多くのリクエストが生成されます。
async-http-client(https://github.com/sonatype/async-http-client)をラップするアクターを持つルーターを作成します。async-http-clientがリクエストを完了すると、ReqAckに含まれているIDを持つメッセージがコーディネーションアクターに送信されます。コーディネーションアクターはIDを集約します。
以下は主に擬似コードですが、実際のAPIに十分近いため、不足している部分を特定できるはずです。
case class Request(url:String)
case class IDReceived(id:String)
case class RequestingActor extends Actor {
override def receive = {
case Request(url) => {
//set up the async client and run the request
//since it's async the client will not block and this actor can continue making generating more requests
}
}
}
class AsyncHttpClientResponseHandler(aggregationActor:ActorRef) extends SomeAsyncClientHandler {
//Override the necessary Handler methods.
override def onComplete = {
aggregationActor ! IDReceived(//get the id from the response)
}
}
class SomeEventHandlerClass {
val requestRouter = actorSystem.actorOf(Props[RequestingActor].withRouter(FromConfig(//maybe you've configured a round-robin router)), requestRouterName)
def onEvent(url:String) {
requestRouter ! Request(url)
}
}
case class AggregationActor extends Actor {
val idStorage = //some form of storage, maybe a Map if other information about the task ID needs to be stored as well. Map(id -> other information)
override def receive = {
case IDReceived(id) => //add the ID to idStorage
}
}
応答の前提:応答に含まれるデータを使用して何かを実行してから、IDを完了としてマークする必要があります。HTTPフロントエンドは、この1セットのメッセージのみを処理する必要があります。
Akka統合を備えたフレームワークを見つける代わりに、作成したAkkaネットワークにメッセージを送信する単純なHTTPフロントエンドを使用するだけです。play-miniを使用することで得られる利点は想像できません。また、作業の分離と制御を示す線の一部がわかりにくくなると思います。それは常に当てはまるわけではありませんが、あなたの質問に要件がないことを考えると、私は自分の意見の根拠となるものは他にありません。
case class ResponseHandlingActor extends Actor {
val aggregationActor = actorSystem.actorFor(//the name of the aggregation router within the Actor System)
override def receive = {
case Response(data) => {
//do something with the data. If the data manipulation is blocking or long running it may warrant its own network of actors.
aggregationActor ! ResponseReceived(//get the id from the response)
}
}
}
class ScalatraFrontEnd() extends ScalatraServlet {
val responseRouter = actorSystem.actorOf(Props[RequestingActor].withRouter(FromConfig(//maybe you've configured a round-robin router)), requestRouterName)
post("/response") {
responseRouter ! Response(//data from the response)
}
}
これに似たシステムを作成すると、関心の分離がうまくいき、処理が行われる場所を簡単に推測でき、システムを拡張したり拡張したりするための十分なスペースが得られます。