Skip to content

Instantly share code, notes, and snippets.

@nikostoulas
Last active September 10, 2021 15:43
Show Gist options
  • Save nikostoulas/24cd58c780a3665e9a9d9e587b0bf914 to your computer and use it in GitHub Desktop.
Save nikostoulas/24cd58c780a3665e9a9d9e587b0bf914 to your computer and use it in GitHub Desktop.
RPC with streams example
// Reading a local file into a stream
const readStream = fs.createReadStream('file.txt');
// The corresponding solution to read a file using a different microservice. (Hypothetical example)
// Reading a local file and exposing this as RPC service
rabbit.createQueue('readFile', { durable: false }, (msg, ack) => {
const readStream = fs.createReadStream(msg.content().toString());
ack(null, readStream);
});
// Requesting a remote file with an RPC call
const readStream = await rabbit.getReply('readFile', 'file.txt');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment