public void Handle(IMessage message, ISocket _)
        {
            if (securityProvider.DomainIsAllowed(message.Domain))
            {
                message.As <Message>().VerifySignature(securityProvider);

                var payload = message.GetPayload <RegisterExternalMessageRouteMessage>();
                var peer    = new Node(new Uri(payload.Uri), payload.NodeIdentity);
                var health  = new Health
                {
                    Uri = payload.Health.Uri,
                    HeartBeatInterval = payload.Health.HeartBeatInterval
                };
                var peerAddedForMonitoring = false;
                foreach (var route in payload.Routes)
                {
                    var receiver      = new ReceiverIdentifier(route.ReceiverIdentity);
                    var messageRoutes = receiver.IsMessageHub()
                                            ? new MessageRoute {
                        Receiver = receiver
                    }.ToEnumerable()
                                            : route.MessageContracts.Select(mc => new MessageRoute
                    {
                        Receiver = receiver,
                        Message  = new MessageIdentifier(mc.Identity, mc.Version, mc.Partition)
                    });
                    foreach (var messageRoute in messageRoutes)
                    {
                        try
                        {
                            //NOTE: Keep the order in if(...), hence MessageHub is not registered to receive any specific message
                            if (receiver.IsMessageHub() || securityProvider.GetDomain(messageRoute.Message.Identity) == message.Domain)
                            {
                                if (!peerAddedForMonitoring)
                                {
                                    clusterHealthMonitor.AddPeer(peer, health);
                                    peerAddedForMonitoring = true;
                                }

                                externalRoutingTable.AddMessageRoute(new ExternalRouteRegistration
                                {
                                    Route  = messageRoute,
                                    Peer   = peer,
                                    Health = health
                                });
                            }
                            else
                            {
                                logger.Warn($"MessageIdentity {messageRoute.Message} doesn't belong to requested Domain {message.Domain}!");
                            }
                        }
                        catch (Exception err)
                        {
                            logger.Error(err);
                        }
                    }
                }
            }
        }
        public void Handle(IMessage message, ISocket _)
        {
            if (securityProvider.DomainIsAllowed(message.Domain))
            {
                message.As <Message>().VerifySignature(securityProvider);

                nodeRoutesRegistrar.RegisterOwnGlobalRoutes(message.Domain);
            }
        }
Пример #3
0
        public void Handle(IMessage message, ISocket _)
        {
            if (securityProvider.DomainIsAllowed(message.Domain))
            {
                message.As <Message>().VerifySignature(securityProvider);

                var payload        = message.GetPayload <DiscoverMessageRouteMessage>();
                var internalRoutes = internalRoutingTable.GetAllRoutes();
                var messageRoutes  = new List <Cluster.MessageRoute>();
                if (payload.ReceiverIdentity.IsMessageHub())
                {
                    messageRoutes.AddRange(internalRoutes.MessageHubs
                                           .Where(mh => !mh.LocalRegistration &&
                                                  mh.MessageHub.Equals(new ReceiverIdentifier(payload.ReceiverIdentity)))
                                           .Select(mh => new Cluster.MessageRoute {
                        Receiver = mh.MessageHub
                    }));
                }
                else
                {
                    var messageContract = new MessageIdentifier(payload.MessageContract.Identity, payload.MessageContract.Version, payload.MessageContract.Partition);
                    messageRoutes.AddRange(internalRoutes.Actors
                                           .Where(r => r.Message.Equals(messageContract))
                                           .SelectMany(r => r.Actors
                                                       .Where(a => !a.LocalRegistration)
                                                       .Select(a => new Cluster.MessageRoute
                    {
                        Receiver = a,
                        Message  = messageContract
                    })));
                }
                foreach (var messageRoute in messageRoutes)
                {
                    var domains = messageRoute.Receiver.IsMessageHub()
                                      ? securityProvider.GetAllowedDomains()
                                      : new[] { securityProvider.GetDomain(messageRoute.Message.Identity) };
                    if (domains.Contains(message.Domain))
                    {
                        clusterMonitor.RegisterSelf(messageRoute.ToEnumerable(), message.Domain);
                    }
                    else
                    {
                        logger.Warn($"MessageIdentity {messageRoute.Message} doesn't belong to requested Domain {message.Domain}!");
                    }
                }
            }
        }
        public void Handle(IMessage message, ISocket scaleOutBackend)
        {
            if (securityProvider.DomainIsAllowed(message.Domain))
            {
                message.As <Message>().VerifySignature(securityProvider);

                var payload = message.GetPayload <UnregisterNodeMessage>();

                var nodeIdentifer    = new ReceiverIdentifier(payload.ReceiverNodeIdentity);
                var peerRemoveResult = externalRoutingTable.RemoveNodeRoute(nodeIdentifer);
                if (peerRemoveResult.ConnectionAction == PeerConnectionAction.Disconnect)
                {
                    scaleOutBackend.SafeDisconnect(peerRemoveResult.Uri);
                }
                if (peerRemoveResult.ConnectionAction != PeerConnectionAction.KeepConnection)
                {
                    clusterHealthMonitor.DeletePeer(nodeIdentifer);
                }
            }
        }