I’m consuming messages from external Kafka like this and feeding those messages to one of the actors let’s suppose MyActor
This actor is having a constructor dependency of one another microservice let’s say ServiceApiToBeCallFromAnActor
Now before this actor start processing any message I wanted to invoke one of the rest endpoints from ServiceApiToBeCallFromAnActor so I override actors preStart
life cycle event.
Now when I tried to invoke rest endpoint inside preStart
, sometime it works and sometimes it doesn’t work and gives following warning
[warn] com.lightbend.lagom.internal.scaladsl.registry.ServiceRegistryServiceLocator - Service name=[service-to-be-call-from-actor-api] was not found. Hint: Maybe it was not registered?
Some of the source code is like
//Inside application loader, dependecies are as follows
lazy val serviceApiToBeCallFromAnActor = serviceClient.implement[ServiceApiToBeCallFromAnActor]
lazy val myActor: MyActor = wire[MyActor]
lazy val myActorRef = actorSystem.actorOf(Props(myActor), name = "MyActor)
wire[Engine]
//Engine consuming messages is as follows
class Engine (myActor: ActorRef) (implicit executionContext: ExecutionContext) {
engineService
.messages()
.subscribe
.atLeastOnce(Flow.fromFunction(message => {
myActor ! message
Done
}))
}
//MyActor
class MyActor(serviceApiToBeCallFromAnActor: ServiceApiToBeCallFromAnActor)
(implicit executionContext: ExecutionContext) extends Actor with ActorLogging {
override def preStart() = {
serviceToBeCallFromActor
.requestSomething
.invoke()
.map(res => SetResponse(res)) pipeTo self //This is the line
override def receive: Receive = {
case someOtherCases => {}
case SetResponse(res) => {
println("This statement is not get printed always....") //And this one
}
}
}
I read this article and thanks @ignasi35 for your explanation I think in my case service isn’t registered yet and before that, i am trying to make an API call.
But guys what should I do where should I make that API call? Is there any callback event for service registration so that on which I can raise an API call.
@TimMoore, @octonato, @ignasi35 Please help me.
Regards,
Dheeraj