private void RequestClusterRoutes() { if (startTime - DateTime.UtcNow < requestClusterRoutesOnStartWindow) { try { var scaleOutAddress = scaleOutConfigurationProvider.GetScaleOutAddress(); foreach (var domain in securityProvider.GetAllowedDomains()) { var message = Message.Create(new RequestClusterMessageRoutesMessage { RequestorNodeIdentity = scaleOutAddress.Identity, RequestorUri = scaleOutAddress.Uri.ToSocketAddress() }) .As <Message>(); message.SetDomain(domain); message.As <Message>().SignMessage(securityProvider); autoDiscoverySender.EnqueueMessage(message); logger.Info($"Request to discover cluster routes for Domain [{domain}] sent."); } } catch (Exception err) { logger.Error(err); } } }
private IEnumerable <MessageRouteDomainMap> GetMessageHubs(InternalRouteRegistration routeRegistration) => routeRegistration.ToEnumerable() .Where(r => !r.KeepRegistrationLocal && r.ReceiverIdentifier.IsMessageHub()) .SelectMany(r => securityProvider.GetAllowedDomains() .Select(dom => new MessageRouteDomainMap { MessageRoute = new Cluster.MessageRoute { Receiver = r.ReceiverIdentifier }, Domain = dom }));
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}!"); } } } }
private void SendDiscoverMessageRouteMessage(MessageRoute messageRoute) { try { var scaleOutAddress = scaleOutConfigurationProvider.GetScaleOutAddress(); var domains = messageRoute.Receiver.IsMessageHub() ? securityProvider.GetAllowedDomains() : new[] { securityProvider.GetDomain(messageRoute.Message.Identity) }; foreach (var domain in domains) { var message = Message.Create(new DiscoverMessageRouteMessage { RequestorNodeIdentity = scaleOutAddress.Identity, RequestorUri = scaleOutAddress.Uri.ToSocketAddress(), ReceiverIdentity = messageRoute.Receiver.IsMessageHub() ? messageRoute.Receiver.Identity : null, MessageContract = messageRoute.Message != null ? new MessageContract { Version = messageRoute.Message.Version, Identity = messageRoute.Message.Identity, Partition = messageRoute.Message.Partition } : null }) .As <Message>(); message.SetDomain(domain); message.SignMessage(securityProvider); autoDiscoverySender.EnqueueMessage(message); } } catch (SecurityException err) { logger.Error(err); } }