nodeJS GRPC Producer

nodeJS GRPC Producer

Producing Facts via nodeJS is very simple due to the available gRPC NPM Module. It will generate a stub constructor called RemoteFactStore from our proto file.

const uuidV4 = require('uuid/v4');
const grpc = require('grpc');
const protoDescriptor = grpc.load('./FactStore.proto');
const RemoteFactStore = protoDescriptor.org.factcast.grpc.api.gen.RemoteFactStore;

// store allows us to publish, subscribe and fetchById (see proto file)
const store = new RemoteFactStore('localhost:9090', grpc.credentials.createInsecure());

store.publish([{
  header: JSON.stringify({
    id: uuidV4(),
    ns: 'myapp'
  }),
  payload: JSON.stringify({
    foo: Date.now()
  })
}], (err, feature) => {
  if (err) {
    console.log(err)
  }
})

See the Facts page for detailed information about all possible and required header fields.