Search in sources :

Example 1 with ServiceReference

use of io.scalecube.services.ServiceReference in project scalecube by scalecube.

the class RoutersTest method tesTagsFromAnnotation.

@Test
public void tesTagsFromAnnotation() {
    ServiceCall serviceCall = provider3.call().router((req, mes) -> {
        ServiceReference tagServiceRef = req.listServiceReferences().get(0);
        Map<String, String> tags = tagServiceRef.tags();
        assertEquals(new HashSet<>(asList("tagA", "tagB", "tagC", "methodTagA")), tags.keySet());
        assertEquals("a", tags.get("tagA"));
        // user override this tag in Microservices#services
        assertEquals("bb", tags.get("tagB"));
        assertEquals("c", tags.get("tagC"));
        assertEquals("a", tags.get("methodTagA"));
        return Optional.of(tagServiceRef);
    });
    serviceCall.api(TagService.class).upperCase(Flux.just("hello")).blockLast();
}
Also used : ServiceCall(io.scalecube.services.ServiceCall) ServiceReference(io.scalecube.services.ServiceReference) Test(org.junit.jupiter.api.Test) BaseTest(io.scalecube.services.BaseTest)

Example 2 with ServiceReference

use of io.scalecube.services.ServiceReference in project scalecube by scalecube.

the class ServiceRegistryImpl method unregisterService.

@Override
public ServiceEndpoint unregisterService(String endpointId) {
    ServiceEndpoint serviceEndpoint = serviceEndpoints.remove(endpointId);
    if (serviceEndpoint != null) {
        LOGGER.debug("ServiceEndpoint unregistered: {}", serviceEndpoint);
        List<ServiceReference> serviceReferencesOfEndpoint = serviceReferencesByQualifier.values().stream().flatMap(Collection::stream).filter(sr -> sr.endpointId().equals(endpointId)).collect(Collectors.toList());
        serviceReferencesOfEndpoint.forEach(sr -> {
            computeServiceReferences(sr.qualifier(), sr);
            computeServiceReferences(sr.oldQualifier(), sr);
        });
    }
    return serviceEndpoint;
}
Also used : ServiceReference(io.scalecube.services.ServiceReference) Logger(org.slf4j.Logger) ServiceRegistry(io.scalecube.services.registry.api.ServiceRegistry) Collection(java.util.Collection) LoggerFactory(org.slf4j.LoggerFactory) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) ServiceEndpoint(io.scalecube.services.ServiceEndpoint) NonBlockingHashMap(org.jctools.maps.NonBlockingHashMap) List(java.util.List) Map(java.util.Map) ServiceMessage(io.scalecube.services.api.ServiceMessage) Collections(java.util.Collections) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Collection(java.util.Collection) ServiceEndpoint(io.scalecube.services.ServiceEndpoint) ServiceReference(io.scalecube.services.ServiceReference)

Example 3 with ServiceReference

use of io.scalecube.services.ServiceReference in project scalecube by scalecube.

the class RSocketClientTransport method create.

@Override
public ClientChannel create(ServiceReference serviceReference) {
    // keep reference for threadsafety
    final Map<Address, Mono<RSocket>> monoMap = rsockets.get();
    final Address address = serviceReference.address();
    Mono<RSocket> mono = monoMap.computeIfAbsent(address, key -> getCredentials(serviceReference).flatMap(creds -> connect(key, creds, monoMap)).cache().doOnError(ex -> monoMap.remove(key)));
    return new RSocketClientChannel(mono, new ServiceMessageCodec(headersCodec, dataCodecs));
}
Also used : ByteBufAllocator(io.netty.buffer.ByteBufAllocator) ReferenceCountUtil(io.scalecube.services.transport.api.ReferenceCountUtil) LoggerFactory(org.slf4j.LoggerFactory) PayloadDecoder(io.rsocket.frame.decoder.PayloadDecoder) ClientTransport(io.scalecube.services.transport.api.ClientTransport) MessageCodecException(io.scalecube.services.exceptions.MessageCodecException) ByteBuf(io.netty.buffer.ByteBuf) RSocket(io.rsocket.RSocket) Map(java.util.Map) ByteBufPayload(io.rsocket.util.ByteBufPayload) UnauthorizedException(io.scalecube.services.exceptions.UnauthorizedException) Address(io.scalecube.net.Address) ServiceReference(io.scalecube.services.ServiceReference) ServiceException(io.scalecube.services.exceptions.ServiceException) Logger(org.slf4j.Logger) MaskUtil(io.scalecube.utils.MaskUtil) RSocketConnector(io.rsocket.core.RSocketConnector) Collection(java.util.Collection) ClientChannel(io.scalecube.services.transport.api.ClientChannel) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Mono(reactor.core.publisher.Mono) ByteBufOutputStream(io.netty.buffer.ByteBufOutputStream) Payload(io.rsocket.Payload) CredentialsSupplier(io.scalecube.services.auth.CredentialsSupplier) ServiceMessageCodec(io.scalecube.services.transport.api.ServiceMessageCodec) DataCodec(io.scalecube.services.transport.api.DataCodec) Collections(java.util.Collections) HeadersCodec(io.scalecube.services.transport.api.HeadersCodec) Address(io.scalecube.net.Address) Mono(reactor.core.publisher.Mono) RSocket(io.rsocket.RSocket) ServiceMessageCodec(io.scalecube.services.transport.api.ServiceMessageCodec)

Aggregations

ServiceReference (io.scalecube.services.ServiceReference)3 Collection (java.util.Collection)2 Collections (java.util.Collections)2 Map (java.util.Map)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 ByteBuf (io.netty.buffer.ByteBuf)1 ByteBufAllocator (io.netty.buffer.ByteBufAllocator)1 ByteBufOutputStream (io.netty.buffer.ByteBufOutputStream)1 Payload (io.rsocket.Payload)1 RSocket (io.rsocket.RSocket)1 RSocketConnector (io.rsocket.core.RSocketConnector)1 PayloadDecoder (io.rsocket.frame.decoder.PayloadDecoder)1 ByteBufPayload (io.rsocket.util.ByteBufPayload)1 Address (io.scalecube.net.Address)1 BaseTest (io.scalecube.services.BaseTest)1 ServiceCall (io.scalecube.services.ServiceCall)1 ServiceEndpoint (io.scalecube.services.ServiceEndpoint)1 ServiceMessage (io.scalecube.services.api.ServiceMessage)1 CredentialsSupplier (io.scalecube.services.auth.CredentialsSupplier)1