-
-
Save tpeczek/b2f963e7c79dcb9648bbb9e87a5065a2 to your computer and use it in GitHub Desktop.
A very simple RSocket client in Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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