Search in sources :

Example 1 with RSocketConnector

use of io.rsocket.core.RSocketConnector in project spring-framework by spring-projects.

the class DefaultRSocketRequesterBuilder method transports.

@Override
public RSocketRequester transports(Publisher<List<LoadbalanceTarget>> targetPublisher, LoadbalanceStrategy loadbalanceStrategy) {
    RSocketStrategies strategies = getRSocketStrategies();
    MimeType metaMimeType = getMetadataMimeType();
    MimeType dataMimeType = getDataMimeType(strategies);
    RSocketConnector connector = initConnector(this.rsocketConnectorConfigurers, metaMimeType, dataMimeType, strategies);
    LoadbalanceRSocketClient client = LoadbalanceRSocketClient.builder(targetPublisher).connector(connector).loadbalanceStrategy(loadbalanceStrategy).build();
    return new DefaultRSocketRequester(client, null, dataMimeType, metaMimeType, strategies);
}
Also used : RSocketConnector(io.rsocket.core.RSocketConnector) LoadbalanceRSocketClient(io.rsocket.loadbalance.LoadbalanceRSocketClient) MimeType(org.springframework.util.MimeType) WellKnownMimeType(io.rsocket.metadata.WellKnownMimeType)

Example 2 with RSocketConnector

use of io.rsocket.core.RSocketConnector in project spring-framework by spring-projects.

the class DefaultRSocketRequesterBuilder method transport.

@Override
public RSocketRequester transport(ClientTransport transport) {
    RSocketStrategies strategies = getRSocketStrategies();
    MimeType metaMimeType = getMetadataMimeType();
    MimeType dataMimeType = getDataMimeType(strategies);
    RSocketConnector connector = initConnector(this.rsocketConnectorConfigurers, metaMimeType, dataMimeType, strategies);
    RSocketClient client = RSocketClient.from(connector.connect(transport));
    return new DefaultRSocketRequester(client, null, dataMimeType, metaMimeType, strategies);
}
Also used : RSocketConnector(io.rsocket.core.RSocketConnector) LoadbalanceRSocketClient(io.rsocket.loadbalance.LoadbalanceRSocketClient) RSocketClient(io.rsocket.core.RSocketClient) MimeType(org.springframework.util.MimeType) WellKnownMimeType(io.rsocket.metadata.WellKnownMimeType)

Example 3 with RSocketConnector

use of io.rsocket.core.RSocketConnector in project spring-framework by spring-projects.

the class DefaultRSocketRequesterBuilder method initConnector.

@SuppressWarnings("deprecation")
private RSocketConnector initConnector(List<RSocketConnectorConfigurer> connectorConfigurers, MimeType metaMimeType, MimeType dataMimeType, RSocketStrategies rsocketStrategies) {
    RSocketConnector connector = RSocketConnector.create();
    connectorConfigurers.forEach(c -> c.configure(connector));
    if (rsocketStrategies.dataBufferFactory() instanceof NettyDataBufferFactory) {
        connector.payloadDecoder(PayloadDecoder.ZERO_COPY);
    }
    connector.metadataMimeType(metaMimeType.toString());
    connector.dataMimeType(dataMimeType.toString());
    Mono<Payload> setupPayloadMono = getSetupPayload(dataMimeType, metaMimeType, rsocketStrategies);
    if (setupPayloadMono != EMPTY_SETUP_PAYLOAD) {
        connector.setupPayload(setupPayloadMono);
    }
    return connector;
}
Also used : RSocketConnector(io.rsocket.core.RSocketConnector) DefaultPayload(io.rsocket.util.DefaultPayload) Payload(io.rsocket.Payload) NettyDataBufferFactory(org.springframework.core.io.buffer.NettyDataBufferFactory)

Example 4 with RSocketConnector

use of io.rsocket.core.RSocketConnector in project spring-framework by spring-projects.

the class DefaultRSocketRequesterBuilderTests method mimeTypesCannotBeChangedAtRSocketConnectorLevel.

