larvitamsync
Sync data between minions
Usage
Server (data master)
Simple command
const Intercom = winston = options = 'exchange': 'test_dataDump' // RabbitMQ exchange, must be unique on the queue amsync = log = winston; optionsintercom = 'conStr': 'AMQP connection string' 'log': log; // Set the log instance for the amsync server// This is optional, but recommendedoptionslog = log; // The stdout from this command will be piped to the data slave// This will be be the input for the// https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_optionsoptionsdataDumpCmd = 'command': 'cat' 'args': '/home/myself/dbdump.sql' 'options': {};// or pipe directly from mysqldump:optionsdataDumpCmd = 'command': 'mysqldump' 'args': '-u' 'root' '-psecret' '--single-transaction' 'dbname' 'table1' 'table2' 'options': {}; // You can set range of network ports to be used.// By not declaring port range a random free port will be used.optionsminPort = 5000;optionsmaxPort = 5100; options { if err throw err; console;};
Custom http request handler
On each data dump request there is a http request and this can be handled manually
const winston = Intercom = options = 'exchange': 'test_dataDump' // RabbitMQ exchange, must be unique on the queue amsync = log = winston; let syncServer; optionsintercom = 'conStr': 'AMQP connection string' 'log': log;optionslog = log; syncServer = options { if err throw err; console;}; syncServerhandleHttpReq_original = syncServerhandleHttpReq; syncServer { // Set custom content type res; // Run different commands depending on request url if requrl === '/' syncServeroptionsdataDumpCmd = 'command': 'echo' 'args': 'blergh'; else syncServeroptionsdataDumpCmd = 'command': 'echo' 'args': requrl; // Run the original request handler syncServer;}
Client (data slave)
For this to work, larvitamintercom must be configured and up and running!
const Intercom = options = {} amsync = ; optionsintercom = 'AMQP connection string';optionsexchange = 'test_dataDump'; // RabbitMQ exchange, must be unique on the queueoptionsrequestOptions = 'path': '/foobar'; // Optional extra options to // https://www.npmjs.com/package/request that // is used to request stuff from the server options { let syncData = Buffer; if err throw err; // res is an instance of https://nodejs.org/api/http.html#http_class_http_incomingmessage res; res; res;};
MariaDB/MySQL
For this to work, both larvitamintercom and larvitdb must be configured and up and running!
const winston = Intercom = options = 'exchange': 'test_dataDump' // RabbitMQ exchange, must be unique on the queue amsync = log = winston db = ; // See how to configure larvitdb here: https://github.com/larvit/larvitdb#larvitdbdb; optionsintercom = 'AMQP connection string';optionslog = log;optionsdb = db; amsync;