19: Implement cluster discovery using dns

This commit is contained in:
Nicolas Dextraze
2017-01-29 10:57:59 -08:00
parent 0463d85cfe
commit 1558918692
3 changed files with 91 additions and 47 deletions

32
test/cluster/dns_test.js Normal file
View File

@ -0,0 +1,32 @@
var client = require('../../src/client');
var uuid = require('uuid');
var settings = {
log: {
info: console.log,
error: console.log,
debug: console.log
}
};
var conn = client.createConnection(settings, "discover://es.nicdex.com:2113");
console.log('Connecting...');
conn.on('connected', function (tcpEndPoint) {
console.log('Connected to', tcpEndPoint);
setTimeout(function () {
conn.appendToStream('test-' + uuid.v4(), client.expectedVersion.noStream, [
client.createJsonEventData(uuid.v4(), {abc: 123}, {}, 'myEvent')
]);
}, 5000);
});
conn.on('error', function (err) {
console.log(err.stack);
});
conn.on('closed', function (reason) {
console.log('Connection closed:', reason);
process.exit(-1);
});
conn.connect()
.catch(function (err) {
console.log(err.stack);
process.exit(-1);
});

View File

@ -9,15 +9,14 @@ var settings = {
}
};
var gossipSeeds = [
new client.GossipSeed({host: '192.168.33.10', port: 1113}),
new client.GossipSeed({host: '192.168.33.11', port: 1113}),
new client.GossipSeed({host: '192.168.33.12', port: 1113})
new client.GossipSeed({host: '192.168.33.10', port: 2113}),
new client.GossipSeed({host: '192.168.33.11', port: 2113}),
new client.GossipSeed({host: '192.168.33.12', port: 2113})
];
var conn = client.createConnection(settings, gossipSeeds);
console.log('Connecting...');
conn.on('connected', function (tcpEndPoint) {
console.log('Connect to', tcpEndPoint);
console.log('Connected to', tcpEndPoint);
setTimeout(function () {
conn.appendToStream('test-' + uuid.v4(), client.expectedVersion.noStream, [
client.createJsonEventData(uuid.v4(), {abc: 123}, {}, 'myEvent')