Quantcast
Channel: Akka Libraries - Discussion Forum for Akka technologies
Viewing all articles
Browse latest Browse all 1362

Asynchronous command validation on EventSourceBehavior

$
0
0

@brabo-hi wrote:

On akka persistence, when receiving a command, how can we execute asynchronous function to validate the command before deciding to reject the command of to persist an event?

EventSourcedBehavior accepts:

commandHandler: (State, Command) => ReplyEffect[Event, State]

I would like to do something like:

val validateCommand(command: Command): Future[Boolean]

commandHandler: (State, Command) => 
validateCommand(command).map(boolean => 
   if(boolean)
     Effect.reply(replyTo)(Rejected("reason"))
   else
     Effect.persist(MyEvent()).thenReply(reply)(_ => Accepted)
)

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 1362

Trending Articles