Last active
September 10, 2021 15:43
-
-
Save nikostoulas/24cd58c780a3665e9a9d9e587b0bf914 to your computer and use it in GitHub Desktop.
RPC with streams example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Reading a local file into a stream | |
const readStream = fs.createReadStream('file.txt'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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