簡體   English   中英

如何在IntelliJ IDEA中運行akka actor

[英]How to run akka actors in IntelliJ IDEA

來自Akka的網站文檔:

然后,這個主要方法將創建運行actor所需的基礎結構,啟動給定的主actor,並在主actor終止后安排整個應用程序關閉。 因此,您將能夠使用類似於以下的命令運行上述代碼:

java -classpath akka.Main example.two.HelloWorld

那么,我如何從IntelliJ IDEA啟動它呢? 我還沒有找到合適的窗口。

對AKKA的依賴已經在項目中:

 <dependencies>
        <dependency>
            <groupId>com.typesafe.akka</groupId>
            <artifactId>akka-actor_2.10</artifactId>
            <version>2.2-M3</version>
        </dependency>
    </dependencies>

代碼本身(你可以看到沒有main(...) ):

public class HelloWorld extends UntypedActor {

    @Override
    public void preStart() {
        // create the greeter actor
        final ActorRef greeter =
                getContext().actorOf(Props.create(Greeter.class), "greeter");
        // tell it to perform the greeting
        greeter.tell(Greeter.Msg.GREET, getSelf());
    }

    @Override
    public void onReceive(Object msg) {
        if (msg == Greeter.Msg.DONE) {
            // when the greeter is done, stop this actor and with it the application
            getContext().stop(getSelf());
        } else unhandled(msg);
    }
}

看起來文檔和二進制發行版不同步。

正如您在Github上看到的Main.scala僅在16天前添加。

要解決此問題,您可以將依賴項版本更改為SNAPSHOT 將快照存儲庫添加到pom並將版本更改為2.2-SNAPSHOT

<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.stackoverflow</groupId>
    <artifactId>akka-app</artifactId>
    <version>1.0-SNAPSHOT</version>

    <name>${project.artifactId}-${project.version}</name>

    <repositories>
        <repository>
            <id>akka-snapshots</id>
            <name>Akka Snapshots</name>
            <url>http://repo.akka.io/snapshots/</url>
            <layout>default</layout>
        </repository>
    </repositories>

    <dependencies>
        <dependency>
            <groupId>com.typesafe.akka</groupId>
            <artifactId>akka-actor_2.10</artifactId>
            <version>2.2-SNAPSHOT</version>
        </dependency>

    </dependencies>

</project>

現在akka.Main將可用。 要啟動應用程序,您必須指向正確的主類並添加自己的actor類作為參數。

首先選擇創建一個新的運行配置:

在此輸入圖像描述

然后添加一個新應用程序:

在此輸入圖像描述

給應用程序命名(Actor或者其他)並將主類填充為akka.Main並將HelloWorld類添加為Program Arguments (記住要包含完整的包):

在此輸入圖像描述

現在您已准備好運行程序,只需按工具欄中的播放按鈕:

在此輸入圖像描述

瞧!

//You can use the following code to start your actor:

public class Main {

  public static void main(String[] args) {
      akka.Main.main(new String[] { HelloWorld.class.getName() });
  }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM