Not able to execute Akka Work pulling java example provided in the akka document

65 views Asked by At

I am interested in understanding the work pull feature in akka. I am trying to create a main method for the example provided that will create and start the producer(ImageWorkManager class in the example) and consumer(ImageConverter class in the example). It will be helpful if someone provides a sample main method for executing the sample example.

2

There are 2 answers

0
Nandu On BEST ANSWER

I had figured it out. Below is the main class to create a producer actor in the given work pull example.

public class WorkPullCreateProducer {
public static void main(String[] args) {    
    final ActorSystem<Command> system = ActorSystem.create(ImageWorkManager.create(), "ClusterSystem");
    final ActorRef<Command> ref = system;   
    Convert img = new Convert("gif", "jpeg", "imagename");
    ref.tell(img);
}}

and below is the main class to create a consumer actor.

public class WorkPullCreateConsumer {
public static Behavior<Void> create() {
    return Behaviors.setup(context -> {
        int workersPerNode = context.getSystem().settings().config().getInt("transformation.workers-per-node");
        for (int i = 0; i < workersPerNode; i++) {
            context.spawn(ImageConverter.create(), "Workernode" + i);
        }
        return Behaviors.empty();
    });
}

public static void main(String[] args) {
    ActorSystem.create(AppWorkPullConsumerStack.create(), "ClusterSystem");
}}
0
David Ogren On

There is a complete sample under Akka Samples. As I said in the comments, I think you are going to have to be more specific with any issues you are having if you are running into problems.