예제 #1
0
        // "/eureka/apps/{appName}/{instanceID}/status?value={status}&lastDirtyTimestamp=1568746948343"
        public ActionResult <string> ChangeInstanceStatus([FromRoute] string appName, [FromRoute] string instanceID, [FromQuery] string value, [FromQuery] long lastDirtyTimestamp, [FromServices] IPublishChangesService publishService, [FromServices] IMemoryDiscoveryClientRepository clientRepo, [FromServices] IPublishClientsService clientPublishService)
        {
            var tenantId       = this.GetTenantIdFromRouteData();
            var clientHostname = Request.HttpContext.Connection.RemoteIpAddress.ToString();

            clientRepo.Add(new DiscoveryClient(clientHostname));
            clientPublishService.PublishClientDiscoveryActivity(tenantId, clientHostname);

            MemoryServicesRepository repo = new MemoryServicesRepository(tenantId, Program.InstanceConfig.EvictionInSecs);

            if (lastDirtyTimestamp == 0)
            {
                lastDirtyTimestamp = DateTimeConversions.ToJavaMillis(DateTime.UtcNow);
            }

            var instance = repo.ChangeStatus(appName, instanceID, value, lastDirtyTimestamp);

            if (instance != null)
            {
                publishService.PublishInstanceStatusChange(instance.TenantId, appName, instanceID, value, lastDirtyTimestamp);

                this.HttpContext.Response.StatusCode = 200;
            }
            else
            {
                this.HttpContext.Response.StatusCode = 500;
            }

            return(string.Empty);
        }
        public void ProcessInstanceChangeStatus(MQTTMessage mqttMessage, string topic)
        {
            InstanceHealthService.Health.MQTTMessagesReceived += 1;

            var receivedMessage = mqttMessage.Message.ToString().Replace("'", "\"");

            var messageContent = JsonConvert.DeserializeObject <MQTTInstanceChangeStatusMessageContent>(receivedMessage);

            if (messageContent != null && mqttMessage.FromInstanceId.CompareTo(Program.InstanceConfig.ServerInstanceID) != 0)
            {
                var memoryRepo = new MemoryServicesRepository(messageContent.TenantId, Program.InstanceConfig.EvictionInSecs);
                memoryRepo.ChangeStatus(messageContent.AppName, messageContent.InstanceId, messageContent.Status, messageContent.LastDirtyTimestamp);
            }
        }