i have 2 server that is using grpc.
my detail server logic is described like down.
Server structure (----> is grpc connection)
Client ----> ServerA ----> ServerB
data stream like below.
- client send stream data. ex (DEF data send)
- ServerA stores data. (ABC is previous data and DEF is new data, so total Data is ABCDEF)
- ServerA send newest data to ServerB from client(DEF)
In this situation, when some event occurs, I need to disconnect from ServerB and connect another server.
for example,
The schematic diagram when an event occurs is as follows.
Client ----> ServerA --X(Stream Stop)--> ServerB
ㅣ--(reconnect to other server using grpc)--> ServerB'
I want to send the old data streams sequentially.
even server is chainging ServerA is received data from Client(EX data is GHI)
so, When ServerA's connection change is completed.
data flow like below
- Server A send previous total data to ServerB' (ABCDEF)
- Server A is receiving newest data. may be this data`ll be received when server change is not compeleted (GHI)
- newest data(GHI) is send to ServerB'
and i want this flowchart to work correctly.
could you tell me any good idea??
thank you.
CodePudding user response:
i find answer. the answer is reactive X.
for example,
ReplaySubject subject = ReplaySubject.create();
subject.subscribe(..anysub function);
...
void pushData(int data) {
if(server change) {
subject data supress
subject clear // caused when replay subscribe clear
ReplaySubject newSubject = ReplaySubject.create();
newSubject.onNext(suppress data);
newSubject.onNext(data);
subject = newSubject;
} else {
subject.onNext(data);
}
//when server change event trigger
}
that is my best way.