Search in sources :

Example 6 with URIEndpointObject

use of io.servicecomb.foundation.common.net.URIEndpointObject in project java-chassis by ServiceComb.

the class CseDiscoveryClient method getInstances.

@Override
public List<ServiceInstance> getInstances(final String serviceId) {
    List<ServiceInstance> instances = new ArrayList<ServiceInstance>();
    ServiceRegistryClient client = RegistryClientFactory.getRegistryClient();
    String appId = DynamicPropertyFactory.getInstance().getStringProperty("APPLICATION_ID", "default").get();
    ReferenceConfig referenceConfig = consumerProviderManager.getReferenceConfig(serviceId);
    String versionRule = referenceConfig.getMicroserviceVersionRule();
    String cseServiceID = client.getMicroserviceId(appId, serviceId, versionRule);
    List<MicroserviceInstance> cseServices = client.getMicroserviceInstance(cseServiceID, cseServiceID);
    if (null != cseServices && !cseServices.isEmpty()) {
        for (MicroserviceInstance instance : cseServices) {
            List<String> eps = instance.getEndpoints();
            for (String ep : eps) {
                URIEndpointObject uri = new URIEndpointObject(ep);
                instances.add(new DefaultServiceInstance(instance.getServiceId(), uri.getHostOrIp(), uri.getPort(), false));
            }
        }
    }
    return instances;
}
Also used : DefaultServiceInstance(org.springframework.cloud.client.DefaultServiceInstance) ArrayList(java.util.ArrayList) DefaultServiceInstance(org.springframework.cloud.client.DefaultServiceInstance) ServiceInstance(org.springframework.cloud.client.ServiceInstance) MicroserviceInstance(io.servicecomb.serviceregistry.api.registry.MicroserviceInstance) ServiceRegistryClient(io.servicecomb.serviceregistry.client.ServiceRegistryClient) URIEndpointObject(io.servicecomb.foundation.common.net.URIEndpointObject)

Example 7 with URIEndpointObject

use of io.servicecomb.foundation.common.net.URIEndpointObject in project java-chassis by ServiceComb.

the class IpPortManager method get.

public IpPort get() {
    List<CacheEndpoint> addresses = getAddressCaches();
    if (addresses == null || addresses.size() == 0) {
        return getDefaultIpPort();
    }
    synchronized (lockObj) {
        int id = indexForAuto.get();
        addressCanUsed.putIfAbsent(id, true);
        return new URIEndpointObject(addresses.get(id).getEndpoint());
    }
}
Also used : CacheEndpoint(io.servicecomb.serviceregistry.cache.CacheEndpoint) URIEndpointObject(io.servicecomb.foundation.common.net.URIEndpointObject) CacheEndpoint(io.servicecomb.serviceregistry.cache.CacheEndpoint)

Example 8 with URIEndpointObject

use of io.servicecomb.foundation.common.net.URIEndpointObject in project java-chassis by ServiceComb.

the class IpPortManager method next.

public IpPort next() {
    List<CacheEndpoint> addresses = getAddressCaches();
    if ((addresses == null || addresses.size() == 0)) {
        return nextDefaultIpPort();
    }
    synchronized (lockObj) {
        int id = indexForAuto.get();
        // 重置可用的地址为false
        if (addressCanUsed.get(id) != null && addressCanUsed.get(id)) {
            addressCanUsed.put(id, false);
            if (id == addresses.size() - 1) {
                indexForAuto.set(0);
                // 重新轮询
                addressCanUsed.clear();
                LOGGER.warn("service center has no available instance");
                return null;
            } else {
                indexForAuto.getAndIncrement();
            }
            LOGGER.warn("service center instance {} is unreachable, try another instance {}", addresses.get(id).getEndpoint(), addresses.get(indexForAuto.get()).getEndpoint());
        }
        return new URIEndpointObject(addresses.get(indexForAuto.get()).getEndpoint());
    }
}
Also used : CacheEndpoint(io.servicecomb.serviceregistry.cache.CacheEndpoint) URIEndpointObject(io.servicecomb.foundation.common.net.URIEndpointObject) CacheEndpoint(io.servicecomb.serviceregistry.cache.CacheEndpoint)

Example 9 with URIEndpointObject

use of io.servicecomb.foundation.common.net.URIEndpointObject in project java-chassis by ServiceComb.

the class ServletRestTransport method send.

@Override
public void send(Invocation invocation, AsyncResponse asyncResp) throws Exception {
    URIEndpointObject endpoint = (URIEndpointObject) invocation.getEndpoint().getAddress();
    RestTransportClient client = RestTransportClientManager.INSTANCE.getRestTransportClient(endpoint.isSslEnabled());
    client.send(invocation, asyncResp);
}
Also used : RestTransportClient(io.servicecomb.transport.rest.client.RestTransportClient) URIEndpointObject(io.servicecomb.foundation.common.net.URIEndpointObject)

Example 10 with URIEndpointObject

use of io.servicecomb.foundation.common.net.URIEndpointObject in project java-chassis by ServiceComb.

the class HighwayTransport method send.

@Override
public void send(Invocation invocation, AsyncResponse asyncResp) throws Exception {
    URIEndpointObject endpoint = (URIEndpointObject) invocation.getEndpoint().getAddress();
    HighwayClient client = HighwayClientManager.INSTANCE.getHighwayClient(endpoint.isSslEnabled());
    client.send(invocation, asyncResp);
}
Also used : URIEndpointObject(io.servicecomb.foundation.common.net.URIEndpointObject)

Aggregations

URIEndpointObject (io.servicecomb.foundation.common.net.URIEndpointObject)15 Test (org.junit.Test)8 Endpoint (io.servicecomb.core.Endpoint)6 Expectations (mockit.Expectations)5 AsyncResponse (io.servicecomb.core.AsyncResponse)2 Invocation (io.servicecomb.core.Invocation)2 CacheEndpoint (io.servicecomb.serviceregistry.cache.CacheEndpoint)2 RestTransportClient (io.servicecomb.transport.rest.client.RestTransportClient)2 OperationProtobuf (io.servicecomb.codec.protobuf.definition.OperationProtobuf)1 WrapSchema (io.servicecomb.codec.protobuf.utils.WrapSchema)1 OperationMeta (io.servicecomb.core.definition.OperationMeta)1 TcpServer (io.servicecomb.foundation.vertx.server.TcpServer)1 MicroserviceInstance (io.servicecomb.serviceregistry.api.registry.MicroserviceInstance)1 ServiceRegistryClient (io.servicecomb.serviceregistry.client.ServiceRegistryClient)1 ArrayList (java.util.ArrayList)1 DefaultServiceInstance (org.springframework.cloud.client.DefaultServiceInstance)1 ServiceInstance (org.springframework.cloud.client.ServiceInstance)1