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);
}
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);
}
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;
}
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);
}
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);
}
Aggregations