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
const file = await rabbit.getReply(‘readFile’, { | |
correlationId, | |
headers: { backpressure: true, timeout: 1000 }, | |
}); | |
for await (const line of file) { | |
console.log(line); | |
process(line); | |
if(processingHasFinished()) { | |
// send stop signal to producer of the stream which is a different microservice |
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
// boilerplate to connect with RabbitMQ | |
const rabbit = require(‘./connect’); | |
rabbit.createQueue(‘add’, { durable: false }, (msg, ack) => { | |
const numbers = JSON.parse(msg.content.toString()); | |
ack(null, numbers[0] + numbers[1]); | |
}); |
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
const http = require(‘http’); | |
const server = http.createServer((req, res) => { | |
// `req` is an http.IncomingMessage, which is a Readable Stream. | |
// `res` is an http.ServerResponse, which is a Writable Stream. | |
let body = ‘’; | |
// Get the data as utf 8 strings. | |
// If an encoding is not set, Buffer objects will be received. | |
req.setEncoding(‘utf8’); | |
// Readable streams emit ‘data’ events once a listener is added. | |
req.on(‘data’, chunk => { |
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
const https = require('https'); | |
https | |
.get('https://api.nasa.gov/planetary/apod?api_key=DEMO_KEY', resp => { | |
let data = ''; | |
// A chunk of data has been received. | |
resp.on('data', chunk => { | |
data += chunk; | |
}); |
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
let globalPrefetch = 10; | |
async function changePrefetch(prefetchNum) { | |
await new Promise(r => setTimeout(r, 10)); | |
globalPrefetch = prefetchNum; | |
} | |
async function subscribeToQueue(name, prefetch) { | |
await changePrefetch(prefetch); | |
await new Promise(r => setTimeout(r, 20)); | |
console.log(`subscribing to queue ${name} with prefetch ${globalPrefetch}`); |
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
# To make it easier to work on a anti git flow branching model described here: http://endoflineblog.com/gitflow-considered-harmful | |
# the following aliases have been created | |
[alias] | |
lg = log --graph --pretty=format:'%Cred%h%Creset [%C(dim cyan)%ad%Creset] %C(dim green)%an%Creset: %C(bold dim white)%s%Creset %C(auto)%d%Creset' --date=short | |
make-hotfix = !git stash && git hotfix-create $1 && git stash pop && : | |
graph = log --graph --color --pretty=format:'%Cred%h%Creset [%C(dim cyan)%cr%Creset] %C(dim green)%an%Creset: %C(bold dim white)%s%Creset %C(auto)%d%Creset' | |
tree = log --all --graph --decorate=short --color --format=format:'%C(bold blue)%h%C(reset) %C(auto)%d%C(reset)\n %C(dim cyan)[%cr]%C(reset) %x09%C(dim cyan)%an:%C(reset) %C(bold cyan)%s %C(reset)' | |
hotfix-create = "!f() {\ | |
red=`tput setaf 1`;\ | |
yellow=`tput setaf 3`;\ |