scala - Spray.io - delegate processing to another actor(s) -


I apply a REST service using spray.io frameworks. Such a service should receive some "search" queries, take action on them and return results to the customer. Code which has been discovered in different actor - search, after receiving the query from the user (JSON), I send this query again from my search engine (using the Ask Pattern) but I do not really understand that This is how I should apply the conversation between the spray.io route actor and my SearchActor.

I look at many variations here, but which one is more correct and why?

  1. Create an example of a search operator at startup and send every request to this actor <
  2. Create the pool of the search actor actor at the startup and send the request to this pool
    class = "post-text" itemprop = "text">

    You have not been forced to use the pattern to ask In fact, This will create a thread for each of your requests and probably is not what you want . I recommend that you use a tell instead you do this by spreading a new actor for each request ( less expensive than the thread ), which has RequestContext in one of its constructor fields. You will use this reference to return the feedback, usually with its complete method.

    Example code.

      class RESTActor HttpService {val path = path ("Mypath") ~ Post {unit (like [SearchActor.Search]) {search = & gt; CTX = & gt; SearchX (CTX)! Search}}} case class SearchActor (ctx: RequestContext) {def receive = {case msg: search = & gt; // ... case message of search process: result = & gt; Ctx.complete (msg) // sends an answer back}}    

    Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -