Hello,

To what cluster event should a member subscribe to be notified when it 
loses the connection to the cluster leader?

Suppose I am in an edge case with only 2 members:
- One is the leader (declared in the configuration as a seed node)
- The other is a simple member (not a seed node).

I would like the actors running on the simple members to perform an action 
when they detect that they have lost the connection with the rest of the 
cluster.

When I stop the leader node(akka.tcp://ClusterSystem@10.1.62.1:2552), I get 
the following logs in the surviving member 
(akka.tcp://ClusterSystem@10.1.62.2:2552):

[warn] a.c.ClusterCoreDaemon - Cluster Node 
[akka.tcp://ClusterSystem@10.1.62.2:2552] - Marking node(s) as UNREACHABLE 
[Member(address = akka.tcp://ClusterSystem@10.1.62.1:2552, status = 
Leaving)]. Node roles [toiler]
[warn] a.r.t.n.NettyTransport - Remote connection to null failed with 
java.net.ConnectException: Connection refused: /10.1.62.1:2552
[warn] a.r.ReliableDeliverySupervisor - Association with remote system 
[akka.tcp://ClusterSystem@10.1.62.1:2552] has failed, address is now gated 
for [5000] ms. Reason: [Association failed with 
[akka.tcp://ClusterSystem@10.1.62.1:2552]] Caused by: [Connection refused: 
/10.1.62.1:2552]
[warn] a.r.t.n.NettyTransport - Remote connection to null failed with 
java.net.ConnectException: Connection refused: /10.1.62.1:2552
[warn] a.r.ReliableDeliverySupervisor - Association with remote system 
[akka.tcp://ClusterSystem@10.1.62.1:2552] has failed, address is now gated 
for [5000] ms. Reason: [Association failed with 
[akka.tcp://ClusterSystem@10.1.62.1:2552]] Caused by: [Connection refused: 
/10.1.62.1:2552]
[warn] a.r.t.n.NettyTransport - Remote connection to null failed with 
java.net.ConnectException: Connection refused: /10.1.62.1:2552
[warn] a.r.ReliableDeliverySupervisor - Association with remote system 
[akka.tcp://ClusterSystem@10.1.62.1:2552] has failed, address is now gated 
for [5000] ms. Reason: [Association failed with 
[akka.tcp://ClusterSystem@10.1.62.1:2552]] Caused by: [Connection refused: 
/10.1.62.1:2552]
[warn] a.r.t.n.NettyTransport - Remote connection to null failed with 
java.net.ConnectException: Connection refused: /10.1.62.1:2552
[warn] a.r.ReliableDeliverySupervisor - Association with remote system 
[akka.tcp://ClusterSystem@10.1.62.1:2552] has failed, address is now gated 
for [5000] ms. Reason: [Association failed with 
[akka.tcp://ClusterSystem@10.1.62.1:2552]] Caused by: [Connection refused: 
/10.1.62.1:2552]
[info] a.c.Cluster(akka://ClusterSystem) - Cluster Node 
[akka.tcp://ClusterSystem@10.1.62.2:2552] - Leader can currently not 
perform its duties, reachability status: 
[akka.tcp://ClusterSystem@10.1.62.2:2552 -> 
akka.tcp://ClusterSystem@10.1.62.1:2552: Unreachable [Unreachable] (1)], 
member status: [akka.tcp://ClusterSystem@10.1.62.1:2552 Leaving seen=false, 
akka.tcp://ClusterSystem@10.1.62.2:2552 Up seen=true]

As shown in the code below, I have tried to subscribe to the following 
events: UnreachableMember, LeaderChanged, and DisassociatedEvent without 
success they don't seem to be triggered when there is no more leader in the 
cluster.

import akka.actor._

import akka.cluster.Cluster

import akka.cluster.ClusterEvent.LeaderChanged

import akka.cluster.ClusterEvent._

import akka.remote.DisassociatedEvent

import play.api.Logger

 

trait Message

case class Ping( i: Int ) extends Message

case object Pong extends Message

case object Start extends Message


class ToilerActor extends Actor with ActorLogging 

{ 

    val cluster = Cluster( context.system )

 

    override def preStart(): Unit = 

    {

        Logger.info( "########################### Toiler prestarted 
###########################" )

        cluster.subscribe(self, initialStateMode = InitialStateAsEvents, 
classOf[UnreachableMember], classOf[LeaderChanged])

        context.system.eventStream.subscribe(self, classOf
[DisassociatedEvent])

        self ! Start

    }

    

    override def postStop(): Unit = cluster.unsubscribe(self)

 

    def receive = 

    {

        case Start => Logger.info( s"Actor started: ${self.path.toString}" )

        

        case ping: Ping => {

            Logger.info( s"Toiler ${self.path.toString} received ping ${ping
.i} message from ${sender.path.toString}" )

            sender ! Pong

        }

        

        case leader: LeaderChanged => {

            Logger.info( s"======================> Leader change detected: $
{leader}" )

        }

        

        case UnreachableMember( member ) => {

            Logger.info( s"======================> remote member detected 
as unreachable: ${member}" )

        }

        

        case event: DisassociatedEvent => {

            Logger.info( s"======================> remote host detected as 
disassociated: ${event.remoteAddress}" )

        }

    

        case x => Logger.info( s"Unknown message received: ${x.toString}" )

    }


}


What am I missing?  How can I subscribe or catch to the "Marking node(s) as 
UNREACHABLE [Member(address = akka.tcp://ClusterSystem@10.1.62.1:2552, 
status = Leaving)]"


Many thanks,


David

-- 
>>>>>>>>>>      Read the docs: http://akka.io/docs/
>>>>>>>>>>      Check the FAQ: 
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>>      Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to