Akka Cluster through an exception "java.net.ConnectException: Connection refused"

256 views Asked by At

I am working with akka cluster but getting a Connection refused error. Here are my files

application.conf file.

akka {
  actor {
    provider = "cluster"
  }
  remote.artery {
    canonical {
      hostname = "127.0.0.1"
      port = 0
    }
  }

  cluster {
    seed-nodes = [
      "akka://[email protected]:2551",
      "akka://[email protected]:2552"]
    auto-down-unreachable-after = 10s
  }
}

ClusterListner (actor class).

class ClusterListener extends Actor{

  val cluster: Cluster = Cluster(context.system)

  override def preStart(): Unit = {
//    subscribe
    cluster.subscribe(self, initialStateMode = InitialStateAsEvents, classOf[MemberEvent], classOf[UnreachableMember])
  }

  override def postStop(): Unit = {
//    unsubscribe
    cluster.unsubscribe(self)
  }
  override def receive: Receive = {
    case MemberUp(member) =>
      log.info("Member is Up: {}", member.address)

    case UnreachableMember(member) =>
      log.info("Member detected as unreachable: {}", member)

    case MemberRemoved(member, previousStatus) =>
      log.info("Member is Removed: {} after {}", member.address, previousStatus)

    case _: MemberEvent =>
      log.info("Something else")
  }
}

Main Class

object MainClass extends App {
  implicit val system: ActorSystem = ActorSystem("ClusterSystem")

  val actor = system.actorOf(Props(new ClusterListener),"clusterActor")
    Cluster(system).registerOnMemberUp(actor)
}

Error:

[INFO] [04/06/2023 13:11:25.781] [main] [ArteryTcpTransport(akka://ClusterSystem)] Remoting started with transport [Artery tcp]; listening on address [akka://[email protected]:35911] with UID [-7093993311719804604]
[INFO] [04/06/2023 13:11:25.831] [main] [Cluster(akka://ClusterSystem)] Cluster Node [akka://[email protected]:35911] - Starting up, Akka version [2.6.0] ...
[INFO] [04/06/2023 13:11:26.217] [main] [Cluster(akka://ClusterSystem)] Cluster Node [akka://[email protected]:35911] - Registered cluster JMX MBean [akka:type=Cluster]
[INFO] [04/06/2023 13:11:26.217] [main] [Cluster(akka://ClusterSystem)] Cluster Node [akka://[email protected]:35911] - Started up successfully
[INFO] [04/06/2023 13:11:26.287] [ClusterSystem-akka.actor.internal-dispatcher-5] [Cluster(akka://ClusterSystem)] Cluster Node [akka://[email protected]:35911] - No downing-provider-class configured, manual cluster downing required, see https://doc.akka.io/docs/akka/current/typed/cluster.html#downing
[WARN] [04/06/2023 13:11:26.706] [ClusterSystem-akka.remote.default-remote-dispatcher-11] [akka.stream.Log(akka://ClusterSystem/system/Materializers/StreamSupervisor-1)] [outbound connection to [akka://[email protected]:2552], message stream] Upstream failed, cause: StreamTcpException: Tcp command [Connect(127.0.0.1:2552,None,List(),Some(5000 milliseconds),true)] failed because of java.net.ConnectException: Connection refused
[WARN] [04/06/2023 13:11:26.710] [ClusterSystem-akka.remote.default-remote-dispatcher-7] [akka.stream.Log(akka://ClusterSystem/system/Materializers/StreamSupervisor-1)] [outbound connection to [akka://[email protected]:2552], control stream] Upstream failed, cause: StreamTcpException: Tcp command [Connect(127.0.0.1:2552,None,List(),Some(5000 milliseconds),true)] failed because of java.net.ConnectException: Connection refused
[WARN] [04/06/2023 13:11:26.719] [ClusterSystem-akka.remote.default-remote-dispatcher-7] [akka.stream.Log(akka://ClusterSystem/system/Materializers/StreamSupervisor-1)] [outbound connection to [akka://[email protected]:2551], message stream] Upstream failed, cause: StreamTcpException: Tcp command [Connect(127.0.0.1:2551,None,List(),Some(5000 milliseconds),true)] failed because of java.net.ConnectException: Connection refused
[WARN] [04/06/2023 13:11:26.719] [ClusterSystem-akka.remote.default-remote-dispatcher-11] [akka.stream.Log(akka://ClusterSystem/system/Materializers/StreamSupervisor-1)] [outbound connection to [akka://[email protected]:2551], control stream] Upstream failed, cause: StreamTcpException: Tcp command [Connect(127.0.0.1:2551,None,List(),Some(5000 milliseconds),true)] failed because of java.net.ConnectException: Connection refused

And the error repeating continuously I'm new to akka cluster , kindly guide me where I'm doing mistake.

0

There are 0 answers