Exemplo n.º 1
0
        private bool SendToExactReceiver(Message message, ISocket scaleOutBackend, ExternalRouteLookupRequest lookupRequest)
        {
            if (Unsafe.ArraysEqual(message.ReceiverNodeIdentity, thisNodeIdentity))
            {
                var localDestinations = internalRoutingTable.FindRoutes(lookupRequest);
                return(SendMessageLocally(localDestinations, message));
            }

            var remoteDestinations = externalRoutingTable.FindRoutes(lookupRequest);

            return(SendMessageAway(remoteDestinations, message, scaleOutBackend));
        }
Exemplo n.º 2
0
        private bool HandleMessageLocally(InternalRouteLookupRequest lookupRequest, Message message)
        {
            var destinations = internalRoutingTable.FindRoutes(lookupRequest);

            foreach (var destination in destinations)
            {
                try
                {
                    message = MessageCameFromLocalActor(message)
                                  ? message.Clone()
                                  : message;

                    message.SetSocketIdentity(destination.As <ILocalSocket <IMessage> >().GetIdentity().Identity);
                    destination.Send(message);
                    RoutedToLocalActor(message);
                }
                catch (HostUnreachableException err)
                {
                    //TODO: HostUnreachableException will never happen here, hence NetMQ sockets are not used
                    //TODO: ILocalSocketShould throw similar exception, if no one is reading messages from the socket,
                    //TODO: which should be a trigger for deletion of the ActorHost
                    //TODO: When change is done, cover with unitests
                    var removedRoutes = internalRoutingTable.RemoveReceiverRoute(destination)
                                        .Select(rr => new Cluster.MessageRoute
                    {
                        Receiver = rr.Receiver,
                        Message  = rr.Message
                    });
                    if (removedRoutes.Any())
                    {
                        clusterServices.GetClusterMonitor().UnregisterSelf(removedRoutes);
                    }
                    logger.Error(err);
                }
            }

            return(destinations.Any());
        }