nodeJS GRPC Producer
Producing Facts via Node.js is straightforward with the available gRPC NPM module. It generates a stub constructor
called RemoteFactStore from the FactCast 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.