Search in sources :

Example 1 with ServiceMessageCodec

use of io.scalecube.services.transport.api.ServiceMessageCodec 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)

Example 2 with ServiceMessageCodec

use of io.scalecube.services.transport.api.ServiceMessageCodec in project scalecube by scalecube.

the class StreamingServiceTest method setup.

@BeforeAll
public static void setup() {
    gateway = Microservices.builder().discovery(serviceEndpoint -> new ScalecubeServiceDiscovery().transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())).options(opts -> opts.metadata(serviceEndpoint))).transport(RSocketServiceTransport::new).defaultDataDecoder(ServiceMessageCodec::decodeData).startAwait();
    final Address gatewayAddress = gateway.discovery().address();
    node = Microservices.builder().discovery(endpoint -> new ScalecubeServiceDiscovery().transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())).options(opts -> opts.metadata(endpoint)).membership(cfg -> cfg.seedMembers(gatewayAddress))).transport(RSocketServiceTransport::new).defaultDataDecoder(ServiceMessageCodec::decodeData).services(new SimpleQuoteService()).startAwait();
}
Also used : Assertions.fail(org.junit.jupiter.api.Assertions.fail) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) ScalecubeServiceDiscovery(io.scalecube.services.discovery.ScalecubeServiceDiscovery) Disposable(reactor.core.Disposable) SimpleQuoteService(io.scalecube.services.sut.SimpleQuoteService) RSocketServiceTransport(io.scalecube.services.transport.rsocket.RSocketServiceTransport) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) ServiceMessageCodec(io.scalecube.services.transport.api.ServiceMessageCodec) BeforeAll(org.junit.jupiter.api.BeforeAll) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Duration(java.time.Duration) QuoteService(io.scalecube.services.sut.QuoteService) WebsocketTransportFactory(io.scalecube.transport.netty.websocket.WebsocketTransportFactory) ServiceMessage(io.scalecube.services.api.ServiceMessage) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Address(io.scalecube.net.Address) ScalecubeServiceDiscovery(io.scalecube.services.discovery.ScalecubeServiceDiscovery) Address(io.scalecube.net.Address) WebsocketTransportFactory(io.scalecube.transport.netty.websocket.WebsocketTransportFactory) SimpleQuoteService(io.scalecube.services.sut.SimpleQuoteService) ServiceMessageCodec(io.scalecube.services.transport.api.ServiceMessageCodec) RSocketServiceTransport(io.scalecube.services.transport.rsocket.RSocketServiceTransport) BeforeAll(org.junit.jupiter.api.BeforeAll)

Aggregations

Address (io.scalecube.net.Address)2 ServiceMessageCodec (io.scalecube.services.transport.api.ServiceMessageCodec)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 ServiceReference (io.scalecube.services.ServiceReference)1 ServiceMessage (io.scalecube.services.api.ServiceMessage)1 CredentialsSupplier (io.scalecube.services.auth.CredentialsSupplier)1 ScalecubeServiceDiscovery (io.scalecube.services.discovery.ScalecubeServiceDiscovery)1 MessageCodecException (io.scalecube.services.exceptions.MessageCodecException)1 ServiceException (io.scalecube.services.exceptions.ServiceException)1 UnauthorizedException (io.scalecube.services.exceptions.UnauthorizedException)1 QuoteService (io.scalecube.services.sut.QuoteService)1 SimpleQuoteService (io.scalecube.services.sut.SimpleQuoteService)1 ClientChannel (io.scalecube.services.transport.api.ClientChannel)1