scala - Chaining Akka Actors in a Spray Route -
i have restful api receives array of json messages converted individual avro messages , sent kafka. inside route, call 3 different actors: 1) 1 actor goes out , retrieves avro schema disk 2) loop through array of json messages , compare avro schema in second actor. if of messages don't validate, need return response caller of api , stop processing. 3) loop through array , pass 3rd actor takes json object, converts avro message , sends kafka topic.
where i'm having problem getting head wrapped around how stop processing in route if fails in 1 of actors. i'm passing in request context each actor , calling it's complete method doesn't seem stop, next actor still processes when shouldn't. here code snippet of i'm doing in route:
post { entity(as[jsobject]) { membersobj => requestcontext => val membersjson = membersobj.fields("messages").convertto[jsarray].elements val messageservice = actorreffactory.actorof(props(new messageprocessingservicev2())) val avroservice = actorreffactory.actorof(props(new avroschemaservice())) val validationservice = actorreffactory.actorof(props(new jsonmessagevalidationservice())) implicit val timeout = timeout(5 seconds) val future = avroservice ? avroschema.memberschema(requestcontext) val memberschema:schema = await.result(future, timeout.duration).asinstanceof[schema] (member <- membersjson) validationservice ! validationservice.membervalidation(member.asjsobject, memberschema, requestcontext) (member <- membersjson) (messageservice ! messageprocessingv2.processmember(member.asjsobject, topicname, memberschema, requestcontext)) i've looked through lot of blogs/books/slides around topic , not sure best approach is. i've been using scala/akka 2 months , self taught on pieces i've been needing. insight more seasoned scala/akka/spray developers have in this, it's appreciated. 1 thought had wrapper 3 actors in 'master' actor , make each child of actor , attempt approach that.
as using async processing (!) cannot control processing after messages have been sent. need use ask (?) return future can work with.
but have better idea. send message first actor second. , instead of returning result first actor, send message third 1 keep on computation.
Comments
Post a Comment