public UserServcie(IHttpClient httpClient, IDnsQuery dns, IOptions <ServiceDisvoveryOptions> options, ILogger <UserServcie> logger) { _dns = dns ?? throw new ArgumentNullException(nameof(dns)); _options = options ?? throw new ArgumentNullException(nameof(options)); _httpClient = httpClient; _logger = logger; }
public UserService(Resillience.IHttpClient client, IDnsQuery dnsQuery) { _client = client; _logger = Startup.logger; _userUrls = new List <string>(); try { //因为是查询consul的某个服务的服务实例,根据consul文档格式为:服务名.service.consul //所以第一个参数是:service.consul //第二参数是要查询的服务名 var services = dnsQuery.ResolveServiceAsync("service.consul", "user").Result; foreach (var service in services) { //返回查询到user服务下的第1个服务实例的ip和端口,给这个identity sever4去进行验证使用 var host = service.AddressList.First(); var port = service.Port; var url = $"http://{host}:{port}"; //存储全部能用的user服务的实例地址 _userUrls.Add(url); } } catch (Exception e) { } }
protected override void Decode(IChannelHandlerContext context, DatagramPacket message, List <object> output) { IByteBuffer buffer = message.Content; IDnsQuery query = NewQuery(message, buffer); bool success = false; try { int questionCount = buffer.ReadUnsignedShort(); int answerCount = buffer.ReadUnsignedShort(); int authorityRecordCount = buffer.ReadUnsignedShort(); int additionalRecordCount = buffer.ReadUnsignedShort(); DecodeQuestions(query, buffer, questionCount); DecodeRecords(query, DnsSection.ANSWER, buffer, answerCount); DecodeRecords(query, DnsSection.AUTHORITY, buffer, authorityRecordCount); DecodeRecords(query, DnsSection.ADDITIONAL, buffer, additionalRecordCount); output.Add(query); success = true; } finally { if (!success) { query.Release(); } } }
private void DecodeQuestions(IDnsQuery query, IByteBuffer buffer, int questionCount) { for (int i = questionCount; i > 0; i--) { query.AddRecord(DnsSection.QUESTION, recordDecoder.DecodeQuestion(buffer)); } }
public UserService(IHttpClient httpClient, IDnsQuery dnsQuery, IOptions <ServiceDiscoveryOptions> option, ILogger <UserService> logger) { _httpClient = httpClient; _dnsQuery = dnsQuery ?? throw new ArgumentNullException(nameof(dnsQuery)); _serviceOption = option.Value ?? throw new ArgumentNullException(nameof(option)); _ilogger = logger; }
public UserService(HttpClient httpClient, IOptions <ServiceDisvoveryOptions> options, IDnsQuery dnsQuery, ILogger <UserService> logger, IConfiguration configuration, IHttpContextAccessor httpContextAccessor ) { _httpClient = httpClient; _httpContextAccessor = httpContextAccessor; _logger = logger; _configuration = configuration; var address = dnsQuery.ResolveService("service.consul", options.Value.ServiceName); if (!string.IsNullOrEmpty(httpContextAccessor.HttpContext.Request?.Path.Value) && httpContextAccessor.HttpContext.Request.Path.Value.ToLower().Contains("/connect/token")) { address = dnsQuery.ResolveService("service.consul", _configuration.GetValue <string>("PostUserapiServiceName")); } var addressList = address.First().AddressList; var host = addressList.Any() ? addressList.First().ToString() : address.First().HostName; var port = address.First().Port; _userServiceUrl = $"http://{host}:{port}/"; }
// public UserService(HttpClient httpClient,IDnsQuery dnsQuery, IOptions<ServiceDiscoveryOptions> serviceOption) // { // _httpClient = httpClient; // _dnsQuery = dnsQuery ?? throw new ArgumentNullException(nameof(dnsQuery)); // _serviceOption = serviceOption.Value ?? throw new ArgumentNullException(nameof(serviceOption)); // } public UserService(IHttpClient httpClient, IDnsQuery dnsQuery, ILogger <UserService> logger) { _httpClient = httpClient; _dnsQuery = dnsQuery ?? throw new ArgumentNullException(nameof(dnsQuery)); _logger = logger; //_serviceOption = serviceOption.Value ?? throw new ArgumentNullException(nameof(serviceOption)); }
/// <summary> /// Initializes a new instance of the <see cref="DiscoveryClient"/> class. /// </summary> /// <param name="logger"></param> /// <param name="policyCreator"></param> /// <param name="httpContextAccessor"></param> /// <param name="dnsQuery"></param> public DiscoveryClient(ILogger <DiscoveryClient> logger, IHttpContextAccessor httpContextAccessor, IDnsQuery dnsQuery) { _client = new HttpClient(); _logger = logger; _httpContextAccessor = httpContextAccessor; _dnsQuery = dnsQuery; }
public UserInfoController(IDnsQuery dns, IOptions <ServiceDisvoveryOptions> options , IConsulClient consulClient, ILogger <UserInfoController> logger) { _dns = dns ?? throw new ArgumentNullException(nameof(dns)); _options = options ?? throw new ArgumentNullException(nameof(options)); _consulClient = consulClient ?? throw new ArgumentNullException(nameof(consulClient)); _logger = logger; }
public UserService(ILogger <UserService> logger, IHttpClient httpClient, IDnsQuery dns, IOptions <ServiceDiscoveryOptions> options, IOptions <DependencyServiceDiscoverySettings> dependencyService) { _logger = logger; _httpClient = httpClient; _dns = dns; _options = options.Value; _dependencyService = dependencyService.Value; }
public ActionResult Get([FromServicesAttribute] IDnsQuery dnsquery, [FromServicesAttribute] IOptions <ServiceDisvoveryOptions> serviceDisvoveryOptions) { var address = dnsquery.ResolveService("service.consul", serviceDisvoveryOptions.Value.ServiceName); var addressList = address.First().AddressList; var host = addressList.Any() ? addressList.First().ToString() : addressList.First().Address.ToString(); var port = address.First().Port; return(Ok($"http://{host}:{port}")); }
/// <summary> /// Creates a SRV lookup for <code>[name1.[nameN]].[baseDomain].</code> and aggregates the results /// of returned host name, port and list of <see cref="IPAddress"/>s. /// </summary> /// <remarks> /// List of IPAddresses can be empty if no matching additional records are returned. /// In case no result was found, an empty list will be returned. /// </remarks> /// <param name="query">The lookup instance.</param> /// <param name="baseDomain">The base domain, will be attached to the end of the query string.</param> /// <param name="names">List of tokens to identify the service. Will be concatinated in the given order.</param> /// <returns></returns> public static Task <ServiceHostEntry[]> ResolveServiceAsync(this IDnsQuery query, string baseDomain, string serviceName, ProtocolType protocol) { if (protocol == ProtocolType.Unspecified || protocol == ProtocolType.Unknown) { return(ResolveServiceAsync(query, baseDomain, serviceName, null)); } return(ResolveServiceAsync(query, baseDomain, serviceName, protocol.ToString())); }
private void EncodeRecords(IDnsQuery query, DnsSection section, IByteBuffer buffer) { int count = query.Count(section); for (int i = 0; i < count; i++) { recordEncoder.EncodeRecord(query.GetRecord <IDnsRecord>(section, i), buffer); } }
private void EncodeQuestions(IDnsQuery query, IByteBuffer buffer) { int count = query.Count(DnsSection.QUESTION); for (int i = 0; i < count; i++) { recordEncoder.EncodeQuestion(query.GetRecord <IDnsQuestion>(DnsSection.QUESTION, i), buffer); } }
public UserService(IHttpClient httpClient, IDnsQuery dnsQuery) { _httpClient = httpClient; _dnsQuery = dnsQuery; var result = dnsQuery.ResolveService("service.consul", ConsulServiceName); var address = result.First().AddressList.FirstOrDefault().ToString(); var port = result.First().Port; requesturl = $"http://{address}:{port}/api/user"; }
public ConsulController(IConsulClient consulClient, IDnsQuery dns, IOptions <ConsulConfig> consulConfig, ILogger <ConsulController> logger) { _consulClient = consulClient; _dns = dns; _consulConfig = consulConfig; _logger = logger; }
public UserService(IHttpClient _httpClient, IDnsQuery dnsQuery, IOptions <Dtos.ServiceDiscoveryOptions> options, ILogger <UserService> _logger) { httpClient = _httpClient; GetServiceUrl(options); logger = _logger; //var address= dnsQuery.ResolveService("", options.Value.UserServiceName); //var host = address.First().AddressList.FirstOrDefault(); //var port = address.First().Port; //UserServiceUrl = $"http://{host}:{port}"; }
public UserService(HttpClient httpClient, IDnsQuery dnsQuery, IOptions <Dto.ServiceDisvoveryOptions> serviceDiscoveryOptions) { _httpClient = httpClient; var address = dnsQuery.ResolveService("service.consul", serviceDiscoveryOptions.Value.UserServiceName); var addressList = address.First().AddressList; var host = addressList.Any() ? addressList.First().ToString() : address.First().HostName; var port = address.First().Port; _userServiceUrl = $"http://{host}:{port}"; }
public RestHttpClient(ILoggerFactory loggerFactory, PolicyOptions policyOptions, IDnsQuery dnsQuery, IHttpContextAccessor httpContextAccessor) { _httpClient = new HttpClient(); _policyWraps = new ConcurrentDictionary <string, AsyncPolicyWrap>(); _hosts = new ConcurrentDictionary <string, List <string> >(); _logger = loggerFactory.CreateLogger <RestHttpClient>(); _policyOptions = policyOptions; _dnsQuery = dnsQuery; _httpContextAccessor = httpContextAccessor; }
public UserService(IHttpClient httpClient, IDnsQuery dns, IOptions <ServiceDiscoveryOptions> options) { _httpClient = httpClient; var result = dns.ResolveService("service.consul", options.Value.ServiceName); var addressList = result.First().AddressList; var address = addressList.Any() ? addressList.First().ToString() : result.First().HostName; var port = result.First().Port; _userServiceUrl = $"http://{address.TrimEnd('.')}:{port}"; }
public UserService(IHttpClient httpClient, IDnsQuery dnsQuery, IOptions <ServiceDiscoveryOptions> serviceDisvoveryOptions, ILogger <ResilienceHttpClient> logger) { this.httpClient = httpClient; this._logger = logger; var address = dnsQuery.ResolveService("service.consul", serviceDisvoveryOptions.Value.UserServiceName); var addressList = address.First().AddressList; var host = addressList.Any() ? addressList.First().ToString() : address.First().HostName; var port = address.First().Port; _userServiceUrl = $"http://{host}:{port}"; }
public UserService(IHttpClient httpClient, ILogger <UserService> logger, IDnsQuery dnsQuery, IOptions <ServiceDisvoveryOptions> options) { _httpClient = httpClient; _logger = logger; var result = dnsQuery.ResolveService("service.consul", options.Value.UserServiceName); var addressList = result.First().AddressList; var address = addressList.Any() ? addressList.First().ToString() : result.First().HostName; var port = result.First().Port; _userServiceUrl = $"http://{address}:{port}"; }
public ContactService(IHttpClient httpClient, IDnsQuery dnsquery, IOptions <ServiceDisvoveryOptions> serviceDisvoveryOptions, ILogger <ContactService> logger) { _httpClient = httpClient; var address = dnsquery.ResolveService("service.consul", serviceDisvoveryOptions.Value.ContactServiceName); var addressList = address.First().AddressList; var host = addressList.Any() ? addressList.First().ToString() : addressList.First().Address.ToString(); var port = address.First().Port; _userContactUrl = $"http://{host}:{port}"; _logger = logger; }
public UserService(IHttpClient httpClient, IDnsQuery dnsQuery, IOptions <Dtos.ServiceDisvoveryOptions> serviceDisvoveryOptions, ILogger <UserService> logger) { _httpClient = httpClient; var address = dnsQuery.ResolveService("service.consul", serviceDisvoveryOptions.Value.UserServiceName); var addressList = address.First().AddressList; var host = addressList.Any()? addressList.First().ToString(): address.First().HostName?.TrimEnd('.'); var port = address.First().Port; _userServiceUrl = $"http://{host}:{port}"; _logger = logger; Console.WriteLine("current http url:" + _userServiceUrl); }
private void DecodeRecords(IDnsQuery query, DnsSection section, IByteBuffer buffer, int count) { for (int i = count; i > 0; i--) { IDnsRecord r = recordDecoder.DecodeRecord(buffer); if (r == null) { break; } query.AddRecord(section, r); } }
public ContactService(IHttpClient httpClient, IDnsQuery dns, IOptions <ServiceDisvoveryOptions> options, ILogger <UserServcie> logger) { _dns = dns ?? throw new ArgumentNullException(nameof(dns)); _options = options ?? throw new ArgumentNullException(nameof(options)); _httpClient = httpClient; _logger = logger; var result = _dns.ResolveService("service.consul", _options.Value.ContactServiceName); var addressList = result.First().AddressList; var address = addressList.Any() ? addressList.First().ToString() : result.First().HostName.TrimEnd('.'); var port = result.First().Port; userServiceUrl = $"http://{address}:{port}/"; }
public UserService(IHttpClient httpClient, IDnsQuery dnsQuery, IOptions <ServiceDiscoveryOptions> options, ILogger <UserService> logger) { _httpClient = httpClient; var address = dnsQuery.ResolveService("service.consul", options.Value.ServiceName); var addressList = address.First().AddressList; var host = addressList.Any() ? addressList.First().ToString() : address.First().HostName; //host = host.Contains('.') ? host.Split('.')[0] : host; var port = address.First().Port; url = $"http://{host}:{port}"; _logger = logger; }
/// <summary> /// The <c>GetHostName</c> method queries a DNS server to resolve the hostname of the <paramref name="address"/> via reverse lookup. /// </summary> /// <param name="query">The <see cref="IDnsQuery"/> instance.</param> /// <param name="address">The <see cref="IPAddress"/> to resolve.</param> /// <returns> /// The hostname if the reverse lookup was successful or <c>null</c>, in case the host was not found. /// If <see cref="ILookupClient.ThrowDnsErrors"/> is set to <c>true</c>, this method will throw an <see cref="DnsResponseException"/> instead of returning <c>null</c>! /// </returns> /// <exception cref="ArgumentNullException">If <paramref name="address"/>is null.</exception> /// <exception cref="DnsResponseException">If no host has been found and <see cref="ILookupClient.ThrowDnsErrors"/> is <c>true</c>.</exception> public static string GetHostName(this IDnsQuery query, IPAddress address) { if (query == null) { throw new ArgumentNullException(nameof(query)); } if (address == null) { throw new ArgumentNullException(nameof(address)); } var result = query.QueryReverse(address); return(GetHostNameAsyncProcessResult(result)); }
public UserService(IHttpClient httpClient , IOptions <Dtos.ServiceDisvoveryOptions> serOp , IDnsQuery dnsQuery , ILogger <UserService> logger) { _logger = logger; _httpClient = httpClient; var address = dnsQuery.ResolveService("service.consul", serOp.Value.ServiceName); var addressList = address.First().AddressList; var host = addressList.Any() ? addressList.First().ToString() : address.First().HostName; var port = address.First().Port; _userServiceUrl = $"http://localhost:{port}"; }
/// <summary> /// The <c>GetHostNameAsync</c> method queries a DNS server to resolve the hostname of the <paramref name="address"/> via reverse lookup. /// </summary> /// <param name="query">The <see cref="IDnsQuery"/> instance.</param> /// <param name="address">The <see cref="IPAddress"/> to resolve.</param> /// <returns> /// The hostname if the reverse lookup was successful or <c>null</c>, in case the host was not found. /// If <see cref="ILookupClient.ThrowDnsErrors"/> is set to <c>true</c>, this method will throw an <see cref="DnsResponseException"/> instead of returning <c>null</c>! /// </returns> /// <exception cref="ArgumentNullException">If <paramref name="address"/>is null.</exception> /// <exception cref="DnsResponseException">If no host has been found and <see cref="ILookupClient.ThrowDnsErrors"/> is <c>true</c>.</exception> public static async Task <string> GetHostNameAsync(this IDnsQuery query, IPAddress address) { if (query == null) { throw new ArgumentNullException(nameof(query)); } if (address == null) { throw new ArgumentNullException(nameof(address)); } var result = await query.QueryReverseAsync(address).ConfigureAwait(false); return(GetHostNameAsyncProcessResult(result)); }