io.rsocket.RSocketFactory Java Examples
The following examples show how to use
io.rsocket.RSocketFactory.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultRSocketRequesterBuilder.java From spring-analysis-note with MIT License | 6 votes |
@Override public Mono<RSocketRequester> connect(ClientTransport transport) { return Mono.defer(() -> { RSocketStrategies strategies = getRSocketStrategies(); MimeType dataMimeType = getDefaultDataMimeType(strategies); RSocketFactory.ClientRSocketFactory factory = RSocketFactory.connect(); if (dataMimeType != null) { factory.dataMimeType(dataMimeType.toString()); } this.factoryConfigurers.forEach(configurer -> configurer.accept(factory)); return factory.transport(transport).start() .map(rsocket -> new DefaultRSocketRequester(rsocket, dataMimeType, strategies)); }); }
Example #2
Source File: RSocketBufferLeakTests.java From spring-analysis-note with MIT License | 6 votes |
@BeforeClass @SuppressWarnings("ConstantConditions") public static void setupOnce() { context = new AnnotationConfigApplicationContext(ServerConfig.class); server = RSocketFactory.receive() .frameDecoder(PayloadDecoder.ZERO_COPY) .addServerPlugin(payloadInterceptor) // intercept responding .acceptor(context.getBean(MessageHandlerAcceptor.class)) .transport(TcpServerTransport.create("localhost", 7000)) .start() .block(); requester = RSocketRequester.builder() .rsocketFactory(factory -> { factory.frameDecoder(PayloadDecoder.ZERO_COPY); factory.addClientPlugin(payloadInterceptor); // intercept outgoing requests }) .rsocketStrategies(context.getBean(RSocketStrategies.class)) .connectTcp("localhost", 7000) .block(); }
Example #3
Source File: ReservationClientApplication.java From bootiful-reactive-microservices with Apache License 2.0 | 6 votes |
public Flux<Reservation> getAllReservations() { return RSocketFactory .connect() .transport(this.localhost) .start() .flatMapMany(socket -> socket .requestStream(DefaultPayload.create(new byte[0])) .map(Payload::getDataUtf8) .map(obj -> { try { return this.objectMapper .readValue(obj, Reservation.class); } catch (IOException e) { throw new RuntimeException(e); } }) .doFinally(signal -> socket.dispose()) ); }
Example #4
Source File: RSocketServerToClientIntegrationTests.java From spring-analysis-note with MIT License | 6 votes |
private static void connectAndVerify(String destination) { ServerController serverController = context.getBean(ServerController.class); serverController.reset(); RSocket rsocket = null; try { rsocket = RSocketFactory.connect() .setupPayload(DefaultPayload.create("", destination)) .dataMimeType("text/plain") .frameDecoder(PayloadDecoder.ZERO_COPY) .acceptor(context.getBean("clientAcceptor", MessageHandlerAcceptor.class)) .transport(TcpClientTransport.create("localhost", 7000)) .start() .block(); serverController.await(Duration.ofSeconds(5)); } finally { if (rsocket != null) { rsocket.dispose(); } } }
Example #5
Source File: ReservationServiceApplication.java From bootiful-reactive-microservices with Apache License 2.0 | 6 votes |
@EventListener(ApplicationReadyEvent.class) public void serve() throws Exception { var abstractRSocket = new AbstractRSocket() { @Override public Flux<Payload> requestStream(Payload payload) { return reservationRepository.findAll() .map(RsocketServer.this::toJson) .map(DefaultPayload::create); } }; SocketAcceptor socketAcceptor = (connectionSetupPayload, rSocket) -> Mono.just(abstractRSocket); RSocketFactory .receive() .acceptor(socketAcceptor) .transport(this.tcp) .start() .subscribe(); }
Example #6
Source File: RSocketClientToServerIntegrationTests.java From spring-analysis-note with MIT License | 6 votes |
@BeforeClass @SuppressWarnings("ConstantConditions") public static void setupOnce() { context = new AnnotationConfigApplicationContext(ServerConfig.class); server = RSocketFactory.receive() .addServerPlugin(interceptor) .frameDecoder(PayloadDecoder.ZERO_COPY) .acceptor(context.getBean(MessageHandlerAcceptor.class)) .transport(TcpServerTransport.create("localhost", 7000)) .start() .block(); requester = RSocketRequester.builder() .rsocketFactory(factory -> factory.frameDecoder(PayloadDecoder.ZERO_COPY)) .rsocketStrategies(context.getBean(RSocketStrategies.class)) .connectTcp("localhost", 7000) .block(); }
Example #7
Source File: DemoApplication.java From spring-boot-rsocket with Apache License 2.0 | 6 votes |
public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args); RSocket rSocket = RSocketFactory.connect() .transport(WebsocketClientTransport.create( HttpClient.from(TcpClient.create() .host("localhost") .port(8080)), "/rsocket-rpc" )) .start() .block(); GreeterClient client = new GreeterClient(rSocket); client.streamGreet(HelloRequest.newBuilder().setName("Jon Doe").build()) .log() .blockLast(); client.requestGreet(HelloRequest.newBuilder().setName("Arthur Conan Doyle").build()) .log() .block(); }
Example #8
Source File: Rsc.java From rsc with Apache License 2.0 | 6 votes |
static Flux<?> run(Args args) { if (args.debug()) { configureDebugLevel("io.rsocket.FrameLogger"); } args.log().ifPresent(Rsc::configureDebugLevel); final ClientTransport clientTransport = args.clientTransport(); final RSocketFactory.ClientRSocketFactory factory = RSocketFactory.connect(); args.resume().ifPresent(duration -> factory.resume().resumeSessionDuration(duration) .resumeStrategy(() -> new PeriodicResumeStrategy(Duration.ofSeconds(5)))); args.setup().map(DefaultPayload::create).ifPresent(factory::setupPayload); return factory // .frameDecoder(PayloadDecoder.ZERO_COPY) // .metadataMimeType(args.composeMetadata().getT1()) // .dataMimeType(args.dataMimeType()) // .transport(clientTransport) // .start() // .flatMapMany(rsocket -> args.interactionModel().request(rsocket, args)); }
Example #9
Source File: DemoApplication.java From spring-boot-rsocket with Apache License 2.0 | 6 votes |
public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args); RSocket rSocket = RSocketFactory.connect() .transport(WebsocketClientTransport.create( HttpClient.from(TcpClient.create() .host("localhost") .port(8080)), "/rsocket" )) .start() .block(); logger.info( rSocket.requestResponse(DefaultPayload.create("HelloWorld")) .map(Payload::getDataUtf8) .block() ); }
Example #10
Source File: PingPongApp.java From spring-cloud-rsocket with Apache License 2.0 | 6 votes |
@Override public void onApplicationEvent(ApplicationReadyEvent event) { ConfigurableEnvironment env = event.getApplicationContext().getEnvironment(); Integer pongDelay = env.getProperty("pong.delay", Integer.class, 5000); try { Thread.sleep(pongDelay); } catch (InterruptedException e) { e.printStackTrace(); } log.info("Starting Pong"); Integer gatewayPort = env.getProperty("spring.rsocket.server.port", Integer.class, 7002); MicrometerRSocketInterceptor interceptor = new MicrometerRSocketInterceptor( meterRegistry, Tag.of("component", "pong")); ByteBuf announcementMetadata = getRouteSetupMetadata(strategies, "pong", 3L); RSocketFactory.connect().metadataMimeType(COMPOSITE_MIME_TYPE.toString()) .setupPayload( DefaultPayload.create(EMPTY_BUFFER, announcementMetadata)) .addRequesterPlugin(interceptor).acceptor(this::accept) .transport(TcpClientTransport.create(gatewayPort)) // proxy .start().block(); }
Example #11
Source File: RSocketNettyReactiveWebServerFactory.java From spring-boot-rsocket with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") private RSocketFactory.Start<CloseableChannel> createRSocketStarter(HttpHandler httpHandler) { RSocketFactory.ServerRSocketFactory rSocketFactory = applyCustomizers(RSocketFactory.receive()); HttpServer httpServer = createHttpServer(); ReactorHttpHandlerAdapter handlerAdapter = new ReactorHttpHandlerAdapter(httpHandler); return rSocketFactory .acceptor(socketAcceptor) .transport((ServerTransport) new WebsocketRouteTransport( httpServer, r -> r.route(hsr -> !("/" + hsr.path()).equals(path), handlerAdapter), path )); }
Example #12
Source File: RSocketRpcServer.java From rpc-thunderdome with Apache License 2.0 | 6 votes |
public static void main(String... args) { String host = System.getProperty("host", "127.0.0.1"); int port = Integer.getInteger("port", 8001); RSocketFactory.receive() .frameDecoder(Frame::retain) .acceptor( (setup, sendingSocket) -> Mono.just( new SimpleServiceServer( new DefaultService(), Optional.empty(), Optional.empty()))) .transport(TcpServerTransport.create(host, port)) .start() .block() .onClose() .doOnSubscribe(s -> logger.info("server started")) .block(); }
Example #13
Source File: ReactiveSocketServer.java From spring-cloud-sockets with Apache License 2.0 | 6 votes |
@Override public void start() { try{ this.lifecycleMonitor.lock(); if(!running){ logger.info("Starting RSocket server using transport: {} ", this.transport.getClass().getName()); this.disposable = RSocketFactory.receive() .acceptor(acceptor) .transport(transport) .start() .subscribe(); running = true; } }finally { lifecycleMonitor.unlock(); } }
Example #14
Source File: Server.java From rpc-benchmark with Apache License 2.0 | 5 votes |
public static void main(String[] args){ UserServiceServer userServiceServer = new UserServiceServer(new UserServiceRsocketServerImpl(), Optional.empty(), Optional.empty()); CloseableChannel closeableChannel = RSocketFactory.receive() .acceptor( (setup, sendingSocket) -> Mono.just(new RequestHandlingRSocket(userServiceServer))) .transport(TcpServerTransport.create(8080)) .start() .block(); // Block so we don't exit closeableChannel.onClose().block(); }
Example #15
Source File: ReservationServiceApplication.java From bootiful-reactive-microservices with Apache License 2.0 | 5 votes |
@Override public void onApplicationEvent(ApplicationReadyEvent event) { SocketAcceptor sa = (connectionSetupPayload, rSocket) -> Mono.just(new AbstractRSocket() { @Override public Flux<Payload> requestStream(Payload payload) { return reservationRepository .findAll() .map(x -> { try { return mapper.writeValueAsString(x); } catch (JsonProcessingException e) { throw new RuntimeException(e); } }) .map(DefaultPayload::create); } }); RSocketFactory .receive() .acceptor(sa) .transport(TcpServerTransport.create("localhost", 7000)) .start() .onTerminateDetach() .subscribe(); }
Example #16
Source File: RsocketClientApplication.java From bootiful-reactive-microservices with Apache License 2.0 | 5 votes |
@Bean RSocket rSocket() { return RSocketFactory .connect() .frameDecoder(PayloadDecoder.ZERO_COPY) .dataMimeType(MimeTypeUtils.APPLICATION_JSON_VALUE) .transport(TcpClientTransport.create(7000)) .start() .block(); }
Example #17
Source File: RSocketConfiguration.java From liiklus with MIT License | 5 votes |
@Override public void initialize(GenericApplicationContext applicationContext) { var environment = applicationContext.getEnvironment(); if (!environment.acceptsProfiles(Profiles.of("gateway"))) { return; } var serverProperties = PropertiesUtil.bind(environment, new RSocketServerProperties()); if (!serverProperties.isEnabled()) { return; } applicationContext.registerBean(RSocketLiiklusService.class); applicationContext.registerBean( CloseableChannel.class, () -> { var liiklusService = applicationContext.getBean(LiiklusService.class); return RSocketFactory.receive() .acceptor((setup, sendingSocket) -> Mono.just(new RequestHandlingRSocket(new LiiklusServiceServer(liiklusService, Optional.empty(), Optional.empty())))) .transport(TcpServerTransport.create(serverProperties.getHost(), serverProperties.getPort())) .start() .block(); }, it -> { it.setDestroyMethodName("dispose"); } ); }
Example #18
Source File: Server.java From tutorials with MIT License | 5 votes |
public Server() { this.server = RSocketFactory.receive() .acceptor((setupPayload, reactiveSocket) -> Mono.just(new RSocketImpl())) .transport(TcpServerTransport.create("localhost", TCP_PORT)) .start() .doOnNext(x -> LOG.info("Server started")) .subscribe(); this.gameController = new GameController("Server Player"); }
Example #19
Source File: ChannelClient.java From tutorials with MIT License | 5 votes |
public ChannelClient() { this.socket = RSocketFactory.connect() .transport(TcpClientTransport.create("localhost", TCP_PORT)) .start() .block(); this.gameController = new GameController("Client Player"); }
Example #20
Source File: FireNForgetClient.java From tutorials with MIT License | 5 votes |
public FireNForgetClient() { this.socket = RSocketFactory.connect() .transport(TcpClientTransport.create("localhost", TCP_PORT)) .start() .block(); this.data = Collections.unmodifiableList(generateData()); }
Example #21
Source File: ClientConfiguration.java From tutorials with MIT License | 5 votes |
@Bean public RSocket rSocket() { return RSocketFactory.connect() .mimeType(MimeTypeUtils.APPLICATION_JSON_VALUE, MimeTypeUtils.APPLICATION_JSON_VALUE) .frameDecoder(PayloadDecoder.ZERO_COPY) .transport(TcpClientTransport.create(7000)) .start() .block(); }
Example #22
Source File: MarketDataRSocketControllerLiveTest.java From tutorials with MIT License | 5 votes |
@Bean @Lazy public RSocket rSocket() { return RSocketFactory.connect() .mimeType(MimeTypeUtils.APPLICATION_JSON_VALUE, MimeTypeUtils.APPLICATION_JSON_VALUE) .frameDecoder(PayloadDecoder.ZERO_COPY) .transport(TcpClientTransport.create(7000)) .start() .block(); }
Example #23
Source File: ReservationClientApplication.java From bootiful-reactive-microservices with Apache License 2.0 | 5 votes |
Flux<Reservation> getAllReservations() { return RSocketFactory .connect() .transport(this.tcpClientTransport) .start() .flatMapMany(rs -> rs.requestStream(DefaultPayload.create(new byte[0])) .map(Payload::getDataUtf8) .map(this::to) ); }
Example #24
Source File: PingPongApp.java From spring-cloud-rsocket with Apache License 2.0 | 5 votes |
@Override public void onApplicationEvent(ApplicationReadyEvent event) { log.info("Starting Ping" + id); ConfigurableEnvironment env = event.getApplicationContext().getEnvironment(); Integer take = env.getProperty("ping.take", Integer.class, null); Integer gatewayPort = env.getProperty("spring.rsocket.server.port", Integer.class, 7002); log.debug("ping.take: " + take); MicrometerRSocketInterceptor interceptor = new MicrometerRSocketInterceptor( meterRegistry, Tag.of("component", "ping")); ByteBuf metadata = getRouteSetupMetadata(strategies, "ping", id); Payload setupPayload = DefaultPayload.create(EMPTY_BUFFER, metadata); pongFlux = RSocketFactory.connect().frameDecoder(PayloadDecoder.ZERO_COPY) .metadataMimeType(COMPOSITE_MIME_TYPE.toString()) .setupPayload(setupPayload).addRequesterPlugin(interceptor) .transport(TcpClientTransport.create(gatewayPort)) // proxy .start().log("startPing" + id) .flatMapMany(socket -> doPing(take, socket)).cast(String.class) .doOnSubscribe(o -> { if (log.isDebugEnabled()) { log.debug("ping doOnSubscribe"); } }); boolean subscribe = env.getProperty("ping.subscribe", Boolean.class, true); if (subscribe) { pongFlux.subscribe(); } }
Example #25
Source File: RSocketService.java From staccato with Apache License 2.0 | 5 votes |
public RSocketService(RSocketConfigProps configProps, ItemSocketAcceptor itemSocketAcceptor) { log.info("Starting RSocket"); TcpServerTransport tcp = TcpServerTransport.create("0.0.0.0", configProps.getPort()); RSocketFactory.receive() .acceptor(itemSocketAcceptor) .transport(tcp) .start().log() .subscribe(channel -> log.info("RSocket initialized on port " + configProps.getPort())); }
Example #26
Source File: DefaultRSocketRequesterBuilderTests.java From spring-analysis-note with MIT License | 5 votes |
@Test @SuppressWarnings("unchecked") public void shouldApplyCustomizations() { Consumer<RSocketFactory.ClientRSocketFactory> factoryConfigurer = mock(Consumer.class); Consumer<RSocketStrategies.Builder> strategiesConfigurer = mock(Consumer.class); RSocketRequester.builder() .rsocketFactory(factoryConfigurer) .rsocketStrategies(strategiesConfigurer) .connect(this.transport) .block(); verify(this.transport).connect(anyInt()); verify(factoryConfigurer).accept(any(RSocketFactory.ClientRSocketFactory.class)); verify(strategiesConfigurer).accept(any(RSocketStrategies.Builder.class)); }
Example #27
Source File: DefaultRSocketRequesterBuilderTests.java From spring-analysis-note with MIT License | 5 votes |
@Test @SuppressWarnings("unchecked") public void shouldApplyCustomizationsAtSubscription() { Consumer<RSocketFactory.ClientRSocketFactory> factoryConfigurer = mock(Consumer.class); Consumer<RSocketStrategies.Builder> strategiesConfigurer = mock(Consumer.class); RSocketRequester.builder() .rsocketFactory(factoryConfigurer) .rsocketStrategies(strategiesConfigurer) .connect(this.transport); verifyZeroInteractions(this.transport, factoryConfigurer, strategiesConfigurer); }
Example #28
Source File: RSocketServerToClientIntegrationTests.java From spring-analysis-note with MIT License | 5 votes |
@BeforeClass @SuppressWarnings("ConstantConditions") public static void setupOnce() { context = new AnnotationConfigApplicationContext(RSocketConfig.class); server = RSocketFactory.receive() .frameDecoder(PayloadDecoder.ZERO_COPY) .acceptor(context.getBean("serverAcceptor", MessageHandlerAcceptor.class)) .transport(TcpServerTransport.create("localhost", 7000)) .start() .block(); }
Example #29
Source File: IntegrationTest.java From rsocket-rpc-java with Apache License 2.0 | 4 votes |
@Test public void test() { RequestHandlingRSocket requestHandler = new RequestHandlingRSocket(new CompositeMetadataDecoder()); RSocketFactory.receive() .acceptor((setup, sendingSocket) -> Mono.just(requestHandler)) .transport(LocalServerTransport.create("test-local-server")) .start() .block(); RSocket rsocket = RSocketFactory.connect() .transport(LocalClientTransport.create("test-local-server")) .start() .block(); AtomicBoolean ff = new AtomicBoolean(); IPCRSocket service = Server.service("HelloService") .noMeterRegistry() .noTracer() .marshall(Strings.marshaller()) .unmarshall(Strings.unmarshaller()) .requestResponse("hello", (s, byteBuf) -> Mono.just("Hello -> " + s)) .requestResponse("goodbye", (s, byteBuf) -> Mono.just("Goodbye -> " + s)) .requestResponse( "count", Primitives.intMarshaller(), (charSequence, byteBuf) -> Mono.just(charSequence.length())) .requestResponse( "increment", Primitives.intUnmarshaller(), Primitives.intMarshaller(), (integer, byteBuf) -> Mono.just(integer + 1)) .requestStream( "helloStream", (s, byteBuf) -> Flux.range(1, 10).map(i -> i + " - Hello -> " + s)) .requestStream( "toString", Primitives.longUnmarshaller(), (aLong, byteBuf) -> Flux.just(String.valueOf(aLong))) .fireAndForget( "ff", (s, byteBuf) -> { ff.set(true); return Mono.empty(); }) .requestChannel("helloChannel", (s, publisher, byteBuf) -> Flux.just("Hello -> " + s)) .toIPCRSocket(); requestHandler.withEndpoint(service); Client<CharSequence, String> helloService = Client.service("HelloService") .rsocket(rsocket) .customMetadataEncoder(new DefaultMetadataEncoder(ByteBufAllocator.DEFAULT)) .noMeterRegistry() .noTracer() .marshall(Strings.marshaller()) .unmarshall(Strings.unmarshaller()); String r1 = helloService.requestResponse("hello").apply("Alice").block(); Assert.assertEquals("Hello -> Alice", r1); String r2 = helloService.requestResponse("goodbye").apply("Bob").block(); Assert.assertEquals("Goodbye -> Bob", r2); StepVerifier.create(helloService.requestStream("helloStream").apply("Carol")) .expectNextCount(10) .expectComplete() .verify(); helloService.fireAndForget("ff").apply("boom").block(); Assert.assertTrue(ff.get()); String r3 = helloService.requestChannel("helloChannel").apply(Mono.just("Eve")).blockLast(); Assert.assertEquals("Hello -> Eve", r3); int count = helloService.requestResponse("count", Primitives.intUnmarshaller()).apply("hello").block(); Assert.assertEquals(5, count); long l = System.currentTimeMillis(); String toString = helloService.requestStream("toString", Primitives.longMarshaller()).apply(l).blockLast(); Assert.assertEquals(String.valueOf(l), toString); Integer increment = helloService .requestResponse("increment", Primitives.intMarshaller(), Primitives.intUnmarshaller()) .apply(1) .block(); Assert.assertEquals(2, increment.intValue()); }
Example #30
Source File: GraphQLIntegrationTest.java From rsocket-rpc-java with Apache License 2.0 | 4 votes |
@Test public void testQuery() throws Exception { RequestHandlingRSocket requestHandler = new RequestHandlingRSocket(); RSocketFactory.receive() .errorConsumer(Throwable::printStackTrace) .acceptor((setup, sendingSocket) -> Mono.just(requestHandler)) .transport(LocalServerTransport.create("testQuery")) .start() .block(); RSocket rsocket = RSocketFactory.connect() .errorConsumer(Throwable::printStackTrace) .transport(LocalClientTransport.create("testQuery")) .start() .block(); String query = "{\n" + " bookById(id: \"book-1\") {\n" + " id\n" + " name\n" + " pageCount\n" + " author {\n" + " firstName\n" + " lastName\n" + " }\n" + " }\n" + "}"; IPCRSocket service = GraphQLServer.service("books") .noMeterRegistry() .noTracer() .marshall(Json.marshaller(Object.class)) .unmarshall(Json.unmarshaller(GraphQLRequest.class)) .noDataLoadRegister() .defaultInstrumentation() .schema(getGraphQLSchema()) .noReadOnlySchema() .toIPCRSocket(); requestHandler.withEndpoint(service); GraphQLClient.Query bookQuery = GraphQLClient.service("books") .rsocket(rsocket) .customMetadataEncoder(new DefaultMetadataEncoder(ByteBufAllocator.DEFAULT)) .noMeterRegistry() .noTracer() .marshall(Json.marshaller(GraphQLRequest.class)) .unmarshall(unmarshaller()) .query(); GraphQLRequest request = new GraphQLRequest(query, new HashMap<>(), ""); GraphQLDataFetchers.Book book = (GraphQLDataFetchers.Book) bookQuery.apply(request).block(); System.out.println(book); }