protected override async Task Execute(CancellationToken token)
        {
            var instanceDiscoveryService =
                new InstanceDiscoveryService.InstanceDiscoveryServiceClient(GrpcChannelManager.Instance.Channel);

            var heartbeat = new ApplicationInstanceHeartbeat
            {
                ApplicationInstanceId = RemoteDownstreamConfig.Agent.ApplicationInstanceId,
                HeartbeatTime         = DateTime.UtcNow.GetTimeMillis()
            };

            await instanceDiscoveryService.heartbeatAsync(heartbeat);
        }
        public async Task HeartbeatAsync(int applicationInstance, long heartbeatTime, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (!_connectionManager.Ready)
            {
                return;
            }
            var connection = _connectionManager.GetConnection();

            var client = new InstanceDiscoveryService.InstanceDiscoveryServiceClient(connection);

            var heartbeat = new ApplicationInstanceHeartbeat
            {
                ApplicationInstanceId = applicationInstance,
                HeartbeatTime         = heartbeatTime
            };

            await ExecuteWithCatch(async() => await client.heartbeatAsync(heartbeat, null, _config.GetTimeout(), cancellationToken), () => ExceptionHelpers.HeartbeatError);
        }
Beispiel #3
0
        protected override async Task Execute(CancellationToken token)
        {
            if (DictionaryUtil.IsNull(RemoteDownstreamConfig.Agent.ApplicationInstanceId))
            {
                _logger.Debug($"{DateTime.Now} Heartbeat fail. Application instance is not registered.");
                return;
            }

            var availableConnection = GrpcConnectionManager.Instance.GetAvailableConnection();

            if (availableConnection == null)
            {
                _logger.Debug($"{DateTime.Now} Heartbeat fail. {GrpcConnectionManager.NotFoundErrorMessage}");
                return;
            }

            try
            {
                var instanceDiscoveryService =
                    new InstanceDiscoveryService.InstanceDiscoveryServiceClient(availableConnection.GrpcChannel);

                var heartbeat = new ApplicationInstanceHeartbeat
                {
                    ApplicationInstanceId = RemoteDownstreamConfig.Agent.ApplicationInstanceId,
                    HeartbeatTime         = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
                };

                await instanceDiscoveryService.heartbeatAsync(heartbeat);

                _logger.Debug($"{DateTime.Now} Heartbeat.");
            }
            catch (Exception e)
            {
                _logger.Debug($"{DateTime.Now} Heartbeat fail. {e.Message}");
                availableConnection.Failure();
            }
        }