public HeartbeatStartup(IDispatchMessages messageDispatcher, ReadOnlySettings settings)
            {
                backend = new ServiceControlBackend(messageDispatcher, settings);
                endpointName = settings.EndpointName();
                HostId = settings.Get<Guid>("NServiceBus.HostInformation.HostId");
                Host = settings.Get<string>("NServiceBus.HostInformation.DisplayName");
                Properties = settings.Get<Dictionary<string, string>>("NServiceBus.HostInformation.Properties");

                var interval = ConfigurationManager.AppSettings["Heartbeat/Interval"];
                if (!string.IsNullOrEmpty(interval))
                {
                    heartbeatInterval = TimeSpan.Parse(interval);
                }
                else if (settings.HasSetting("ServiceControl.Heartbeat.Interval"))
                {
                    heartbeatInterval = settings.Get<TimeSpan>("ServiceControl.Heartbeat.Interval");
                }

                ttlTimeSpan = TimeSpan.FromTicks(heartbeatInterval.Ticks*4); // Default ttl

                var ttl = ConfigurationManager.AppSettings["Heartbeat/TTL"];
                if (!string.IsNullOrEmpty(ttl))
                {
                    ttlTimeSpan = TimeSpan.Parse(ttl);
                }
                else if (settings.HasSetting("ServiceControl.Heartbeat.Ttl"))
                {
                    ttlTimeSpan = settings.Get<TimeSpan>("ServiceControl.Heartbeat.Ttl");
                }
            }
        public TimerBasedPeriodicCheck(IPeriodicCheck periodicCheck, ISendMessages messageSender, Configure configure, UnicastBus unicastBus, CriticalError criticalError)
        {
            this.periodicCheck    = periodicCheck;
            this.configure        = configure;
            this.unicastBus       = unicastBus;
            serviceControlBackend = new ServiceControlBackend(messageSender, configure, criticalError);

            timer = new Timer(Run, null, TimeSpan.Zero, periodicCheck.Interval);
        }
        public TimerBasedPeriodicCheck(IPeriodicCheck periodicCheck, ISendMessages messageSender, Configure configure, UnicastBus unicastBus, CriticalError criticalError)
        {

            this.periodicCheck = periodicCheck;
            this.configure = configure;
            this.unicastBus = unicastBus;
            serviceControlBackend = new ServiceControlBackend(messageSender, configure, criticalError);

            timer = new Timer(Run, null, TimeSpan.Zero, periodicCheck.Interval);
        }
        public void It_can_serialize_EndpointHeartbeat()
        {
            var body = ServiceControlBackend.Serialize(new EndpointHeartbeat
            {
                EndpointName = "My.Endpoint",
                ExecutedAt   = new DateTime(2016, 02, 01, 13, 59, 0, DateTimeKind.Utc),
                Host         = "Host",
                HostId       = Guid.Empty
            });

            Approver.Verify(Encoding.UTF8.GetString(body));
        }
示例#5
0
        protected override void Setup(FeatureConfigurationContext context)
        {
            var serviceControlQueue           = context.Settings.Get <string>(SettingsKeys.SagaAuditQueue);
            var customSagaEntitySerialization = context.Settings.GetOrDefault <Func <object, Dictionary <string, string> > >(SettingsKeys.CustomSerialization);

            var backend = new ServiceControlBackend(serviceControlQueue, context.Settings.LocalAddress());

            context.Pipeline.Register(new CaptureSagaStateBehavior.CaptureSagaStateRegistration(context.Settings.EndpointName(), backend, customSagaEntitySerialization));
            context.Pipeline.Register("CaptureSagaResultingMessages", new CaptureSagaResultingMessagesBehavior(), "Reports the messages sent by sagas to ServiceControl");
            context.Pipeline.Register("AuditInvokedSaga", new AuditInvokedSagaBehavior(), "Adds saga information to audit messages");

            context.RegisterStartupTask(b => new SagaAuditStartupTask(backend, b.GetRequiredService <IMessageDispatcher>()));
        }
        public void It_can_serialize_EndpointHeartbeat()
        {
            ConfigurationManager.AppSettings["ServiceControl/Queue"] = "SC";
            var settingsHolder = new SettingsHolder();
            var backend = new ServiceControlBackend(null, settingsHolder);

            var body = backend.Serialize(new EndpointHeartbeat
            {
                EndpointName = "My.Endpoint",
                ExecutedAt = new DateTime(2016, 02, 01, 13, 59, 0),
                Host = "Host",
                HostId = Guid.Empty
            });
            Approvals.Verify(Encoding.UTF8.GetString(body));
        }
        public void It_can_serialize_RegisterEndpointStartup()
        {
            var body = ServiceControlBackend.Serialize(new RegisterEndpointStartup
            {
                HostDisplayName = "Display name :-)",
                Endpoint        = "My.Endpoint",
                HostProperties  = new Dictionary <string, string>
                {
                    { "key1", "value1" },
                    { "key2", "value2" }
                },
                StartedAt = new DateTime(2016, 02, 01, 13, 59, 0, DateTimeKind.Utc),
                Host      = "Host",
                HostId    = Guid.Empty
            });

            Approver.Verify(Encoding.UTF8.GetString(body));
        }
        void ReportToBackend(CheckResult result)
        {
            var sender = Builder.Build <ISendMessages>();

            var serviceControlBackend = new ServiceControlBackend(sender, Configure, CriticalError);

            serviceControlBackend.Send(new ReportCustomCheckResult
            {
                HostId        = UnicastBus.HostInformation.HostId,
                Host          = UnicastBus.HostInformation.DisplayName,
                EndpointName  = Configure.Settings.EndpointName(),
                CustomCheckId = Id,
                Category      = Category,
                HasFailed     = result.HasFailed,
                FailureReason = result.FailureReason,
                ReportedAt    = DateTime.UtcNow
            });
        }
示例#9
0
            protected override async Task OnStart(IMessageSession session)
            {
                if (!customChecks.Any())
                {
                    return;
                }

                timerPeriodicChecks   = new List <TimerBasedPeriodicCheck>(customChecks.Count);
                serviceControlBackend = new ServiceControlBackend(dispatchMessages, settings, criticalError);
                await serviceControlBackend.VerifyIfServiceControlQueueExists().ConfigureAwait(false);

                foreach (var check in customChecks)
                {
                    var timerBasedPeriodicCheck = new TimerBasedPeriodicCheck(check, serviceControlBackend);
                    timerBasedPeriodicCheck.Start();

                    timerPeriodicChecks.Add(timerBasedPeriodicCheck);
                }
            }
        public void It_can_serialize_RegisterEndpointStartup()
        {
            ConfigurationManager.AppSettings["ServiceControl/Queue"] = "SC";
            var settingsHolder = new SettingsHolder();
            var backend = new ServiceControlBackend(null, settingsHolder);

            var body = backend.Serialize(new RegisterEndpointStartup
            {
                HostDisplayName = "Display name :-)",
                Endpoint = "My.Endpoint",
                HostProperties = new Dictionary<string, string>
                {
                    {"key1", "value1"},
                    {"key2", "value2"}
                },
                StartedAt = new DateTime(2016, 02, 01, 13, 59, 0),
                Host = "Host",
                HostId = Guid.Empty
            });
            Approvals.Verify(Encoding.UTF8.GetString(body));
        }
        public void Run(Configure config)
        {
            if (!IsEnabledByDefault)
            {
                return;
            }
            
            backend = new ServiceControlBackend(SendMessages, Configure, CriticalError);
            heartbeatInterval = TimeSpan.FromSeconds(10); // Default interval
            var interval = ConfigurationManager.AppSettings[@"Heartbeat/Interval"];
            
            if (!String.IsNullOrEmpty(interval))
            {
                heartbeatInterval = TimeSpan.Parse(interval);
            }

            ttlTimeSpan = TimeSpan.FromTicks(heartbeatInterval.Ticks * 4); // Default ttl
            var ttl = ConfigurationManager.AppSettings[@"Heartbeat/TTL"];
            if (!String.IsNullOrWhiteSpace(ttl))
            {
                if (TimeSpan.TryParse(ttl, out ttlTimeSpan))
                {
                    logger.InfoFormat("Heartbeat/TTL set to {0}", ttlTimeSpan);
                }
                else
                {
                    ttlTimeSpan = TimeSpan.FromTicks(heartbeatInterval.Ticks * 4);
                    logger.Warn("Invalid Heartbeat/TTL specified in AppSettings. Reverted to default TTL (4 x Heartbeat/Interval)");   
                }
            }
            
            var hostInfo = UnicastBus.HostInformation;

            SendStartupMessageToBackend(hostInfo);

            heartbeatTimer = new Timer(x => ExecuteHeartbeat(hostInfo), null, TimeSpan.Zero, heartbeatInterval);
        }
        void ReportToBackend(CheckResult result)
        {
            var sender = Builder.Build<ISendMessages>();

            var serviceControlBackend = new ServiceControlBackend(sender, Configure, CriticalError);
            serviceControlBackend.Send(new ReportCustomCheckResult
            {
                HostId = UnicastBus.HostInformation.HostId,
                Host = UnicastBus.HostInformation.DisplayName,
                EndpointName = Configure.Settings.EndpointName(),
                CustomCheckId = Id,
                Category = Category,
                HasFailed = result.HasFailed,
                FailureReason = result.FailureReason,
                ReportedAt = DateTime.UtcNow
            });
        }
 public CaptureSagaStateBehavior(Configure configure, ServiceControlBackend backend)
 {
     this.configure = configure;
     this.backend   = backend;
 }
 public TimerBasedPeriodicCheck(ICustomCheck customCheck, ServiceControlBackend serviceControlBackend)
 {
     this.customCheck = customCheck;
     this.serviceControlBackend = serviceControlBackend;
 }
示例#15
0
 public TimerBasedPeriodicCheck(ICustomCheck customCheck, ServiceControlBackend serviceControlBackend)
 {
     this.customCheck           = customCheck;
     this.serviceControlBackend = serviceControlBackend;
 }
示例#16
0
 public SagaAuditStartupTask(ServiceControlBackend backend, IMessageDispatcher dispatcher)
 {
     serviceControlBackend = backend;
     this.dispatcher       = dispatcher;
 }