示例#1
0
 private void OnSubscribed(NatsSubscription subscription)
 {
     Logger.Info($"{nameof(OnSubscribed)}");
     Script.Statements.Add(new ScriptStatement {
         Name = nameof(SubscribeCommand), Param1 = subscription.Subject, Param2 = ""
     });
 }
示例#2
0
 private void OnItemDoubleClicked(string colName, NatsSubscription subscription)
 {
     if (subscription.Subscribed)
     {
         Unsubscribe(subscription);
     }
     else
     {
         Subscribe(subscription);
     }
 }
示例#3
0
        public void Unsubscribe(NatsSubscription natsSubscription)
        {
            if (Subscriptions.TryGetValue(natsSubscription, out var subs))
            {
                foreach (var subscription in subs)
                {
                    subscription.Unsubscribe();
                }

                Subscriptions.Remove(natsSubscription);
                natsSubscription.Subscribed = false;
                Unsubscribed?.Invoke(natsSubscription);
            }
        }
示例#4
0
        public void Start()
        {
            if (natsClient.Start())
            {
                discoverMessage = new VcapComponentDiscover(
                    type: Resources.Agent_DEAComponentType,
                    uuid: natsClient.UniqueIdentifier,
                    host: config.MonitoringServiceHostStr,
                    credentials: config.MonitoringCredentials);

                varzProvider.Discover = discoverMessage;

                natsClient.Subscribe(NatsSubscription.VcapComponentDiscover,
                                     (msg, reply) =>
                {
                    discoverMessage.UpdateUptime();
                    natsClient.Publish(reply, discoverMessage);
                });

                natsClient.Publish(new VcapComponentAnnounce(discoverMessage));

                natsClient.Subscribe(NatsSubscription.DeaStatus, ProcessDeaStatus);
                natsClient.Subscribe(NatsSubscription.DropletStatus, ProcessDropletStatus);
                natsClient.Subscribe(NatsSubscription.DeaDiscover, ProcessDeaDiscover);
                natsClient.Subscribe(NatsSubscription.DeaFindDroplet, ProcessDeaFindDroplet);
                natsClient.Subscribe(NatsSubscription.DeaUpdate, ProcessDeaUpdate);
                natsClient.Subscribe(NatsSubscription.DeaStop, ProcessDeaStop);
                natsClient.Subscribe(NatsSubscription.GetDeaInstanceStartFor(natsClient.UniqueIdentifier), ProcessDeaStart);
                natsClient.Subscribe(NatsSubscription.RouterStart, ProcessRouterStart);
                natsClient.Subscribe(NatsSubscription.HealthManagerStart, ProcessHealthManagerStart);
                natsClient.Subscribe(NatsSubscription.DeaLocate, ProcessDeaLocate);

                natsClient.Publish(helloMessage);

                SendAdvertise();

                RecoverExistingDroplets();

                processTask.Start();
                heartbeatTask.Start();
                advertiseTask.Start();
                varzTask.Start();
                monitorAppsTask.Start();
            }
            else
            {
                log.Error(Resources.Agent_ErrorDetectedInNats_Message);
                Error = true;
            }
        }
示例#5
0
        public bool Create(NatsSubscription natsSubscription, out string msg)
        {
            Logger.Info($"Create NatsSubject: {natsSubscription.Subject}");
            if (Configuration.GetSubject(natsSubscription.Subject) != null)
            {
                msg = $"A subject already exists with subject: {natsSubscription.Subject}";
                Logger.Warn(msg);
                return(false);
            }
            Configuration.Add(natsSubscription);
            Configuration.Save(NatsXml);

            msg = $"NatsSubject created: {natsSubscription}";
            return(true);
        }
示例#6
0
        protected void CreateSubscription()
        {
            Logger.Info($"{nameof(CreateSubscription)}: {Model}");
            var natsSubscription = new NatsSubscription(Model.Subject)
            {
                Checked    = false,
                Subscribed = false
            };

            if (NatsService.Create(natsSubscription, out _))
            {
                Subscriptions.Insert(0, natsSubscription);
            }
            Subscribe(natsSubscription);
        }
示例#7
0
        private void OnItemClicked(string colName, NatsSubscription subscription)
        {
            switch (colName)
            {
            case nameof(NatsSubscription.Unsubscribe):
                Unsubscribe(subscription);
                break;

            case nameof(NatsSubscription.Subscribe):
                Subscribe(subscription);
                break;

            case nameof(NatsSubscription.Trash):
                Logger.Info($"{nameof(NatsSubscription.Trash)}: {subscription}");
                NatsService.Remove(subscription);
                Subscriptions.Remove(subscription);
                break;
            }
        }
示例#8
0
        public void Subscribe(NatsSubscription natsSubscription)
        {
            if (Subscriptions.ContainsKey(natsSubscription))
            {
                return;
            }

            Logger.Info($"{nameof(Subscribe)}: {natsSubscription.Subject}");
            List <IAsyncSubscription> subs = new List <IAsyncSubscription>();

            foreach (var conn in ConnectionsByName.Values)
            {
                IAsyncSubscription sub = conn.SubscribeAsync(natsSubscription.Subject, OnMessage);
                subs.Add(sub);
            }

            Subscriptions[natsSubscription] = subs;
            natsSubscription.Subscribed     = subs.Any();
            Subscribed?.Invoke(natsSubscription);
        }
示例#9
0
 public void Remove(NatsSubscription natsSubscription)
 {
     Logger.Info($"Remove NatsSubject: {natsSubscription.Subject}");
     Configuration.RemoveSubject(natsSubscription.Subject);
     Configuration.Save(NatsXml);
 }
示例#10
0
 public void Add(NatsSubscription subscription)
 {
     RemoveSubject(subscription.Subject);
     Subscriptions.Add(subscription);
 }
示例#11
0
 private void OnSelectedItemChanged(NatsSubscription subscription)
 {
     Model.Subject = subscription.Subject;
     InvokeAsync(StateHasChanged);
 }
示例#12
0
 private void Subscribe(NatsSubscription subscription)
 {
     Logger.Info($"{nameof(NatsSubscription.Subscribe)}: {subscription}");
     NatsService.Subscribe(subscription);
     Subscriptions.Update(subscription);
 }