public void ProcessInstanceUpdated(MQTTMessage mqttMessage, string topic) { InstanceHealthService.Health.MQTTMessagesReceived += 1; var receivedMessage = mqttMessage.Message.ToString().Replace("'", "\""); var instance = JsonConvert.DeserializeObject <Instance>(receivedMessage); instance.TenantId = GetTenantFromTopicName(topic); if (instance != null && mqttMessage.FromInstanceId.CompareTo(Program.InstanceConfig.ServerInstanceID) != 0) { var memoryRepo = new MemoryServicesRepository(instance.TenantId, Program.InstanceConfig.EvictionInSecs); memoryRepo.Add(instance); } }
public ActionResult <string> AddAppInstance([FromRoute] string appName, [FromBody] ServiceInstaceRegisterRequest request, [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); request.instance.AppName = appName; MemoryServicesRepository repo = new MemoryServicesRepository(tenantId, Program.InstanceConfig.EvictionInSecs); Instance instance = repo.Add(request.instance); publishService.PublishAddedOrUpdatedInstance(instance, "ADD_INSTANCE"); this.HttpContext.Response.StatusCode = 204; return(string.Empty); }