@nebulae/event-store-tpi-rx6 1.1.2
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/.env +0 -0
- package/.jshintrc +4 -0
- package/.vscode/settings.json +6 -0
- package/README.md +23 -0
- package/docs/images/microservices_platform.png +0 -0
- package/docs/images/nebula.png +0 -0
- package/docs/images/read_workflow.png +0 -0
- package/docs/images/service_interaction.png +0 -0
- package/docs/images/shell_composition.png +0 -0
- package/docs/images/write_workflow_crud_es.png +0 -0
- package/docs/images/write_workflow_pure_cqrs_es.png +0 -0
- package/docs/tmp/microservices_platform.png +0 -0
- package/docs/tmp/ms-dashboard-devices_intro.png +0 -0
- package/docs/tmp/ms-devices-location-dev-env.png +0 -0
- package/docs/tmp/nebula.png +0 -0
- package/docs/tmp/read_workflow.png +0 -0
- package/docs/tmp/service_interaction.png +0 -0
- package/docs/tmp/shell_composition.png +0 -0
- package/docs/tmp/write_workflow_crud_es.png +0 -0
- package/docs/tmp/write_workflow_pure_cqrs_es.png +0 -0
- package/index.js +9 -0
- package/lib/EventStore.js +172 -0
- package/lib/broker/MqttBroker.js +116 -0
- package/lib/broker/PubSubBroker.js +144 -0
- package/lib/entities/Event.js +47 -0
- package/lib/store/MongoStore.js +455 -0
- package/package.json +68 -0
- package/test/EventStore.js +114 -0
- package/test/broker/MqttBroker.js +129 -0
- package/test/broker/PubSubBroker.js +125 -0
- package/test/store/MongoStore.js +509 -0
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
// TEST LIBS
|
|
2
|
+
const assert = require('assert');
|
|
3
|
+
const Rx = require('rxjs');
|
|
4
|
+
const { first, timeout, filter, mapTo, map} = require('rxjs/operators');
|
|
5
|
+
//LIBS FOR TESTING
|
|
6
|
+
const MqttBroker = require('../../lib/broker/MqttBroker');
|
|
7
|
+
const Event = require('../../lib/entities/Event');
|
|
8
|
+
|
|
9
|
+
//GLOABAL VARS to use between tests
|
|
10
|
+
let mqttBroker = {};
|
|
11
|
+
let eventMqtt = new Event(
|
|
12
|
+
{
|
|
13
|
+
eventType: 'TestCreated', eventTypeVersion: 1,
|
|
14
|
+
aggregateType: 'Test', aggregateId: 1,
|
|
15
|
+
data: { id: 1, name: 'x' },
|
|
16
|
+
user: 'Mocha', aggregateVersion: 1
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
/*
|
|
21
|
+
NOTES:
|
|
22
|
+
before run please start mqtt:
|
|
23
|
+
docker run -it -p 1883:1883 -p 9001:9001 eclipse-mosquitto
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
describe('MQTT BROKER', function () {
|
|
27
|
+
describe('Prepare mqtt broker', function () {
|
|
28
|
+
it('instance MqttBroker', function (done) {
|
|
29
|
+
//ENVIRONMENT VARS
|
|
30
|
+
const brokerUrl = 'mqtt://localhost:1883';
|
|
31
|
+
const projectId = 'MqttBrokerTest';
|
|
32
|
+
const eventsTopic = 'MqttBrokerTest';
|
|
33
|
+
mqttBroker = new MqttBroker({ brokerUrl, eventsTopic, projectId });
|
|
34
|
+
assert.ok(true, 'MqttBroker constructor worked');
|
|
35
|
+
return done();
|
|
36
|
+
});
|
|
37
|
+
it('start MqttBroker', function (done) {
|
|
38
|
+
mqttBroker.start$()
|
|
39
|
+
.subscribe(
|
|
40
|
+
(evt) => console.log(`start MqttBroker: ${evt}`),
|
|
41
|
+
(error) => {
|
|
42
|
+
console.error(`error starting MqttBroker`,error);
|
|
43
|
+
return done(error);
|
|
44
|
+
},
|
|
45
|
+
() => {
|
|
46
|
+
console.log('MQTT Broker started!');
|
|
47
|
+
return done();
|
|
48
|
+
}
|
|
49
|
+
);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
describe('Publish and listen on MQTT', function () {
|
|
53
|
+
it('Publish event and recive my own event on MQTT', function (done) {
|
|
54
|
+
this.timeout(10000);
|
|
55
|
+
let event1 = new Event(
|
|
56
|
+
{
|
|
57
|
+
eventType: 'TestCreated', eventTypeVersion: 1,
|
|
58
|
+
aggregateType: 'Test', aggregateId: 1,
|
|
59
|
+
data: { id: 1, name: 'x' },
|
|
60
|
+
user: 'Mocha', aggregateVersion: 1
|
|
61
|
+
});
|
|
62
|
+
//let event1 = new Event('Test', 1, 'TestCreated', { id: 1, name: 'x' }, 'Mocha');
|
|
63
|
+
mqttBroker.getEventListener$('Test', false)
|
|
64
|
+
.pipe(first())
|
|
65
|
+
//.timeout(1500)
|
|
66
|
+
.subscribe(
|
|
67
|
+
(evt) => {
|
|
68
|
+
incomingEvent = evt;
|
|
69
|
+
//console.log('==============> Expected message -> ', event1.timestamp + " -- "+ evt.timestamp);
|
|
70
|
+
assert.deepEqual(evt, event1);
|
|
71
|
+
},
|
|
72
|
+
error => {
|
|
73
|
+
return done(new Error(error));
|
|
74
|
+
},
|
|
75
|
+
() => {
|
|
76
|
+
return done();
|
|
77
|
+
}
|
|
78
|
+
);
|
|
79
|
+
mqttBroker.publish$(event1).subscribe(
|
|
80
|
+
() => { },
|
|
81
|
+
(err) => console.error(err),
|
|
82
|
+
() => { }
|
|
83
|
+
);
|
|
84
|
+
});
|
|
85
|
+
it('Publish event and DO NOT recieve my own event on MQTT', function (done) {
|
|
86
|
+
let event2 = new Event('TestCreated', 1, 'Test', 1, 1, { id: 1, name: 'x' }, 'Mocha');
|
|
87
|
+
mqttBroker.getEventListener$('Test')
|
|
88
|
+
.pipe(first()
|
|
89
|
+
, timeout(500)
|
|
90
|
+
)
|
|
91
|
+
.subscribe(
|
|
92
|
+
(evt) => {
|
|
93
|
+
incomingEvent = evt;
|
|
94
|
+
//console.log('==============> Unexpected message -> ', event2.timestamp + " -- "+ evt.timestamp);
|
|
95
|
+
assert.notDeepEqual(evt, event2);
|
|
96
|
+
//assert.fail(evt, 'nothing', 'Seems I have recieved the same evt I just sent');
|
|
97
|
+
},
|
|
98
|
+
error => {
|
|
99
|
+
assert.equal(error.name, 'TimeoutError');
|
|
100
|
+
return done();
|
|
101
|
+
},
|
|
102
|
+
() => {
|
|
103
|
+
return done();
|
|
104
|
+
}
|
|
105
|
+
);
|
|
106
|
+
mqttBroker.publish$(event2).subscribe(
|
|
107
|
+
() => { },
|
|
108
|
+
(err) => console.error(err),
|
|
109
|
+
() => { }
|
|
110
|
+
);
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
describe('de-prepare mqtt broker', function () {
|
|
114
|
+
it('stop MqttBroker', function (done) {
|
|
115
|
+
mqttBroker.stop$()
|
|
116
|
+
.subscribe(
|
|
117
|
+
(evt) => console.log(`stop MqttBroker: ${evt}`),
|
|
118
|
+
(error) => {
|
|
119
|
+
console.error('Error stopping MqttBroker',error);
|
|
120
|
+
return done(error);
|
|
121
|
+
},
|
|
122
|
+
() => {
|
|
123
|
+
console.log('Mqtt broker stoped');
|
|
124
|
+
return done();
|
|
125
|
+
}
|
|
126
|
+
);
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
});
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
// TEST LIBS
|
|
2
|
+
const assert = require('assert');
|
|
3
|
+
const Rx = require('rxjs');
|
|
4
|
+
|
|
5
|
+
//LIBS FOR TESTING
|
|
6
|
+
const PubSubBroker = require('../../lib/broker/PubSubBroker');
|
|
7
|
+
const Event = require('../../lib/entities/Event');
|
|
8
|
+
|
|
9
|
+
//GLOABAL VARS to use between tests
|
|
10
|
+
let broker = {};
|
|
11
|
+
let subscription = {};
|
|
12
|
+
let event = new Event(
|
|
13
|
+
{
|
|
14
|
+
eventType: 'TestCreated', eventTypeVersion: 1,
|
|
15
|
+
aggregateType: 'Test', aggregateId: 1,
|
|
16
|
+
data: { id: 1, name: 'x' },
|
|
17
|
+
user: 'Mocha', aggregateVersion: 1
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
describe('PUBSUB BROKER', function () {
|
|
23
|
+
describe('Prepare pubsub broker', function () {
|
|
24
|
+
it('instance PubSubBroker', function (done) {
|
|
25
|
+
//ENVIRONMENT VARS
|
|
26
|
+
process.env.GOOGLE_APPLICATION_CREDENTIALS = "/Users/sebastianmolano/NebulaE/Projects/TPM/gateway/etc/gcloud-service-key.json";
|
|
27
|
+
const eventsTopic = 'Test';
|
|
28
|
+
const eventsTopicSubscription = 'TestSubscription';
|
|
29
|
+
broker = new PubSubBroker({ eventsTopic, eventsTopicSubscription });
|
|
30
|
+
assert.ok(true, 'PubSubBroker constructor worked');
|
|
31
|
+
return done();
|
|
32
|
+
});
|
|
33
|
+
it('start PubSubBroker', function (done) {
|
|
34
|
+
subscription = broker.start$()
|
|
35
|
+
.subscribe(
|
|
36
|
+
(evt) => console.log(`start PubSubBroker: ${evt}`),
|
|
37
|
+
(error) => {
|
|
38
|
+
console.error(`error starting PubSubBroker`, error);
|
|
39
|
+
return done(error);
|
|
40
|
+
},
|
|
41
|
+
() => {
|
|
42
|
+
console.log('PubSubBroker Broker started!');
|
|
43
|
+
return done();
|
|
44
|
+
}
|
|
45
|
+
);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
describe('Publish and listen on PubSub', function () {
|
|
49
|
+
it('Publish event and recive my own event on PubSub', function (done) {
|
|
50
|
+
this.timeout(10000);
|
|
51
|
+
let event1 = new Event(
|
|
52
|
+
{
|
|
53
|
+
eventType: 'TestCreated', eventTypeVersion: 1,
|
|
54
|
+
aggregateType: 'Test', aggregateId: 1,
|
|
55
|
+
data: { id: 1, name: 'x' },
|
|
56
|
+
user: 'Mocha', aggregateVersion: 1
|
|
57
|
+
});
|
|
58
|
+
//let event1 = new Event('Test', 1, 'TestCreated', { id: 1, name: 'x' }, 'Mocha');
|
|
59
|
+
broker.getEventListener$('Test', false)
|
|
60
|
+
.pipe(first())
|
|
61
|
+
//.timeout(1500)
|
|
62
|
+
.subscribe(
|
|
63
|
+
(evt) => {
|
|
64
|
+
incomingEvent = evt;
|
|
65
|
+
//console.log('==============> Expected message -> ', event1.timestamp + " -- "+ evt.timestamp);
|
|
66
|
+
assert.deepEqual(evt, event1);
|
|
67
|
+
},
|
|
68
|
+
error => {
|
|
69
|
+
return done(new Error(error));
|
|
70
|
+
},
|
|
71
|
+
() => {
|
|
72
|
+
return done();
|
|
73
|
+
}
|
|
74
|
+
);
|
|
75
|
+
broker.publish$(event1).subscribe(
|
|
76
|
+
() => { },
|
|
77
|
+
(err) => console.error(err),
|
|
78
|
+
() => { }
|
|
79
|
+
);
|
|
80
|
+
});
|
|
81
|
+
it('Publish event and DO NOT recieve my own event on PubSubBroker', function (done) {
|
|
82
|
+
let event2 = new Event('TestCreated', 1, 'Test', 1, 1, { id: 1, name: 'x' }, 'Mocha');
|
|
83
|
+
broker.getEventListener$('Test')
|
|
84
|
+
.pipe(first()
|
|
85
|
+
,timeout(500))
|
|
86
|
+
.subscribe(
|
|
87
|
+
(evt) => {
|
|
88
|
+
incomingEvent = evt;
|
|
89
|
+
//console.log('==============> Unexpected message -> ', event2.timestamp + " -- "+ evt.timestamp);
|
|
90
|
+
assert.notDeepEqual(evt, event2);
|
|
91
|
+
//assert.fail(evt, 'nothing', 'Seems I have recieved the same evt I just sent');
|
|
92
|
+
},
|
|
93
|
+
error => {
|
|
94
|
+
assert.equal(error.name, 'TimeoutError');
|
|
95
|
+
return done();
|
|
96
|
+
},
|
|
97
|
+
() => {
|
|
98
|
+
return done();
|
|
99
|
+
}
|
|
100
|
+
);
|
|
101
|
+
broker.publish$(event2).subscribe(
|
|
102
|
+
() => { },
|
|
103
|
+
(err) => console.error(err),
|
|
104
|
+
() => { }
|
|
105
|
+
);
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
describe('de-prepare PubSub broker', function () {
|
|
109
|
+
it('stop PubSubBroker', function (done) {
|
|
110
|
+
broker.stop$()
|
|
111
|
+
.subscribe(
|
|
112
|
+
(evt) => console.log(`stop PubSubBroker: ${evt}`),
|
|
113
|
+
(error) => {
|
|
114
|
+
console.error('Error stopping PubSubBroker', error);
|
|
115
|
+
return done(error);
|
|
116
|
+
},
|
|
117
|
+
() => {
|
|
118
|
+
console.log('PubSubBroker broker stoped');
|
|
119
|
+
subscription.unsubscribe();
|
|
120
|
+
return done();
|
|
121
|
+
}
|
|
122
|
+
);
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
});
|