@Test
public void mimeTypesCannotBeChangedAtRSocketConnectorLevel() {
    MimeType dataMimeType = MimeTypeUtils.APPLICATION_JSON;
    MimeType metaMimeType = MimeTypeUtils.parseMimeType(WellKnownMimeType.MESSAGE_RSOCKET_ROUTING.getString());
    RSocketRequester requester = RSocketRequester.builder().metadataMimeType(metaMimeType).dataMimeType(dataMimeType).rsocketConnector(connector -> {
        connector.metadataMimeType("text/plain");
        connector.dataMimeType("application/xml");
    }).transport(this.transport);
    ConnectionSetupPayload setupPayload = getConnectionSetupPayload(requester);
    assertThat(setupPayload.dataMimeType()).isEqualTo(dataMimeType.toString());
    assertThat(setupPayload.metadataMimeType()).isEqualTo(metaMimeType.toString());
    assertThat(requester.dataMimeType()).isEqualTo(dataMimeType);
    assertThat(requester.metadataMimeType()).isEqualTo(metaMimeType);
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ClientTransport(io.rsocket.transport.ClientTransport) BeforeEach(org.junit.jupiter.api.BeforeEach) NettyDataBufferFactory(org.springframework.core.io.buffer.NettyDataBufferFactory) SocketAddress(java.net.SocketAddress) Decoder(org.springframework.core.codec.Decoder) DefaultDataBufferFactory(org.springframework.core.io.buffer.DefaultDataBufferFactory) ByteBufAllocator(io.netty.buffer.ByteBufAllocator) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) DefaultConnectionSetupPayload(io.rsocket.core.DefaultConnectionSetupPayload) DecodingException(org.springframework.core.codec.DecodingException) RSocketErrorException(io.rsocket.RSocketErrorException) PayloadDecoder(io.rsocket.frame.decoder.PayloadDecoder) MimeType(org.springframework.util.MimeType) WellKnownMimeType(io.rsocket.metadata.WellKnownMimeType) ByteBuf(io.netty.buffer.ByteBuf) BDDMockito.given(org.mockito.BDDMockito.given) Duration(java.time.Duration) Map(java.util.Map) ResolvableType(org.springframework.core.ResolvableType) RSocketConnector(io.rsocket.core.RSocketConnector) StringDecoder(org.springframework.core.codec.StringDecoder) Publisher(org.reactivestreams.Publisher) Mono(reactor.core.publisher.Mono) MimeTypeUtils(org.springframework.util.MimeTypeUtils) Field(java.lang.reflect.Field) DataBuffer(org.springframework.core.io.buffer.DataBuffer) InetSocketAddress(java.net.InetSocketAddress) Mockito.verify(org.mockito.Mockito.verify) Consumer(java.util.function.Consumer) Test(org.junit.jupiter.api.Test) Flux(reactor.core.publisher.Flux) List(java.util.List) DataBufferFactory(org.springframework.core.io.buffer.DataBufferFactory) ReflectionUtils(org.springframework.util.ReflectionUtils) DuplexConnection(io.rsocket.DuplexConnection) ConnectionSetupPayload(io.rsocket.ConnectionSetupPayload) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) DefaultConnectionSetupPayload(io.rsocket.core.DefaultConnectionSetupPayload) ConnectionSetupPayload(io.rsocket.ConnectionSetupPayload) MimeType(org.springframework.util.MimeType) WellKnownMimeType(io.rsocket.metadata.WellKnownMimeType) Test(org.junit.jupiter.api.Test)

Example 5 with RSocketConnector

use of io.rsocket.core.RSocketConnector in project spring-framework by spring-projects.

the class DefaultRSocketRequesterBuilderTests method testPayloadDecoder.

private void testPayloadDecoder(DataBufferFactory bufferFactory, PayloadDecoder payloadDecoder) throws NoSuchFieldException {
    RSocketStrategies strategies = RSocketStrategies.builder().dataBufferFactory(bufferFactory).build();
    RSocketRequester.builder().rsocketStrategies(strategies).rsocketConnector(this.connectorConfigurer).transport(this.transport);
    RSocketConnector connector = this.connectorConfigurer.connector();
    assertThat(connector).isNotNull();
    Field field = RSocketConnector.class.getDeclaredField("payloadDecoder");
    ReflectionUtils.makeAccessible(field);
    PayloadDecoder decoder = (PayloadDecoder) ReflectionUtils.getField(field, connector);
    assertThat(decoder).isSameAs(payloadDecoder);
}
Also used : Field(java.lang.reflect.Field) RSocketConnector(io.rsocket.core.RSocketConnector) PayloadDecoder(io.rsocket.frame.decoder.PayloadDecoder)

Aggregations

RSocketConnector (io.rsocket.core.RSocketConnector)6 WellKnownMimeType (io.rsocket.metadata.WellKnownMimeType)4 MimeType (org.springframework.util.MimeType)4 PayloadDecoder (io.rsocket.frame.decoder.PayloadDecoder)2 LoadbalanceRSocketClient (io.rsocket.loadbalance.LoadbalanceRSocketClient)2 Field (java.lang.reflect.Field)2 NettyDataBufferFactory (org.springframework.core.io.buffer.NettyDataBufferFactory)2 ByteBuf (io.netty.buffer.ByteBuf)1 ByteBufAllocator (io.netty.buffer.ByteBufAllocator)1 ConnectionSetupPayload (io.rsocket.ConnectionSetupPayload)1 DuplexConnection (io.rsocket.DuplexConnection)1 Payload (io.rsocket.Payload)1 RSocketErrorException (io.rsocket.RSocketErrorException)1 DefaultConnectionSetupPayload (io.rsocket.core.DefaultConnectionSetupPayload)1 RSocketClient (io.rsocket.core.RSocketClient)1 ClientTransport (io.rsocket.transport.ClientTransport)1 DefaultPayload (io.rsocket.util.DefaultPayload)1 InetSocketAddress (java.net.InetSocketAddress)1 SocketAddress (java.net.SocketAddress)1 Duration (java.time.Duration)1