node-eventstore-client/samples/simple.js

47 lines
1.2 KiB
JavaScript
Raw Normal View History

2017-04-21 02:32:53 +00:00
const client = require("eventstore-node")
const uuid = require("uuid")
2017-04-21 02:32:53 +00:00
const settings = {
verboseLogging: true,
2017-04-21 02:32:53 +00:00
log: new client.FileLogger("./simple-verbose.log")
}
const gossipSeeds = [
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})
]
const connection = client.createConnection(settings, gossipSeeds)
connection.connect().catch(err => console.log(err))
connection.on("connected", endPoint => {
console.log(`connected to endPoint ${endPoint}`)
setInterval(() => {
connection.appendToStream(
`test-${uuid.v4()}`,
client.expectedVersion.noStream,
[
client.createJsonEventData(
uuid.v4(),
{ abc: 123 },
null,
"MyEvent"
)
]
).then(writeResult => console.log(writeResult))
}, 1000)
})
connection.on("error", error =>
console.log(`Error occurred on connection: ${error}`)
)
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))