Skip to content

Instantly share code, notes, and snippets.

View thakursaurabh1998's full-sized avatar
Getting Better

Saurabh Thakur thakursaurabh1998

Getting Better
View GitHub Profile
const async = require('async');
const { ConsumerGroup } = require('kafka-node');
const consumerConfig = {
kafkaHost: 'broker:9092',
groupId: 'order-service',
fetchMaxBytes: 100 * 1024, // 100 KB
autoCommit: false,
};
const { ConsumerGroup } = require('kafka-node');
const options = {
kafkaHost: 'broker:9092',
groupId: 'order-service',
fetchMaxBytes: 100 * 1024, // 100 KB
autoCommit: false,
};
const consumer = new ConsumerGroup(options, 'OrderTopic');
consumer.on('message', (data) => {
consumer.pause();
const { ConsumerGroup } = require('kafka-node');
const options = {
kafkaHost: 'broker:9092',
groupId: 'order-service',
fetchMaxBytes: 100 * 1024, // 100 KB
autoCommit: false,
};
const consumer = new ConsumerGroup(options, 'OrderTopic');
const { ConsumerGroup } = require('kafka-node');
const options = {
kafkaHost: 'broker:9092',
groupId: 'order-service',
fetchMaxBytes: 100 * 1024, // 100 KB
};
const consumer = new ConsumerGroup(options, 'OrderTopic');
@thakursaurabh1998
thakursaurabh1998 / throttle1.js
Last active August 9, 2020 15:26
Kafka Throttle
const { ConsumerGroup } = require('kafka-node');
const options = {
kafkaHost: 'broker:9092',
groupId: 'order-service',
};
const consumer = new ConsumerGroup(options, 'OrderTopic');
consumer.on('message', (data) => {
@thakursaurabh1998
thakursaurabh1998 / sha256-hmac.md
Created July 14, 2020 13:39 — forked from jasny/sha256-hmac.md
Hashing examples in different languages

Example inputs:

Variable Value
key the shared secret key here
message the message to hash here

Reference outputs for example inputs above:

| Type | Hash |

const _ = require('underscore');
const { query, model, operation } = offer.eligibility;
// the query is parsed because the query string in
// the offer document is an undercore string template where
// the variables can be replaced with the provided value
const parsedQuery = JSON.parse(
_.template(query)({
brokeruserId: event.data.brokeruserId,
})
{
"meta": {
"cta": {
"primary": {
"text": "See smallcases",
"action": "DISCOVER",
"query": "scids=SCAW_0001&scids=SCSB_0001&scids=SCSB_0003&scids=SCSB_0004",
"path": "/discover/all"
},
"secondary": {
{
"status": "AVAILABLE",
"offerCode": "FREE_AWI",
"includedScids": ["SCAW_0001"],
"endDate": ISODate("2020-03-13T10:00:00.000Z"),
"startDate": ISODate("2020-02-23T18:30:00.000Z"),
"discount": {
"type": "percentage",
"value": 1.0
},
@thakursaurabh1998
thakursaurabh1998 / streamFile.js
Created April 14, 2020 09:04
Stream file and create a local buffer, after stream ends, use the buffer accordingly
const readStream = s3Mumbai.getObject(workbookfile).createReadStream();
const buffers = [];
readStream.on('data', data => {
buffers.push(data);
});
readStream.on('error', err => {
next(err);
});