@codefresh-io/eventbus 2.4.0 → 3.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +39 -1
- package/lib/Bus.js +256 -135
- package/lib/Store.js +89 -94
- package/lib/index.js +74 -61
- package/lib/logger.js +5 -0
- package/package.json +19 -30
- package/.dockerignore +0 -2
- package/.eslintrc +0 -71
- package/Dockerfile +0 -15
- package/codefresh.yml +0 -23
- package/event.json +0 -9
- package/examples/etl.js +0 -64
- package/examples/test-consumer.js +0 -49
- package/examples/test-producer.js +0 -56
- package/gulpfile.js +0 -75
- package/lib/tests/test.unit.spec.js +0 -28
- package/yarn-error.log +0 -3182
- package/yarn.lock +0 -3120
package/codefresh.yml
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
version: '1.0'
|
|
2
|
-
steps:
|
|
3
|
-
main_clone:
|
|
4
|
-
title: "Cloning repository"
|
|
5
|
-
type: "git-clone"
|
|
6
|
-
repo: "codefresh-io/cf-eventbus"
|
|
7
|
-
revision: "${{CF_BRANCH}}"
|
|
8
|
-
git: "cf_github"
|
|
9
|
-
|
|
10
|
-
unit_test:
|
|
11
|
-
title: Running Unit Tests
|
|
12
|
-
image: node:11.10.0
|
|
13
|
-
commands:
|
|
14
|
-
- yarn install
|
|
15
|
-
|
|
16
|
-
deploy_to_npm:
|
|
17
|
-
type: npm-publish
|
|
18
|
-
arguments:
|
|
19
|
-
NPM_TOKEN: '${{NPM_TOKEN}}'
|
|
20
|
-
DIR: ./cf-eventbus
|
|
21
|
-
when:
|
|
22
|
-
branch:
|
|
23
|
-
only: [ master ]
|
package/event.json
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"aggregateId": "guid", // guid (the id of the object that the event is related to)
|
|
3
|
-
"version": 1, // the version of the aggregate
|
|
4
|
-
"data": {
|
|
5
|
-
"eventName": "eventName", // logical name of the event, referencing the schema
|
|
6
|
-
"eventVersion": "1", // version of the schema,
|
|
7
|
-
"field1": "field1"
|
|
8
|
-
}
|
|
9
|
-
}
|
package/examples/etl.js
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const Promise = require('bluebird');
|
|
4
|
-
const eventbus = require('../index');
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const main = async () => {
|
|
8
|
-
await exportDocs();
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const tranformDoc = async (row) => {
|
|
13
|
-
return row;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
const loadDoc = async (data) => {
|
|
17
|
-
return;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
const exportDocs = async () => {
|
|
21
|
-
|
|
22
|
-
const cursor = await eventbus.getAllEventsByName('myevent');
|
|
23
|
-
|
|
24
|
-
const totalCount = await cursor.count();
|
|
25
|
-
console.log(`Total count: ${totalCount}`);
|
|
26
|
-
let count = 0;
|
|
27
|
-
|
|
28
|
-
let row = await cursor.next();
|
|
29
|
-
while (row) {
|
|
30
|
-
const data = await tranformDoc(row);
|
|
31
|
-
await loadDoc(data);
|
|
32
|
-
count++;
|
|
33
|
-
console.log(`handled ${count} out of: ${totalCount}. ${JSON.stringify(data)}`);
|
|
34
|
-
row = await cursor.next();
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
await cursor.close();
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
Promise.resolve()
|
|
41
|
-
.then(async () => {
|
|
42
|
-
eventbus.init({
|
|
43
|
-
bus: {
|
|
44
|
-
url: 'amqp://codefresh.dev', // rabbitmq server
|
|
45
|
-
reconnectInterval: 5
|
|
46
|
-
},
|
|
47
|
-
store: {
|
|
48
|
-
host: 'codefresh.dev', // postgres host
|
|
49
|
-
database: 'postgres', // postgres database
|
|
50
|
-
user: 'postgres', // postgres user
|
|
51
|
-
password: 'postgres' // postgres password
|
|
52
|
-
},
|
|
53
|
-
microServiceName: 'service-name' // client name
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
eventbus.on('ready', async () => {
|
|
57
|
-
try {
|
|
58
|
-
await main();
|
|
59
|
-
await eventbus.quit();
|
|
60
|
-
} catch (err) {
|
|
61
|
-
console.error(err.stack);
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
});
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const Promise = require('bluebird');
|
|
4
|
-
const eventBus = require('../index');
|
|
5
|
-
eventBus.init({
|
|
6
|
-
bus: {
|
|
7
|
-
url: 'amqp://local.codefresh.io',
|
|
8
|
-
reconnectInterval: 5
|
|
9
|
-
},
|
|
10
|
-
store: {
|
|
11
|
-
host: 'local.codefresh.io',
|
|
12
|
-
database: 'postgres',
|
|
13
|
-
user: 'postgres',
|
|
14
|
-
password: 'postgres'
|
|
15
|
-
},
|
|
16
|
-
microServiceName: 'microservice2'
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
eventBus.on('error', async (err) => {
|
|
20
|
-
console.error(err.toString());
|
|
21
|
-
//await eventBus.quit();
|
|
22
|
-
console.log('quitted');
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
let totalRecieved = 0;
|
|
27
|
-
// setInterval(() => {
|
|
28
|
-
// eventBus.publish('myevent', `my message ${totalRecieved}`);
|
|
29
|
-
// totalRecieved++;
|
|
30
|
-
// console.log(`sent message: ${totalRecieved}`);
|
|
31
|
-
// }, 1000);
|
|
32
|
-
let bool = false;
|
|
33
|
-
const subscriber = eventBus.subscribe('myevent', (msg) => {
|
|
34
|
-
return Promise.resolve()
|
|
35
|
-
.then(() => {
|
|
36
|
-
totalRecieved++;
|
|
37
|
-
console.log(`recived message ${totalRecieved}: ${JSON.stringify(msg)}`);
|
|
38
|
-
})
|
|
39
|
-
.then(() => {
|
|
40
|
-
bool = !bool;
|
|
41
|
-
//return Promise.reject(new Error('my error!'));
|
|
42
|
-
})
|
|
43
|
-
.delay(1000);
|
|
44
|
-
}, {waitForAck: true, concurrencyLimit: 2, timeout: 2000, ackOnTimeout: true})
|
|
45
|
-
.then((subscriber) => {
|
|
46
|
-
subscriber.on('error', (err) => {
|
|
47
|
-
console.error(err.stack);
|
|
48
|
-
});
|
|
49
|
-
});
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const Promise = require("bluebird");
|
|
4
|
-
const eventBus = require('../index');
|
|
5
|
-
eventBus.init({
|
|
6
|
-
bus: {
|
|
7
|
-
url: 'amqp://local.codefresh.io',
|
|
8
|
-
reconnectInterval: 5
|
|
9
|
-
},
|
|
10
|
-
store: {
|
|
11
|
-
host: 'local.codefresh.io',
|
|
12
|
-
database: 'postgres',
|
|
13
|
-
user: 'postgres',
|
|
14
|
-
password: 'postgres'
|
|
15
|
-
},
|
|
16
|
-
//microServiceName: 'microservice2'
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
// eventBus.getAllAggregateEvents("552d386d3824831d00b1ca36")
|
|
20
|
-
// .then((events) => {
|
|
21
|
-
// var x = events;
|
|
22
|
-
// });
|
|
23
|
-
|
|
24
|
-
let totalSent = 0;
|
|
25
|
-
const eventsToSend = 1;
|
|
26
|
-
const interval = setInterval(() => {
|
|
27
|
-
return Promise.resolve()
|
|
28
|
-
.then(() => {
|
|
29
|
-
for (var i = 0; i < eventsToSend; i++) {
|
|
30
|
-
totalSent++;
|
|
31
|
-
eventBus.publish('myevent', {
|
|
32
|
-
accountId: "552d386d3824831d00b1ca38",
|
|
33
|
-
aggregateId: "552d386d3824831d00b1ca36",
|
|
34
|
-
userId: "userId",
|
|
35
|
-
props: {
|
|
36
|
-
totalSent: totalSent
|
|
37
|
-
}
|
|
38
|
-
})
|
|
39
|
-
}
|
|
40
|
-
})
|
|
41
|
-
.then(() => {
|
|
42
|
-
console.log(`sent message: ${totalSent}`);
|
|
43
|
-
})
|
|
44
|
-
.catch((err) => {
|
|
45
|
-
console.error(err.toString());
|
|
46
|
-
})
|
|
47
|
-
.done();
|
|
48
|
-
}, 2000);
|
|
49
|
-
|
|
50
|
-
setTimeout(() => {
|
|
51
|
-
console.log("STOPPING");
|
|
52
|
-
clearInterval(interval);
|
|
53
|
-
setTimeout(() => {
|
|
54
|
-
process.exit(0);
|
|
55
|
-
}, 100000);
|
|
56
|
-
}, 500000);
|
package/gulpfile.js
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
var gulp = require('gulp');
|
|
2
|
-
var jshint = require('gulp-jshint');
|
|
3
|
-
var rimraf = require('gulp-rimraf');
|
|
4
|
-
var runSequence = require('run-sequence');
|
|
5
|
-
var fs = require('fs');
|
|
6
|
-
var coveralls = require('gulp-coveralls');
|
|
7
|
-
var istanbul = require('gulp-istanbul');
|
|
8
|
-
var isparta = require('isparta');
|
|
9
|
-
var mocha = require('gulp-mocha');
|
|
10
|
-
require('shelljs/global');
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
gulp.task('no.onlys', function (callback) {
|
|
15
|
-
exec('find . -path "*/*.spec.js" -type f -exec grep -l "describe.only" {} + \n find . -path "*/*.spec.js" -type f -exec grep -l "it.only" {} +', function (code, output) { // jshint ignore:line
|
|
16
|
-
if (output) return callback(new Error("The following files contain .only in their tests"));
|
|
17
|
-
return callback();
|
|
18
|
-
});
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
gulp.task('lint', ['clean'], function () {
|
|
22
|
-
return gulp.src(['**/*.js', '!**/node_modules/**', '!**/server/migration/**', '!coverage/**/*.js'])
|
|
23
|
-
.pipe(jshint({lookup: true}))
|
|
24
|
-
.pipe(jshint.reporter('default'))
|
|
25
|
-
.pipe(jshint.reporter('fail'));
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
gulp.task('unit_pre', function () {
|
|
29
|
-
return gulp.src(['**/*.js', '!**/*.spec.js', '!**/node_modules/**/*.js', '!.debug/**/*.js', '!gulpfile.js', '!coverage/**/*.js', '!server/migration/**/*.js'])
|
|
30
|
-
.pipe(istanbul({ // Covering files
|
|
31
|
-
instrumenter: isparta.Instrumenter,
|
|
32
|
-
includeUntested: true
|
|
33
|
-
}))
|
|
34
|
-
.pipe(istanbul.hookRequire()) // Force `require` to return covered files
|
|
35
|
-
.on('finish', function () {
|
|
36
|
-
gulp.src(['**/*.unit.spec.js', '!**/node_modules/**/*.js'], {read: false})
|
|
37
|
-
.pipe(mocha({reporter: 'spec', timeout: '10000'}))
|
|
38
|
-
.pipe(istanbul.writeReports({
|
|
39
|
-
reporters: ['lcov'],
|
|
40
|
-
reportOpts: {dir: 'coverage'}
|
|
41
|
-
}))
|
|
42
|
-
.once('end', function () {
|
|
43
|
-
process.exit();
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
gulp.task('clean', function () {
|
|
49
|
-
return gulp.src(['.coverdata', '.debug', '.coverrun'], {read: false})
|
|
50
|
-
.pipe(rimraf());
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
gulp.task('unit_test', function (callback) {
|
|
54
|
-
runSequence('unit_pre',
|
|
55
|
-
callback);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
gulp.task('coveralls', function (callback) {
|
|
59
|
-
var repo_token = process.env.COVERALLS_TOKEN;
|
|
60
|
-
if (!repo_token) {
|
|
61
|
-
return callback(new Error("COVERALLS_TOKEN environment variable is missing"));
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
fs.writeFile(".coveralls.yml", "service_name: codefresh-io\nrepo_token: " + repo_token, function (err) {
|
|
65
|
-
if (err) {
|
|
66
|
-
callback(err);
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
gulp.src('coverage/lcov.info')
|
|
70
|
-
.pipe(coveralls());
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const chai = require('chai');
|
|
4
|
-
const expect = chai.expect;
|
|
5
|
-
const proxyquire = require('proxyquire').noCallThru();
|
|
6
|
-
const sinon = require('sinon');
|
|
7
|
-
const sinonChai = require('sinon-chai');
|
|
8
|
-
chai.use(sinonChai);
|
|
9
|
-
|
|
10
|
-
describe('test', () => {
|
|
11
|
-
|
|
12
|
-
describe('positive tests', () => {
|
|
13
|
-
|
|
14
|
-
it('my test', () => {
|
|
15
|
-
expect(3).to.equal(3);
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
describe('negative tests', () => {
|
|
21
|
-
|
|
22
|
-
it('my test', () => {
|
|
23
|
-
expect(4).to.equal(4);
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
});
|