private void UpdateRemoteNotifications(IList <ApolloConfigNotification> deltaNotifications)
        {
            foreach (ApolloConfigNotification notification in deltaNotifications)
            {
                if (String.IsNullOrEmpty(notification.NamespaceName))
                {
                    continue;
                }

                if (notification.Messages == null || notification.Messages.IsEmpty())
                {
                    continue;
                }

                ApolloNotificationMessages localRemoteMessages = null;
                m_remoteNotificationMessages.TryGetValue(notification.NamespaceName, out localRemoteMessages);
                if (localRemoteMessages == null)
                {
                    localRemoteMessages = new ApolloNotificationMessages();
                    m_remoteNotificationMessages[notification.NamespaceName] = localRemoteMessages;
                }

                localRemoteMessages.MergeFrom(notification.Messages);
            }
        }
Ejemplo n.º 2
0
 public void OnLongPollNotified(ServiceDTO longPollNotifiedServiceDto, ApolloNotificationMessages remoteMessages)
 {
     m_longPollServiceDto.WriteFullFence(longPollNotifiedServiceDto);
     m_remoteMessages.WriteFullFence(remoteMessages);
     m_executorService.QueueWorkItem(() =>
     {
         TrySync();
     });
 }
Ejemplo n.º 3
0
 public void AddMessage(string key, long notificationId)
 {
     if (this.messages == null)
     {
         lock (this)
         {
             if (this.messages == null)
             {
                 this.messages = new ApolloNotificationMessages();
             }
         }
     }
     this.messages.Put(key, notificationId);
 }
Ejemplo n.º 4
0
        public void OnLongPollNotified(ServiceDto longPollNotifiedServiceDto, ApolloNotificationMessages remoteMessages)
        {
            _longPollServiceDto = longPollNotifiedServiceDto;
            _remoteMessages     = remoteMessages;

            ExecutorService.StartNew(async() =>
            {
                try
                {
                    await Sync(false).ConfigureAwait(false);
                }
                catch (Exception ex)
                {
                    Logger().Warn($"Sync config failed, will retry. Repository {GetType()}, reason: {ex.GetDetailMessage()}");
                }
            });
        }
        public void OnLongPollNotified(ServiceDto longPollNotifiedServiceDto, ApolloNotificationMessages remoteMessages)
        {
            _longPollServiceDto.WriteFullFence(longPollNotifiedServiceDto);
            _remoteMessages.WriteFullFence(remoteMessages);

            ExecutorService.StartNew(async() =>
            {
                try
                {
                    await Sync();
                }
                catch (Exception ex)
                {
                    Logger.Warn($"Sync config failed, will retry. Repository {GetType()}, reason: {ex.GetDetailMessage()}");
                }
            });
        }
Ejemplo n.º 6
0
        private string AssembleQueryConfigUrl(string uri,
                                              string appId,
                                              string cluster,
                                              string?namespaceName,
                                              string?dataCenter,
                                              ApolloNotificationMessages remoteMessages,
                                              ApolloConfig previousConfig)
        {
            if (!uri.EndsWith("/", StringComparison.Ordinal))
            {
                uri += "/";
            }
            //Looks like .Net will handle all the url encoding for me...
            var path       = $"configs/{appId}/{cluster}/{namespaceName}";
            var uriBuilder = new UriBuilder(uri + path);
            var query      = new Dictionary <string, string>();

            if (previousConfig != null)
            {
                query["releaseKey"] = previousConfig.ReleaseKey;
            }

            if (!string.IsNullOrEmpty(dataCenter))
            {
                query["dataCenter"] = dataCenter !;
            }

            var localIp = _options.LocalIp;

            if (!string.IsNullOrEmpty(localIp))
            {
                query["ip"] = localIp;
            }

            if (remoteMessages != null)
            {
                query["messages"] = JsonConvert.SerializeObject(remoteMessages, JsonSettings);
            }

            uriBuilder.Query = QueryUtils.Build(query);

            return(uriBuilder.ToString());
        }
        private void Notify(ServiceDTO lastServiceDto, IList <ApolloConfigNotification> notifications)
        {
            if (notifications == null || notifications.Count == 0)
            {
                return;
            }
            foreach (ApolloConfigNotification notification in notifications)
            {
                string namespaceName = notification.NamespaceName;
                //create a new list to avoid ConcurrentModificationException
                ISet <RemoteConfigRepository> registries   = null;
                List <RemoteConfigRepository> toBeNotified = new List <RemoteConfigRepository>();
                m_longPollNamespaces.TryGetValue(namespaceName, out registries);
                ApolloNotificationMessages originalMessages = null;
                m_remoteNotificationMessages.TryGetValue(namespaceName, out originalMessages);
                ApolloNotificationMessages remoteMessages = originalMessages == null ? null : originalMessages.Clone();

                if (registries != null && registries.Count > 0)
                {
                    toBeNotified.AddRange(registries);
                }
                //since .properties are filtered out by default, so we need to check if there is any listener for it
                ISet <RemoteConfigRepository> extraRegistries = null;
                m_longPollNamespaces.TryGetValue(string.Format("{0}.{1}", namespaceName, ConfigFileFormat.Properties.GetString()), out extraRegistries);
                if (extraRegistries != null && extraRegistries.Count > 0)
                {
                    toBeNotified.AddRange(extraRegistries);
                }
                foreach (RemoteConfigRepository remoteConfigRepository in toBeNotified)
                {
                    try
                    {
                        remoteConfigRepository.OnLongPollNotified(lastServiceDto, remoteMessages);
                    }
                    catch (Exception ex)
                    {
                        logger.Warn(ex);
                    }
                }
            }
        }
Ejemplo n.º 8
0
        private string AssembleQueryConfigUrl(string uri, string appId, string cluster, string namespaceName,
                                              string dataCenter, ApolloNotificationMessages remoteMessages, ApolloConfig previousConfig)
        {
            if (!uri.EndsWith("/", StringComparison.Ordinal))
            {
                uri += "/";
            }
            //Looks like .Net will handle all the url encoding for me...
            string     path       = string.Format("configs/{0}/{1}/{2}", appId, cluster, namespaceName);
            UriBuilder uriBuilder = new UriBuilder(uri + path);
            var        query      = HttpUtility.ParseQueryString(string.Empty);

            if (previousConfig != null)
            {
                query["releaseKey"] = previousConfig.ReleaseKey;
            }

            if (!string.IsNullOrEmpty(dataCenter))
            {
                query["dataCenter"] = dataCenter;
            }

            string localIp = m_configUtil.LocalIp;

            if (!string.IsNullOrEmpty(localIp))
            {
                query["ip"] = localIp;
            }

            if (remoteMessages != null)
            {
                query["messages"] = JSON.SerializeObject(remoteMessages);
            }

            uriBuilder.Query = query.ToString();

            return(uriBuilder.ToString());
        }