Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stateful Rsocket Application

in my project I want to have multiple clients connecting to a service. I am using the java Rsocket implementation.

The service should maintain a state for each client. Now at this point I either can manage the clients by some identifier. This option I have already implemented. But I do not want to manage the session manually using strings.

So another idea is to identify the clients by the Rsocket connection. Is there a way to use Rsocket channel for identification of a specific client?

Imagine an example service and a couple of clients. Each client has the Rsocket channel with the service up and running. Is there a way to identify these clients on the server side using the Rsocket channel? Would be amazing if you could show a programmatic example of such behavior. Thank you!

EDIT (describing the case more detailed)

Here is my example.

We currently have three CORBA objects that are used as demonstrated in the diagram:

  • LoginObject (to which a reference is retrieved via NamingService). Clients can call a login() method to obtain a session
  • The Session object has various methods for query details about the current serivce context and most importatly to obtain a Transaction object
  • The Transaction object can be used to execute various commands via a generic method that take a commandName and a list of key-value pairs as parameters. After the client executed n commands he can commit or rollback the transaction (also via methods on the Transaction object).

enter image description here

so here we use the session object to execute transactions on our service.

Now we decided to move away from CORBA to Rsocket. Thus we need Rsocket microservice to be able to store the session's state, otherwise we can't know what's going to be commited or rolled back. Can this be done with just individual Publisher for each client?

like image 360
Aksim Elnik Avatar asked May 03 '19 11:05

Aksim Elnik


People also ask

Does RSocket use TCP?

RSocket requires TCP, WebSockets or Aeron. We have no intention of this running over HTTP/1.1. We also do not intend on running over HTTP/2 when fronted only by HTTP/1.1 APIs (as browsers expose), though that could be explored and conceptually is possible (with the use of SSE or chunked encoding).

What is spring boot RSocket?

RSocket is an application protocol for multiplexed, duplex communication over TCP, WebSocket, and other byte stream transports, using one of the following interaction models: Request-Response — send one message and receive one back. Request-Stream — send one message and receive a stream of messages back.

Who created RSocket?

RSocket is an application protocol initially developed by Netflix, that supports Reactive Streams.


1 Answers

Here's an example I made the other day that will create a stateful RSocket using Netifi's broker: https://github.com/netifi/netifi-stateful-socket

Unfortunately you'd need to build our develop branch locally to try it out (https://github.com/netifi/netifi-java) - there should be a release with the code by the end of the week if you don't want to build it locally.

I'm working on a pure RSocket example too, but if you want to see how it would take a look at the StatefulSocket found in the example. It should give you a clue how to deal with the session with pure RSocket.

Regarding your other questions about a transaction manager - you would need to tie your transaction to the Reactive Streams signals that are being emitted - if you received an cancel, an onError you'd roll back, and if received a onComplete you would commit the transaction. There are side effect methods from Flux/Mono that should make this easy to deal with. Depending on what you are doing you could also use the BaseSubscriber as it has hooks to deal with the different Reactive Streams signals.

Thanks, Robert

like image 197
Robert Roeser Avatar answered Sep 25 '22 22:09

Robert Roeser