Spring Rsocket Bi-Directional Channel

208 Views Asked by At

Is there a possibility to send Messages in a sequential way like flatMapSequential from client to Server? The default behaviour seems to be only in an almost sequential way like flatMap if I use

requester.route("name")
         .data(fluxSendToServer.doOnNext(nr -> log.trace("Send next " + nr.getRequest().getCurrentSequenceValue())))
         .retrieveFlux(ResponseMessageWrapper.class)

and log the sequence at the server.

1

There are 1 best solutions below

1
On

Thank you for your answer. If I change the Code at the client to

  requester.route("name").data(fluxSendToServer.index().map(indexedTuple->{
if(!indexedTuple.getT2().getRequest().getCurrentSequenceValue().equals(indexedTuple.getT1()+1))
{
throw new IllegalStateException("Orderingproblem in client at index "+indexedTuple.getT1());
 };
return indexedTuple.getT2();
 }))

and use the same code at the receiving server method

     @MessageMapping("name")
   Flux<EncryptedResponseMessageWrapper> handleMessageClientToServer(Flux<EncryptedRequestMessageWrapper> 
         fluxReceivedAtServer){
         return fluxReceivedAtServer.index().map(indexedTuple->  {
if(!indexedTuple.getT2().getRequest().getCurrentSequenceValue().equals(indexedTuple.getT1()+1))
{
 throw new IllegalStateException("Orderingproblem at server at index"+indexedTuple.getT1());
};
return indexedTuple.getT2();
})

For a Flux of 4000 Elements I get each time the IllegalStateException at random positions for Example Error in Route send-message-client-to-server Orderingproblem at server at index 2175

In case I use less elements it seems to repeatedly work.