Replication

The Replication protocol is based on the AppWebsocket protocol and is used between a publisher and a replicator to replicate a table of data between these two entities. When the replication starts, the complete table is replicated from the publisher to the replicator. During the replication session is active any changes are replicated in both directions.

General message structure

{
    "api": Name of the Table,
    "mt": Name of the Message,
    "src": AppWebsocket src
}

The AppWebsocket message format is used with the api, mt and src properties. To identify which AppWebsocket connection can be used for Replication and is not scope of the specification, but is defined for the specific publisher.

Messages sent by the Replicator Messages sent by the Publisher
Objects - recurring definitions

ReplicateStart

{
    "api": TableName,
    "mt": "ReplicateStart",
    "guid": hexstring,
    "usn": ulong64,
    "add": bool,
    "del": bool,
    "columns": Columns
}

This message is used by the Replicator to start or restart an replication. The replicator indicates it it ís able to add or delete rows and provides a list of columns it is interessted in.

guid
This is a GUID as a hex string which identifies the replicated database. If this matches to guid stored on the server side, only changes from the last replication have tp be sent.
usn
This is an "update sequence number" identifying the last information already replicated. Only rows with a higher usn need to be replicated.

ReplicateNext

{
    "api": TableName,
    "mt": "ReplicateNext"
}

ReplicateAdd

{
    "api": TableName,
    "mt": "ReplicateAdd",
    "columns": Columns
}

ReplicateDel

{
    "api": TableName,
    "mt": "ReplicateDel",
    "columns": Columns
}

ReplicateUpdate

{
    "api": TableName,
    "mt": "ReplicateAdd",
    "columns": Columns
}

ReplicateStartResult

{
    "api": TableName,
    "mt": "ReplicateStartResult",
    "guid": hexstring,
    "usn": ulong64,
    "columns": Columns
}

This message is sent by the publisher in response to a ReplicateStart message. The columns avaliable on the publisher are indicated in this message

guid
A GUID which identifies the connected database as a hex string. The replicator has to store this GUID and use it when restarting the replication with a ReplicateStart message so that only updates need to be sent.
usn
The update sequence number, at which the replication continues.

ReplicateNextResult

{
    "api": TableName,
    "mt": "ReplicateNextResult",
    "usn": ulong64,
    "columns": Columns
}

usn
The update sequence number of this row. The replicator should store the latest usn so that replication can continue at this point.

Objects

Columns
{
    "<row0>": { <"update":true> },
    "<row1>": { <"update":true> },
    ...
}

The columns object is used to describe the columns of a replication session. For each column a property with the name of the column is used. This property is an object, with the optional boolean property "update", which indicates, if update of the column is possibe/desired.