Home > Software engineering >  Akka spawn actor issue
Akka spawn actor issue

Time:02-05

I'm trying to realise the "actors fabric". An application include fabric-actor, which must spawn child actors on demand.

I tried to realise this as follows:

 object BranchCreator {
     final case class CreateBranche(name: String)
            
     def apply(): Behavior[CreateBranche] = {
                Behaviors.receiveMessage { (context, message) =>
                 context.spawn(new Branch(), message.name)
               }
           }
    }

But method spawn is not available for context. Only "name" and "copy" are available for context.

CodePudding user response:

Use Behaviors.receive instead of Behaviors.receiveMessage

As per documentation of Behaviors.receiveMessage:

Simplified version of Behaviors.Receive with only a single argument - the message to be handled. Useful for when the context is already accessible by other means, like being wrapped in an setup or similar. [cut]

  •  Tags:  
  • Related