1.1.4 • Published 5 years ago
@inspr/chimera-client-ts v1.1.4
@inspr/chimera-client-ts
Install
# change npm version to lts (required by node-rdkafka)
npm install -g n
n lts
# install Chimera typescript client
npm install @inspr/chimera-client-ts
Usage
Let's see how to read and write messages on Chimera
channels using the ping pong application:
Writer
import { Writer } from '@inspr/chimera-client-ts/'
class Ping {
writer: Writer
constructor() {
// Instantiate the Writer class
this.writer = new Writer()
}
run(turn: number) {
// Write object in the ping_out channel
this.writer.writeMessage(
{
player: "player1",
turn: turn
},
"ping_out"
)
}
}
Reader
import { Reader } from '@inspr/chimera-client-ts'
class Pong {
reader: Reader
constructor() {
// Instantiate the Reader class
this.reader = new Reader()
}
functionrun() {
// Read message
this.reader.readMessage()
.then(([channel, msg]) => {
console.log(channel)
console.log(msg)
})
.catch((err) => {
console.log(err)
})
}
}