Search in sources :

Example 1 with Endpoint

use of com.linecorp.armeria.client.Endpoint in project curiostack by curioswitch.

the class ClientBuilderFactory method create.

public ClientBuilder create(String name, String url) {
    URI uri = URI.create(url);
    EndpointGroup endpoint = Endpoint.parse(uri.getAuthority());
    if (((Endpoint) endpoint).authority().endsWith("cluster.local")) {
        DnsAddressEndpointGroup dnsEndpointGroup = DnsAddressEndpointGroup.builder(uri.getHost()).port(uri.getPort()).ttl(1, 10).build();
        dnsEndpointGroup.addListener(endpoints -> logger.info("Resolved new endpoints for {} : [ {} ]", name, endpoints.stream().map(e -> MoreObjects.firstNonNull(e.ipAddr(), e.authority())).collect(Collectors.joining(","))));
        HealthCheckedEndpointGroup endpointGroup = HealthCheckedEndpointGroup.builder(dnsEndpointGroup, "/internal/health").clientFactory(clientFactory).protocol(SessionProtocol.HTTPS).retryInterval(Duration.ofSeconds(3)).build();
        endpoint = endpointGroup;
    }
    ClientBuilder builder = Clients.builder(uri.getScheme(), endpoint, uri.getPath()).factory(clientFactory);
    return builder.decorator(MetricCollectingClient.newDecorator(RpcMetricLabels.grpcRequestLabeler("grpc_clients"))).decorator(BraveClient.newDecorator(tracing)).decorator(loggingClient);
}
Also used : HealthCheckedEndpointGroup(com.linecorp.armeria.client.endpoint.healthcheck.HealthCheckedEndpointGroup) SessionProtocol(com.linecorp.armeria.common.SessionProtocol) DnsNameResolverBuilder(io.netty.resolver.dns.DnsNameResolverBuilder) ResourceUtil(org.curioswitch.common.server.framework.util.ResourceUtil) BraveClient(com.linecorp.armeria.client.brave.BraveClient) Singleton(javax.inject.Singleton) Function(java.util.function.Function) Inject(javax.inject.Inject) InsecureTrustManagerFactory(io.netty.handler.ssl.util.InsecureTrustManagerFactory) EventLoopGroups(com.linecorp.armeria.common.util.EventLoopGroups) RpcMetricLabels(org.curioswitch.common.server.framework.monitoring.RpcMetricLabels) Duration(java.time.Duration) Clients(com.linecorp.armeria.client.Clients) ClientBuilder(com.linecorp.armeria.client.ClientBuilder) URI(java.net.URI) ClientFactoryBuilder(com.linecorp.armeria.client.ClientFactoryBuilder) Tracing(brave.Tracing) DnsAddressEndpointGroup(com.linecorp.armeria.client.endpoint.dns.DnsAddressEndpointGroup) ClientFactory(com.linecorp.armeria.client.ClientFactory) TrustManagerFactory(javax.net.ssl.TrustManagerFactory) SelfSignedCertificate(io.netty.handler.ssl.util.SelfSignedCertificate) MetricCollectingClient(com.linecorp.armeria.client.metric.MetricCollectingClient) MoreObjects(com.google.common.base.MoreObjects) EndpointGroup(com.linecorp.armeria.client.endpoint.EndpointGroup) Endpoint(com.linecorp.armeria.client.Endpoint) DnsServerAddressStreamProviders(io.netty.resolver.dns.DnsServerAddressStreamProviders) Collectors(java.util.stream.Collectors) LoggingClient(com.linecorp.armeria.client.logging.LoggingClient) Consumer(java.util.function.Consumer) Logger(org.apache.logging.log4j.Logger) ServerConfig(org.curioswitch.common.server.framework.config.ServerConfig) HttpClient(com.linecorp.armeria.client.HttpClient) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) SslContextBuilder(io.netty.handler.ssl.SslContextBuilder) Optional(java.util.Optional) DnsAddressResolverGroup(io.netty.resolver.dns.DnsAddressResolverGroup) LogManager(org.apache.logging.log4j.LogManager) HealthCheckedEndpointGroup(com.linecorp.armeria.client.endpoint.healthcheck.HealthCheckedEndpointGroup) HealthCheckedEndpointGroup(com.linecorp.armeria.client.endpoint.healthcheck.HealthCheckedEndpointGroup) DnsAddressEndpointGroup(com.linecorp.armeria.client.endpoint.dns.DnsAddressEndpointGroup) EndpointGroup(com.linecorp.armeria.client.endpoint.EndpointGroup) URI(java.net.URI) DnsAddressEndpointGroup(com.linecorp.armeria.client.endpoint.dns.DnsAddressEndpointGroup) ClientBuilder(com.linecorp.armeria.client.ClientBuilder)

