Alex K
Alex K

Reputation: 844

How to compose routes in actor's receive with runRoute?

I need to add a few custom system messages processing to spray.routing.HttpService. I need to chain receive methods as follows:

def receive = {
 case ...my messages here
 case _ => ...call httpReceive below
}

def httpReceive = runRoute...

How to organize this?

Upvotes: 1

Views: 740

Answers (1)

4lex1v
4lex1v

Reputation: 21547

in Spray runRoute converts your route structure into Akka's Receive, which is a type alias for PartialFunction[Any, Unit]. So if you have some method which handles your own messages and some route you can just compose them with orElse:

def httpReceive: Receive = runRoute(...)
def handle: Receive = ...

def receive = handle orElse httpReceive

Now if your messages will be handled with handle method and then, if it was a request, spray will handle this request

Upvotes: 3

Related Questions