Пример #1
0
        private void HandleInsertedHosts(int serviceId, IEnumerable <string> insertedHosts, ServiceSubscriberInfo serviceSubscriberInfo, string path)
        {
            var    connectionInfos = new List <ConnectionInfo>();
            string serializerName  = null;

            logger.LogInformation($"Insert client begin. ProxyName={serviceSubscriberInfo.ServiceProxy.ProxyName}");

            foreach (var hostName in insertedHosts)
            {
                ServicePublishInfo servicePublishInfo;
                try
                {
                    servicePublishInfo = GetServicePublishInfo($"{path}/{hostName}");
                }
                catch (Exception ex)
                {
                    logger.LogError(ex, $"Insert client failed, get connection infomation error. HostName={hostName}, ProxyName={serviceSubscriberInfo.ServiceProxy.ProxyName}");
                    continue;
                }

                var connectionInfo = new ConnectionInfo()
                {
                    Host = servicePublishInfo.Host,
                    Port = servicePublishInfo.Port
                };

                serviceSubscriberInfo.ConnectionInfos.Add(connectionInfo);
                connectionInfos.Add(connectionInfo);

                if (string.IsNullOrWhiteSpace(serializerName))
                {
                    serializerName = servicePublishInfo.SerializerName;
                }
            }

            IList <INodeClient> nodeClientList;

            try
            {
                nodeClientList = nodeClientManager.CreateNodeClientList(serviceId, connectionInfos, serializerName, serviceSubscriberInfo.UseNewClient, true);
            }
            catch (Exception ex)
            {
                logger.LogError(ex, "Insert client failed, create NodeClient error.");
                return;
            }

            try
            {
                serviceSubscriberInfo.ServiceProxy.AddClients(nodeClientList);
            }
            catch (Exception ex)
            {
                logger.LogError(ex, "Insert client failed, append client to ServiceProxy error.");
            }

            logger.LogInformation($"Insert client finished. ProxyName={serviceSubscriberInfo.ServiceProxy.ProxyName}");
        }
Пример #2
0
        private void HandleDeletedHosts(int serviceId, IEnumerable <string> deletedHosts, ServiceSubscriberInfo serviceSubscriberInfo)
        {
            logger.LogInformation($"Delete client begin. ProxyName={serviceSubscriberInfo.ServiceProxy.ProxyName}");

            foreach (var hostName in deletedHosts)
            {
                try
                {
                    var connectionInfo = serviceSubscriberInfo.ConnectionInfos.Where(c => Utils.GetHostName(c.Host, c.Port) == hostName).Single();
                    if (serviceSubscriberInfo.UseNewClient)
                    {
                        serviceSubscriberInfo.ServiceProxy.RemoveClient(connectionInfo.Host, connectionInfo.Port);
                    }
                    else
                    {
                        serviceSubscriberInfo.ServiceProxy.RemoveClient(connectionInfo.Host, connectionInfo.Port, false);
                        nodeClientManager.RemoveNodeClient(hostName);
                    }
                    serviceSubscriberInfo.ConnectionInfos.Remove(connectionInfo);
                }
                catch (Exception ex)
                {
                    logger.LogError(ex, $"Delete client failed. HostName={hostName}, ProxyName={serviceSubscriberInfo.ServiceProxy.ProxyName}");
                }
            }

            logger.LogInformation($"Delete client finished. ProxyName={serviceSubscriberInfo.ServiceProxy.ProxyName}");
        }