1 year ago

#361693

test-img

欧阳维杰

how to create a pub/sub pattern between two collections

I have a document on server A as a publisher and another document on server B as a subscriber. The data structure of the document looks like this:

{
  nodeId0: {
    property0: value0,
    property1: value1,
    ...
  },
  nodeId1: {
    property0: value0,
    property1: value1,
    ...
  },
  ...
}

I want every time when the document on server A to change. Then the document on server B will follow the same way. So I am trying to create a "version mechanism" for the document. And create some rules like this:

  1. every time when A changes will emit a message to B. And A will increase its version number.
  2. B is not allowed to change the document version.
  3. In the cause of network condition may cause B offline. Every 10 seconds, the B will check if its document version is less than the A's. If that is the cause, B will try to find out which node of the document needs to be changed.

So my question is:

  1. Am I doing the right thing?
  2. Is there exist any libraries doing the same thing? (I am using redux.js on server B, a node.js server on A, and socket.io for communication)
  3. If I am on the right way, what is the most efficient way for B to check which node needs to be updated when the version of B is less than A?

node.js

redux

socket.io

publish-subscribe

0 Answers

Your Answer

Accepted video resources