Skip to content

Instantly share code, notes, and snippets.

@tpeczek tpeczek/RSocketClient.java Secret
Created Aug 18, 2019

Embed
What would you like to do?
A very simple RSocket client in Java
package com.tpeczek.demo;
import io.rsocket.*;
import io.rsocket.transport.netty.client.TcpClientTransport;
import io.rsocket.util.DefaultPayload;
public class RSocketClient
{
private static final String PAYLOAD = "[Demo Payload]";
private static final int MAX_ECHOES = 10;
public static void main( String[] args )
{
System.out.println("-- Demo.RSocket --");
System.out.println("Connecting to RSocket server...");
RSocket socket = RSocketFactory.connect()
.transport(TcpClientTransport.create("127.0.0.1", 6000))
.start()
.block();
System.out.println("Requesting stream...");
System.out.println(" REQUEST PAYLOAD: " + PAYLOAD);
socket.requestStream(DefaultPayload.create(PAYLOAD))
.map(Payload::getDataUtf8)
.doOnNext(payload -> System.out.println(" RESPONSE ON NEXT PAYLOAD: " + payload))
.take(MAX_ECHOES)
.then()
.doFinally(signalType -> socket.dispose())
.then()
.block();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.