public async Task RegisterRoutes() { var addess = NetUtils.GetHostAddress(); var addressDescriptors = _serviceEntryManager.GetEntries().Select(i => { return(new ServiceRoute { Address = new[] { addess }, ServiceDescriptor = i.Descriptor }); }).ToList(); await _serviceRouteManager.SetRoutesAsync(addressDescriptors); }
public async Task RegisterRoutes(decimal processorTime) { var addess = NetUtils.GetHostAddress(); addess.ProcessorTime = processorTime; RpcContext.GetContext().SetAttachment("Host", addess); var addressDescriptors = _serviceEntryManager.GetEntries().Select(i => { i.Descriptor.Token = _serviceTokenGenerator.GetToken(); return(new ServiceRoute { Address = new[] { addess }, ServiceDescriptor = i.Descriptor }); }).ToList(); await _serviceRouteManager.SetRoutesAsync(addressDescriptors); }
public async Task RegisterRoutes(decimal processorTime) { var addess = NetUtils.GetHostAddress(); addess.ProcessorTime = processorTime; addess.Weight = SurgingConfig.MicroService.Surging.Weight; if (addess.Weight > 0) { addess.Timestamp = DateTimeConverter.DateTimeToUnixTimestamp(DateTime.Now); } RpcContext.GetContext().SetAttachment("Host", addess); var addressDescriptors = _serviceEntryManager.GetEntries().Select(i => { i.Descriptor.Token = _serviceTokenGenerator.GetToken(); return(new ServiceRoute { Address = new[] { addess }, ServiceDescriptor = i.Descriptor }); }).ToList(); await _serviceRouteManager.SetRoutesAsync(addressDescriptors); }
public async void PollingAddressChangeTest() { IAddressSelector selector = new PollingAddressSelector(_serviceRouteManager); await selector.SelectAsync(GetSelectContext()); await selector.SelectAsync(GetSelectContext()); var address = (IpAddressModel)await selector.SelectAsync(GetSelectContext()); Assert.Equal(3, address.Port); //更新路由信息。 await _serviceRouteManager.SetRoutesAsync(new[] { new ServiceRoute { Address = new[] { new IpAddressModel("127.0.0.1", 0), new IpAddressModel("127.0.0.1", 2) }, ServiceDescriptor = new ServiceDescriptor { Id = "service1" } } }); address = (IpAddressModel)await selector.SelectAsync(GetSelectContext()); Assert.Equal(0, address.Port); address = (IpAddressModel)await selector.SelectAsync(GetSelectContext()); Assert.Equal(2, address.Port); ((TestServiceRouteManager)_serviceRouteManager).Reset(); }