Example 2 with Endpoint

use of com.linecorp.armeria.client.Endpoint in project zipkin by openzipkin.

the class InitialEndpointSupplier method get.

@Override
public EndpointGroup get() {
    List<EndpointGroup> endpointGroups = new ArrayList<>();
    for (String hostText : hosts.split(",", 100)) {
        // possibly extra comma
        if ("".equals(hostText))
            continue;
        URI url;
        if (hostText.startsWith("http://") || hostText.startsWith("https://")) {
            url = URI.create(hostText);
        } else if (!sessionProtocol.isTls() && hostText.indexOf(':') == -1) {
            url = URI.create(sessionProtocol.uriText() + "://" + hostText + ":9200");
        } else {
            url = URI.create(sessionProtocol.uriText() + "://" + hostText);
        }
        String host = url.getHost();
        if (host == null) {
            LOGGER.warn("Skipping invalid ES host {}", url);
            continue;
        }
        int port = getPort(url);
        if (port == 9300) {
            LOGGER.warn("Native transport no longer supported. Changing {} to http port 9200", host);
            port = 9200;
        }
        if (isIpAddress(host) || host.equals("localhost")) {
            endpointGroups.add(EndpointGroup.of(Endpoint.of(host, port)));
        } else {
            // A host that isn't an IP may resolve to multiple IP addresses, so we use a endpoint
            // group to round-robin over them. Users can mix addresses that resolve to multiple IPs
            // with single IPs freely, they'll all get used.
            endpointGroups.add(DnsAddressEndpointGroup.builder(host).port(port).build());
        }
    }
    if (endpointGroups.isEmpty()) {
        throw new IllegalArgumentException("No valid endpoints found in ES hosts: " + hosts);
    }
    return EndpointGroup.of(endpointGroups);
}
Also used : DnsAddressEndpointGroup(com.linecorp.armeria.client.endpoint.dns.DnsAddressEndpointGroup) EndpointGroup(com.linecorp.armeria.client.endpoint.EndpointGroup) ArrayList(java.util.ArrayList) URI(java.net.URI) Endpoint(com.linecorp.armeria.client.Endpoint)

Aggregations

Endpoint (com.linecorp.armeria.client.Endpoint)2 EndpointGroup (com.linecorp.armeria.client.endpoint.EndpointGroup)2 DnsAddressEndpointGroup (com.linecorp.armeria.client.endpoint.dns.DnsAddressEndpointGroup)2 URI (java.net.URI)2 Tracing (brave.Tracing)1 MoreObjects (com.google.common.base.MoreObjects)1 ClientBuilder (com.linecorp.armeria.client.ClientBuilder)1 ClientFactory (com.linecorp.armeria.client.ClientFactory)1 ClientFactoryBuilder (com.linecorp.armeria.client.ClientFactoryBuilder)1 Clients (com.linecorp.armeria.client.Clients)1 HttpClient (com.linecorp.armeria.client.HttpClient)1 BraveClient (com.linecorp.armeria.client.brave.BraveClient)1 HealthCheckedEndpointGroup (com.linecorp.armeria.client.endpoint.healthcheck.HealthCheckedEndpointGroup)1 LoggingClient (com.linecorp.armeria.client.logging.LoggingClient)1 MetricCollectingClient (com.linecorp.armeria.client.metric.MetricCollectingClient)1 SessionProtocol (com.linecorp.armeria.common.SessionProtocol)1 EventLoopGroups (com.linecorp.armeria.common.util.EventLoopGroups)1 MeterRegistry (io.micrometer.core.instrument.MeterRegistry)1 SslContextBuilder (io.netty.handler.ssl.SslContextBuilder)1 InsecureTrustManagerFactory (io.netty.handler.ssl.util.InsecureTrustManagerFactory)1