Пример #1
0
        private bool ProcessStartPeerMonitoringMessage(IMessage message, ISocket socket)
        {
            var shouldHandle = message.Equals(KinoMessages.StartPeerMonitoring);

            if (shouldHandle)
            {
                var payload = message.GetPayload <StartPeerMonitoringMessage>();

                logger.Debug($"Received {typeof(StartPeerMonitoringMessage).Name} for node {payload.SocketIdentity.GetAnyString()}@{payload.Uri}. "
                             + $"HealthUri: {payload.Health.Uri}");

                var meta = new ClusterMemberMeta
                {
                    HealthUri         = payload.Health.Uri,
                    HeartBeatInterval = payload.Health.HeartBeatInterval,
                    ScaleOutUri       = payload.Uri
                };
                meta = connectedPeerRegistry.FindOrAdd(new ReceiverIdentifier(payload.SocketIdentity), meta);
                // NOTE: Starting peer monitoring may happen after quite some time after it was first added.
                // To avoid immediate node disconnection, as being dead, update LastKnownHeartBeat before setting ConnectionEstablished to TRUE.
                meta.LastKnownHeartBeat    = DateTime.UtcNow;
                meta.ConnectionEstablished = true;
                StartDeadPeersCheck(meta.HeartBeatInterval);
                socket.Connect(new Uri(meta.HealthUri));

                logger.Debug($"Connected to node {payload.SocketIdentity.GetAnyString()}@{meta.HealthUri} for HeartBeat monitoring.");
            }

            return(shouldHandle);
        }
Пример #2
0
 private void CheckPeerConnection(ReceiverIdentifier nodeIdentifier, ClusterMemberMeta meta)
 {
     if (!meta.ConnectionEstablished)
     {
         using (var socket = socketFactory.CreateRouterSocket())
         {
             var uri = new Uri(meta.ScaleOutUri);
             try
             {
                 socket.SetMandatoryRouting();
                 socket.Connect(uri, waitUntilConnected: true);
                 var message = Message.Create(new PingMessage())
                               .As <Message>();
                 message.SetDomain(securityProvider.GetDomain(KinoMessages.Ping.Identity));
                 message.SetSocketIdentity(nodeIdentifier.Identity);
                 message.SignMessage(securityProvider);
                 socket.SendMessage(message);
                 socket.Disconnect(uri);
                 meta.LastKnownHeartBeat = DateTime.UtcNow;
             }
             catch (Exception err)
             {
                 routerLocalSocket.Send(Message.Create(new UnregisterUnreachableNodeMessage {
                     ReceiverNodeIdentity = nodeIdentifier.Identity
                 }));
                 logger.Warn($"Failed trying to check connectivity to node {nodeIdentifier}@{uri.ToSocketAddress()}. Peer deletion scheduled. {err}");
             }
         }
     }
 }
Пример #3
0
        private bool ProcessAddPeerMessage(IMessage message, ISocket _)
        {
            var shouldHandle = message.Equals(KinoMessages.AddPeer);

            if (shouldHandle)
            {
                var payload = message.GetPayload <AddPeerMessage>();

                logger.Debug($"New node {payload.SocketIdentity.GetAnyString()} added.");

                var meta = new ClusterMemberMeta
                {
                    HealthUri          = payload.Health.Uri,
                    HeartBeatInterval  = payload.Health.HeartBeatInterval,
                    ScaleOutUri        = payload.Uri,
                    LastKnownHeartBeat = DateTime.UtcNow
                };
                connectedPeerRegistry.FindOrAdd(new ReceiverIdentifier(payload.SocketIdentity), meta);
            }

            return(shouldHandle);
        }