commit
a1b9d6db9b
|
@ -1,39 +1,47 @@
|
||||||
var client = require('../src/client');
|
// const client = require('../src/client')
|
||||||
var uuid = require('uuid');
|
const client = require("eventstore-node")
|
||||||
|
const uuid = require("uuid")
|
||||||
|
|
||||||
var settings = {
|
const settings = {
|
||||||
verboseLogging: true,
|
verboseLogging: true,
|
||||||
log: new client.FileLogger('./simple-verbose.log')
|
log: new client.FileLogger("./simple-verbose.log")
|
||||||
};
|
}
|
||||||
var gossipSeeds = [
|
const gossipSeeds = [
|
||||||
new client.GossipSeed({host: '192.168.33.10', port: 2113}),
|
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.11", port: 2113}),
|
||||||
new client.GossipSeed({host: '192.168.33.12', port: 2113})
|
new client.GossipSeed({host: "192.168.33.12", port: 2113})
|
||||||
];
|
]
|
||||||
var conn = client.createConnection(settings, gossipSeeds);
|
const connection = client.createConnection(settings, gossipSeeds)
|
||||||
conn.connect()
|
|
||||||
.catch(function (err) {
|
connection.connect().catch(err => console.log(err))
|
||||||
console.log(err);
|
|
||||||
//process.exit(-1);
|
connection.on("connected", endPoint => {
|
||||||
});
|
console.log(`connected to endPoint ${endPoint}`)
|
||||||
conn.on('connected', function (endPoint) {
|
|
||||||
console.log('connected to endPoint', endPoint);
|
setInterval(() => {
|
||||||
//Start some work
|
connection.appendToStream(
|
||||||
setInterval(function () {
|
`test-${uuid.v4()}`,
|
||||||
conn.appendToStream('test-' + uuid.v4(), client.expectedVersion.noStream, [
|
client.expectedVersion.noStream,
|
||||||
client.createJsonEventData(uuid.v4(), {abc: 123}, null, 'MyEvent')
|
[
|
||||||
]).then(function (writeResult) {
|
client.createJsonEventData(
|
||||||
console.log(writeResult);
|
uuid.v4(),
|
||||||
});
|
{ abc: 123 },
|
||||||
}, 1000);
|
null,
|
||||||
});
|
"MyEvent"
|
||||||
conn.on('error', function (err) {
|
)
|
||||||
console.log('Error occurred on connection:', err);
|
]
|
||||||
});
|
).then(writeResult => console.log(writeResult))
|
||||||
conn.on('closed', function (reason) {
|
}, 1000)
|
||||||
console.log('Connection closed, reason:', reason);
|
})
|
||||||
//process.exit(-1);
|
|
||||||
});
|
connection.on("error", error =>
|
||||||
process.stdin.setRawMode(true);
|
console.log(`Error occurred on connection: ${error}`)
|
||||||
process.stdin.resume();
|
)
|
||||||
process.stdin.on('data', process.exit.bind(process, 0));
|
|
||||||
|
connection.on("closed", reason =>
|
||||||
|
console.log(`Connection closed, reason: ${reason}`)
|
||||||
|
)
|
||||||
|
|
||||||
|
process.stdin.setRawMode(true)
|
||||||
|
process.stdin.resume()
|
||||||
|
process.stdin.on("data", process.exit.bind(process, 0))
|
||||||
|
|
|
@ -1,40 +1,52 @@
|
||||||
var esClient = require('../src/client'); // When running in 'eventstore-node/samples' folder.
|
// const client = require('../src/client')
|
||||||
// var esClient = require('eventstore-node'); // Otherwise
|
const client = require("eventstore-node")
|
||||||
var uuid = require('uuid');
|
const uuid = require("uuid")
|
||||||
|
|
||||||
var esConnection = esClient.createConnection({}, {"host": "localhost", "port": 1113});
|
const settings = {}
|
||||||
esConnection.connect();
|
const endpoint = { host: "localhost", port: 1113 }
|
||||||
esConnection.once('connected', function (tcpEndPoint) {
|
const connection = client.createConnection(settings, endpoint)
|
||||||
console.log('Connected to eventstore at ' + tcpEndPoint.host + ":" + tcpEndPoint.port);
|
|
||||||
var userId = uuid.v4();
|
|
||||||
// This event could happen as a result of (e.g.) a 'CreateUser(id, username, password)' command.
|
|
||||||
var userCreatedEvent = {
|
|
||||||
id: userId,
|
|
||||||
username: "user" + uuid.v4().substring(0,6), // Hard-to-spell exotic username.
|
|
||||||
password: Math.random().toString() // Hard-to-guess password.
|
|
||||||
};
|
|
||||||
var eventId = uuid.v4();
|
|
||||||
var event = esClient.createJsonEventData(eventId, userCreatedEvent, null, "UserCreated");
|
|
||||||
// Every user has her/his own stream of events:
|
|
||||||
var streamName = "user-" + userId;
|
|
||||||
console.log("Storing event. Look for it at http://localhost:2113/web/index.html#/streams/user-" + userId);
|
|
||||||
esConnection.appendToStream(streamName, esClient.expectedVersion.any, event)
|
|
||||||
.then(function(result) {
|
|
||||||
console.log("Event stored.");
|
|
||||||
process.exit(0);
|
|
||||||
})
|
|
||||||
.catch(function(err) {
|
|
||||||
console.log(err);
|
|
||||||
process.exit(-1);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
esConnection.on('error', function (err) {
|
connection.connect().catch(err => console.log(err))
|
||||||
console.log('Error occurred on connection:', err);
|
|
||||||
process.exit(-1);
|
|
||||||
});
|
|
||||||
|
|
||||||
esConnection.on('closed', function (reason) {
|
connection.once("connected", tcpEndPoint => {
|
||||||
console.log('Connection closed, reason:', reason);
|
const userId = uuid.v4()
|
||||||
process.exit(-1);
|
|
||||||
});
|
const userCreatedEvent = {
|
||||||
|
id: userId,
|
||||||
|
username: `user${uuid.v4().substring(0,6)}`,
|
||||||
|
password: Math.random().toString()
|
||||||
|
}
|
||||||
|
|
||||||
|
const event = client.createJsonEventData(
|
||||||
|
uuid.v4(),
|
||||||
|
userCreatedEvent,
|
||||||
|
null,
|
||||||
|
"UserCreated"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Every user has their own stream of events:
|
||||||
|
const streamName = `user-${userId}`
|
||||||
|
|
||||||
|
console.log(`Connected to eventstore at ${tcpEndPoint.host}:${tcpEndPoint.port}`)
|
||||||
|
console.log(`Storing event. Look for it at http://localhost:2113/web/index.html#/streams/user-${userId}`)
|
||||||
|
|
||||||
|
connection.appendToStream(streamName, client.expectedVersion.any, event)
|
||||||
|
.then(result => {
|
||||||
|
console.log("Event stored.")
|
||||||
|
process.exit(0)
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.log(error)
|
||||||
|
process.exit(-1)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
connection.on("error", error => {
|
||||||
|
console.log(`Error occurred on connection: ${error}`)
|
||||||
|
process.exit(-1)
|
||||||
|
})
|
||||||
|
|
||||||
|
connection.on("closed", reason => {
|
||||||
|
console.log(`Connection closed, reason: ${reason}`)
|
||||||
|
process.exit(-1)
|
||||||
|
})
|
||||||
|
|
|
@ -1,48 +1,51 @@
|
||||||
// Subscribe to all new events on the $all stream. Filter out any which aren't about "user" aggregates.
|
// Subscribe to all new events on the $all stream. Filter out any which aren"t about "user" aggregates.
|
||||||
|
|
||||||
var esClient = require('../src/client'); // When running in 'eventstore-node/samples' folder.
|
// const client = require('../src/client')
|
||||||
// var esClient = require('eventstore-node'); // Otherwise
|
const client = require("eventstore-node")
|
||||||
|
|
||||||
const credentialsForAllEventsStream = new esClient.UserCredentials("admin", "changeit");
|
const resolveLinkTos = false
|
||||||
const resolveLinkTos = false;
|
|
||||||
|
|
||||||
var esConnection = esClient.createConnection({}, {"host": "localhost", "port": 1113});
|
const belongsToAUserAggregate = event =>
|
||||||
esConnection.connect();
|
event.originalEvent.eventStreamId.startsWith("user-")
|
||||||
esConnection.once('connected', function (tcpEndPoint) {
|
|
||||||
console.log('Connected to eventstore at ' + tcpEndPoint.host + ":" + tcpEndPoint.port);
|
|
||||||
esConnection.subscribeToAll(resolveLinkTos, eventAppeared, subscriptionDropped, credentialsForAllEventsStream)
|
|
||||||
.then(function(subscription) {
|
|
||||||
console.log("subscription.isSubscribedToAll: " + subscription.isSubscribedToAll);
|
|
||||||
console.log("(To generate a test event, try running 'node store-event.js' in a separate console.)")
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
function belongsToAUserAggregate(event) {
|
const eventAppeared = (subscription, event) => {
|
||||||
return event.originalEvent.eventStreamId.startsWith("user-")
|
if (belongsToAUserAggregate(event)) {
|
||||||
|
const aggregateId = event.originalEvent.eventStreamId
|
||||||
|
const eventId = event.originalEvent.eventId
|
||||||
|
const eventType = event.originalEvent.eventType
|
||||||
|
console.log(aggregateId, eventType, eventId)
|
||||||
|
console.log(event.originalEvent.data.toString())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function eventAppeared(subscription, event) {
|
const subscriptionDropped = (subscription, reason, error) =>
|
||||||
// Ignore all events which aren't about users:
|
console.log(error ? error : "Subscription dropped.")
|
||||||
if(belongsToAUserAggregate(event)) {
|
|
||||||
var aggregateId = event.originalEvent.eventStreamId;
|
|
||||||
var eventId = event.originalEvent.eventId;
|
|
||||||
var eventType = event.originalEvent.eventType;
|
|
||||||
console.log(aggregateId, eventType, eventId);
|
|
||||||
console.log(event.originalEvent.data.toString() + "\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function subscriptionDropped(subscription, reason, error) {
|
const credentials = new client.UserCredentials("admin", "changeit")
|
||||||
if (error) {
|
|
||||||
console.log(error);
|
|
||||||
}
|
|
||||||
console.log('Subscription dropped.');
|
|
||||||
}
|
|
||||||
|
|
||||||
esConnection.on('error', function (err) {
|
const settings = {}
|
||||||
console.log('Error occurred on connection:', err);
|
const endpoint = { host: "localhost", port: 1113 }
|
||||||
});
|
const connection = client.createConnection(settings, endpoint)
|
||||||
|
|
||||||
esConnection.on('closed', function (reason) {
|
connection.connect().catch(err => console.log(err))
|
||||||
console.log('Connection closed, reason:', reason);
|
|
||||||
});
|
connection.once("connected", tcpEndPoint => {
|
||||||
|
console.log(`Connected to eventstore at ${tcpEndPoint.host}:${tcpEndPoint.port}`)
|
||||||
|
connection.subscribeToAll(
|
||||||
|
resolveLinkTos,
|
||||||
|
eventAppeared,
|
||||||
|
subscriptionDropped,
|
||||||
|
credentials
|
||||||
|
).then(subscription => {
|
||||||
|
console.log(`subscription.isSubscribedToAll: ${subscription.isSubscribedToAll}`),
|
||||||
|
console.log("(To generate a test event, try running 'node store-event.js' in a separate console.)")
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
connection.on("error", error =>
|
||||||
|
console.log(`Error occurred on connection: ${error}`)
|
||||||
|
)
|
||||||
|
|
||||||
|
connection.on("closed", reason =>
|
||||||
|
console.log(`Connection closed, reason: ${reason}`)
|
||||||
|
)
|
||||||
|
|
|
@ -1,51 +1,49 @@
|
||||||
// Subscribe to all events on the $all stream. Catch up from the beginning, then listen for any new events as they occur.
|
// Subscribe to all events on the $all stream. Catch up from the beginning, then listen for any new events as they occur.
|
||||||
// This can be used (e.g.) for subscribers which populate read models.
|
// This could be used for subscribers which populate read models.
|
||||||
|
|
||||||
var esClient = require('../src/client'); // When running in 'eventstore-node/samples' folder.
|
// const client = require('../src/client')
|
||||||
// var esClient = require('eventstore-node'); // Otherwise
|
const client = require("eventstore-node")
|
||||||
|
|
||||||
const credentialsForAllEventsStream = new esClient.UserCredentials("admin", "changeit");
|
const eventAppeared => (stream, event) =>
|
||||||
|
console.log(
|
||||||
|
event.originalEvent.eventStreamId,
|
||||||
|
event.originalEvent.eventId,
|
||||||
|
event.originalEvent.eventType
|
||||||
|
)
|
||||||
|
|
||||||
var esConnection = esClient.createConnection({}, {"host": "localhost", "port": 1113});
|
const liveProcessingStarted = () => {
|
||||||
esConnection.connect();
|
console.log("Caught up with previously stored events. Listening for new events.")
|
||||||
esConnection.once('connected', function (tcpEndPoint) {
|
console.log("(To generate a test event, try running 'node store-event.js' in a separate console.)")
|
||||||
console.log('Connected to eventstore at ' + tcpEndPoint.host + ":" + tcpEndPoint.port);
|
|
||||||
var subscription = esConnection.subscribeToAllFrom(null, true, eventAppeared, liveProcessingStarted, subscriptionDropped, credentialsForAllEventsStream);
|
|
||||||
console.log("subscription.isSubscribedToAll: " + subscription.isSubscribedToAll);
|
|
||||||
});
|
|
||||||
|
|
||||||
function eventAppeared(subscription, event) {
|
|
||||||
// This is where to filter out events which the subscriber isn't interested in.
|
|
||||||
// For an example, see 'subscribe-all-events.js'.
|
|
||||||
console.log(event.originalEvent.eventStreamId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function subscriptionDropped(subscription, reason, error) {
|
const subscriptionDropped = (subscription, reason, error) =>
|
||||||
if (error) {
|
console.log(error ? error : "Subscription dropped.")
|
||||||
console.log(error);
|
|
||||||
}
|
|
||||||
console.log('Subscription dropped.');
|
|
||||||
}
|
|
||||||
|
|
||||||
function liveProcessingStarted() {
|
const credentials = new client.UserCredentials("admin", "changeit")
|
||||||
console.log("Caught up with previously stored events. Listening for new events.");
|
|
||||||
console.log("(To generate a test event, try running 'node store-event.js' in a separate console.)")
|
|
||||||
}
|
|
||||||
|
|
||||||
function eventAppeared(stream, event) {
|
const settings = {}
|
||||||
console.log(event.originalEvent.eventStreamId, event.originalEvent.eventId, event.originalEvent.eventType);
|
const endpoint = { host: "localhost", port: 1113 }
|
||||||
// Data:
|
const connection = client.createConnection(settings, endpoint)
|
||||||
// console.log(event.originalEvent.data.toString());
|
|
||||||
|
|
||||||
// Position in the event stream. Can be persisted and used to catch up with missed events when re-starting subscribers instead of re-reading
|
connection.connect().catch(err => console.log(err))
|
||||||
// all events from the beginning.
|
|
||||||
// console.log(event.originalPosition);
|
|
||||||
}
|
|
||||||
|
|
||||||
esConnection.on('error', function (err) {
|
connection.once("connected", tcpEndPoint => {
|
||||||
console.log('Error occurred on connection:', err);
|
const subscription = connection.subscribeToAllFrom(
|
||||||
});
|
null,
|
||||||
|
true,
|
||||||
|
eventAppeared,
|
||||||
|
liveProcessingStarted,
|
||||||
|
subscriptionDropped,
|
||||||
|
credentials
|
||||||
|
)
|
||||||
|
console.log(`Connected to eventstore at ${tcpEndPoint.host}:${tcpEndPoint.port}`)
|
||||||
|
console.log(`subscription.isSubscribedToAll: ${subscription.isSubscribedToAll}`)
|
||||||
|
})
|
||||||
|
|
||||||
esConnection.on('closed', function (reason) {
|
connection.on("error", err =>
|
||||||
console.log('Connection closed, reason:', reason);
|
console.log(`Error occurred on connection: ${err}`)
|
||||||
});
|
)
|
||||||
|
|
||||||
|
connection.on("closed", reason =>
|
||||||
|
console.log(`Connection closed, reason: ${reason}`)
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user