Change state after external api call

Hello,
I have the following scenario:

  1. In service impl, i receive a request
  2. I perform some validation using the state
  3. If validation succeeds, i need to make an external call (not in lagom microservice)
    ( this will be made in impl afaik, as asynchronous web service calls from persistent entity are not allowed…)
  4. if that external call is successful, i need to change the state.

I am not able to figure out how the command handler will wait for the external call to complete successfully and emit the event to change state.
Am i missing something?

I assume you can’t process any other command when waiting for the validation and completing the first command? Then I suggest that you use stashing with Akka EventSourcedBehavior. Lagom - Domain Modelling with Akka Persistence Typed

1 Like

Regardless of if incoming commands need to wait (be stashed) or not, the pattern to use for the external request is “Send Future result to self”. See the docs here: Interaction Patterns • Akka Documentation. In essence, the actor makes an external call and the result is sent back to the actor as message (think command) “some time later”.

2 Likes