1
我有一個簡單的POC有兩個參與者:阿卡集羣 - 協會與遠程系統失敗...原因:[公會未能]
public final class Task1Actor extends AbstractLoggingActor {
public Task1Actor() {
final UnitPFBuilder<Object> builder = ReceiveBuilder.create()
.matchAny(message -> {
log().warning("Received unknown message: {}", message);
unhandled(message);
});
receive(builder.build());
}
@Override
public void preStart() throws Exception {
IntStream.range(0, 5).forEach(i -> {
final ActorRef actor = context().actorOf(Props.create(Task2Actor.class));
actor.tell(RandomStringUtils.randomAlphabetic(10), self());
});
}
}
public final class Task2Actor extends AbstractLoggingActor {
public Task2Actor() {
final UnitPFBuilder<Object> builder = ReceiveBuilder.create()
.match(String.class, this::process)
.matchAny(message -> {
log().warning("Received unknown message: {}", message);
unhandled(message);
});
receive(builder.build());
}
private void process(final String message) {
log().debug("Processing message: {}", message);
// Do something useful here in the (not-so far) future
}
}
這是主類:
final class ClusterSample {
public static void main(final String... args) throws Exception {
ClusterSample.start(2251);
ClusterSample.start(2252);
ClusterSample.start(0);
}
private static void start(final int port) {
final Config config = ConfigFactory.parseString(String.format("akka.remote.netty.tcp.port = %s", port))
//.withFallback(ConfigFactory.parseString(String.format("akka.cluster.roles = [%s]", role)))
.withFallback(ConfigFactory.load("cluster"));
ActorSystem system = ActorSystem.create("ClusterSystem", config);
system.actorOf(Props.create(Task1Actor.class));
}
}
......這些都是我的配置文件(application.conf
和cluster.conf
分別):
akka {
actor {
default-dispatcher { throughput = 5 }
provider = cluster
}
cluster {
seed-nodes = [ "akka.tcp://[email protected]:2551", "akka.tcp://[email protected]:2552" ]
# roles = ["role"]
}
remote {
log-remote-lifecycle-events = off
netty.tcp {
hostname = 127.0.0.1
port = 0
}
}
loggers = [ "akka.event.slf4j.Slf4jLogger" ]
logging-filter = "akka.event.slf4j.Slf4jLoggingFilter"
loglevel = DEBUG
}
include "application"
akka.cluster.min-nr-of-members = 2
akka.cluster.role {
watson.min-nr-of-members = 2
}
akka.actor.deployment {
}
我想在這裏實現的是「形成產業集羣」,從已經建立的流程。所以我曾經有過這些演員(真的可以是任何流程),現在我試圖讓他們在(或作爲)羣集中工作。我剛開始閱讀,所以我對此不太瞭解。
我得到的錯誤是:
03-09-2017 16:52:43.749 |- DEBUG in Task2Actor:88 [ClusterSystem-akka.actor.default-dispatcher-20] - Processing message: GCGboeqRKJ
03-09-2017 16:52:43.749 |- DEBUG in Task2Actor:88 [ClusterSystem-akka.actor.default-dispatcher-21] - Processing message: ykhePhziFT
03-09-2017 16:52:43.749 |- DEBUG in Task2Actor:88 [ClusterSystem-akka.actor.default-dispatcher-2] - Processing message: SFvnRAlGgg
03-09-2017 16:52:43.753 |- DEBUG in Task2Actor:88 [ClusterSystem-akka.actor.default-dispatcher-21] - Processing message: bMgBtCzWCI
03-09-2017 16:52:43.753 |- DEBUG in Task2Actor:88 [ClusterSystem-akka.actor.default-dispatcher-20] - Processing message: ifoOOmqbbv
03-09-2017 16:52:43.753 |- DEBUG in Task2Actor:88 [ClusterSystem-akka.actor.default-dispatcher-2] - Processing message: ZekwWXmmSQ
03-09-2017 16:52:43.754 |- DEBUG in Task2Actor:88 [ClusterSystem-akka.actor.default-dispatcher-21] - Processing message: MqXGoSQSzU
03-09-2017 16:52:43.754 |- DEBUG in Task2Actor:88 [ClusterSystem-akka.actor.default-dispatcher-20] - Processing message: NrdVYAFgrR
03-09-2017 16:52:43.754 |- DEBUG in Task2Actor:88 [ClusterSystem-akka.actor.default-dispatcher-2] - Processing message: GsjyIsxetC
03-09-2017 16:52:43.754 |- DEBUG in Task2Actor:88 [ClusterSystem-akka.actor.default-dispatcher-21] - Processing message: LpVNmbriXO
03-09-2017 16:52:43.754 |- DEBUG in Task2Actor:88 [ClusterSystem-akka.actor.default-dispatcher-20] - Processing message: HCFzOjJwnO
03-09-2017 16:52:43.755 |- DEBUG in Task2Actor:88 [ClusterSystem-akka.actor.default-dispatcher-2] - Processing message: iqflQMSeJF
03-09-2017 16:52:43.755 |- DEBUG in Task2Actor:88 [ClusterSystem-akka.actor.default-dispatcher-21] - Processing message: HlyMdMJfUs
03-09-2017 16:52:43.755 |- DEBUG in Task2Actor:88 [ClusterSystem-akka.actor.default-dispatcher-20] - Processing message: jlwxzLmRsF
03-09-2017 16:52:43.755 |- DEBUG in Task2Actor:88 [ClusterSystem-akka.actor.default-dispatcher-2] - Processing message: XPSmMYekCs
03-09-2017 16:52:43.794 |- WARN in ReliableDeliverySupervisor:78 [ClusterSystem-akka.actor.default-dispatcher-20] - Association with remote system [akka.tcp://[email protected]:2552] has failed, address is now gated for [5000] ms. Reason: [Association failed with [akka.tcp://[email protected]:2552]] Caused by: [Connection refused: /127.0.0.1:2552]
03-09-2017 16:52:43.794 |- WARN in ReliableDeliverySupervisor:78 [ClusterSystem-akka.actor.default-dispatcher-21] - Association with remote system [akka.tcp://[email protected]:2552] has failed, address is now gated for [5000] ms. Reason: [Association failed with [akka.tcp://[email protected]:2552]] Caused by: [Connection refused: /127.0.0.1:2552]
03-09-2017 16:52:43.794 |- WARN in ReliableDeliverySupervisor:78 [ClusterSystem-akka.actor.default-dispatcher-20] - Association with remote system [akka.tcp://[email protected]:2551] has failed, address is now gated for [5000] ms. Reason: [Association failed with [akka.tcp://[email protected]:2551]] Caused by: [Connection refused: /127.0.0.1:2551]
03-09-2017 16:52:43.794 |- WARN in ReliableDeliverySupervisor:78 [ClusterSystem-akka.actor.default-dispatcher-2] - Association with remote system [akka.tcp://[email protected]:2551] has failed, address is now gated for [5000] ms. Reason: [Association failed with [akka.tcp://[email protected]:2551]] Caused by: [Connection refused: /127.0.0.1:2551]
03-09-2017 16:52:43.795 |- WARN in ReliableDeliverySupervisor:78 [ClusterSystem-akka.actor.default-dispatcher-21] - Association with remote system [akka.tcp://[email protected]:2551] has failed, address is now gated for [5000] ms. Reason: [Association failed with [akka.tcp://[email protected]:2551]] Caused by: [Connection refused: /127.0.0.1:2551]
03-09-2017 16:52:43.796 |- WARN in ReliableDeliverySupervisor:78 [ClusterSystem-akka.actor.default-dispatcher-2] - Association with remote system [akka.tcp://[email protected]:2552] has failed, address is now gated for [5000] ms. Reason: [Association failed with [akka.tcp://[email protected]:2552]] Caused by: [Connection refused: /127.0.0.1:2552]
我在同一臺機器上執行此而已使用這些端口...保證。我在我的Gradle配置中擁有所有的依賴關係,但仍然無法使其工作。
防火牆阻止訪問也許? 「連接被拒絕」的錯誤來自底層的Java IO API:並且不是Akka特有的,但正如它所說的那樣,它試圖建立TCP連接,但是被另一端拒絕。配置和啓動邏輯看起來是正確的。 – johanandren
你在unix上嗎? 127.0.0.1和localhost有時並不一樣。我不記得細節,但我記得不得不從一個更改到另一個,使它在unix上工作 –
嗯,原來的端口號是相似的,但不一樣;只是一個錯字。如果我在Akka配置文件和'ClusterSample.java'中使用相同的端口號,我不會收到錯誤,但是如果我打印演員的路徑,它不是'akka.tcp://。 。 。'但是'akka://。 。 。,所以我假設整個集羣都不起作用。 –