node-eventstore-client/samples/simple.js

56 lines
1.6 KiB
JavaScript
Raw Normal View History

const client = require('../src/client')
// const client = require("node-eventstore-client")
2017-04-21 02:32:53 +00:00
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")
}
/*
// connecting to Cluster using hard-coded gossip seeds
2017-04-21 02:32:53 +00:00
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)
*/
/*
// connecting to Cluster using dns discovery, note that cluster gossip over external http port not tcp port
const connection = client.createConnection(settings, 'discover://my.dns:2113')
*/
const connection = client.createConnection(settings, 'tcp://localhost:1113')
2017-04-21 02:32:53 +00:00
connection.connect().catch(err => console.log(err))
connection.on("connected", tcpEndPoint => {
console.log(`connected to endPoint ${tcpEndPoint.host}:${tcpEndPoint.port}`)
2017-04-21 02:32:53 +00:00
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))