Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
478 views
in Technique[技术] by (71.8m points)

spring webflux - How to implement an RSocketRequest Client Handler in Typescript

I would like to implement a client handler which will receive my server callbacks. The following tutorial provides an idea of how to handle callbacks from the server in Java :

@Slf4j
class ClientHandler {
 
 @MessageMapping("client-status")
 public Flux<String> statusUpdate(String status) {
   log.info("Connection {}", status);
   return Flux.interval(Duration.ofSeconds(5)).map(index -> String.valueOf(Runtime.getRuntime().freeMemory()));
 }
}

I am stuck here wondering how can I implement a similar thing in typescript. I am using Angular for my frontend. Any help will be more than appreciated.

question from:https://stackoverflow.com/questions/65901502/how-to-implement-an-rsocketrequest-client-handler-in-typescript

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This example has a simple echo responder that will allow the server to initiate requests back to the client.

https://github.com/rsocket/rsocket-js/blob/c539b3a42d56780011392fc06ebd488d09f929da/packages/rsocket-examples/src/LeaseClientExample.js

class EchoResponder implements Responder<string, string> {
  metadataPush(payload: Payload<string, string>): Single<void> {
    return Single.error(new Error('not implemented'));
  }

  fireAndForget(payload: Payload<string, string>): void {
    logRequest('fire-and-forget', payload);
  }

So you could connect a socket, not initiate any requests from client->server, but wait for server->client requests.

const client = new RSocketClient({
  setup: {
    dataMimeType: 'text/plain',
    keepAlive: 1000000,
    lifetime: 100000,
    metadataMimeType: 'text/plain',
  },
  responder: new EchoResponder(),
  leases: () =>
    new Leases()
      .receiver(receivedLeasesLogger)
      .sender(stats => periodicLeaseSender(10000, 7000, 10)),
  transport: getClientTransport(address.host, address.port),
});

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...