I would like to distribute the request context implicitly in the system of collaborating entities.
To simplify and present the situation, my system has several participants, and messages sent to these entities should include this RequestContext object.
ActorA receives messages of type MessageA ActorB receives messages of type MessageB
when ActorA needs to send a message to ActorB as part of MessageA processing, it executes the business logic and then creates a MessageB from the results of the logic as well as RequestContext available in MessageA and then sends them to ActorB
def handle(ma:MessageA) {
val intermediateResult = businessLogic(ma)
actorB ! MessageB(intermediateResult, ma.requestContext)
}
We have a lot of messages that need to be processed, and explicitly walking around requestContext is cumbersome.
I am trying to use creative ways to use the Scala implicits function to avoid explicitly embedding the RequestContext object embedded in the incoming message into the outgoing message.
Messages are case classes (and they should be). I read about implicits rules, but casting an attribute of an object to the current implicit scope seems far-fetched.
This, I am sure, should be a general requirement. Any suggestions?
Thank.
source
share