Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
no-kafka is Apache Kafka 0.9 client for Node.js with new unified consumer API support. No Zookeeper connection required.
All methods will return a promise
kafka-topics.sh --zookeeper 127.0.0.1:2181 --create --topic kafka-test-topic --partitions 3 --replication-factor 1
Example:
var Kafka = require('no-kafka');
var producer = new Kafka.Producer();
return producer.init().then(function(){
return producer.send({
topic: 'kafka-test-topic',
partition: 0,
message: {
value: 'Hello!'
}
});
})
.then(function (result) {
/*
{ ok: [ { topic: 'kafka-test-topic', partition: 0, offset: 353 } ],
errors: [] }
*/
});
Manually specify topic, partition and offset when subscribing. Suitable for simple use cases.
Example:
var consumer = new Kafka.SimpleConsumer();
consumer.on('data', function (messageSet, topic, partition) {
messageSet.forEach(function (m) {
console.log(topic, partition, m.offset, m.message.value.toString('utf8'));
});
});
return consumer.init().then(function () {
return Promise.all([
consumer.subscribe('kafka-test-topic', 0),
consumer.subscribe('kafka-test-topic', 1)
]);
});
Subscribe (or change subscription) to specific offset and limit maximum received MessageSet size:
consumer.subscribe('kafka-test-topic', 0, {offset: 20, maxBytes: 30}
Subscribe to latest or earliest offsets in the topic/parition:
consumer.subscribe('kafka-test-topic', 0, {time: Kafka.LATEST_OFFSET}
consumer.subscribe('kafka-test-topic', 0, {time: Kafka.EARLIEST_OFFSET}
Commit offset(s) (V0, Kafka saves these commits to Zookeeper)
consumer.commitOffset([
{
topic: 'kafka-test-topic',
partition: 0,
offset: 1
},
{
topic: 'kafka-test-topic',
partition: 1,
offset: 2
}
])
Fetch commited offset(s)
consumer.fetchOffset([
{
topic: 'kafka-test-topic',
partition: 0
},
{
topic: 'kafka-test-topic',
partition: 1
}
]).then(function (result) {
/*
[ { topicName: 'kafka-test-topic',
partitions:
[ { partition: 0,
offset: 1,
metadata: null,
error: null },
{ partition: 1,
offset: 2,
metadata: null,
error: null },
]
},
]
*/
});
Specify an assignment strategy (or use no-kafka built-in consistent assignment strategy) and subscribe by specifying only topics. Elected group leader will automatically assign partitions between all group members.
Example:
var consumer = new Kafka.GroupConsumer();
var strategies = [{
strategy: 'TestStrategy',
subscriptions: ['kafka-test-topic'],
metadata: {
id: process.argv[2] || 'consumer_1',
weight: 50
}
}];
consumer.on('data', function (messageSet, topic, partition) {
messageSet.forEach(function (m) {
console.log(topic, partition, m.offset, m.message.value.toString('utf8'));
});
});
return consumer.init(strategies).then(function(){
// all done, now wait for messages in event listener
});
no-kafka provides GroupConsumer.ConsistentAssignment
strategy based on a hashring and so providing consistent assignment across consumers in a group based on metadata.id
and metadata.weight
options.
You can write your own assignment strategy function and provide it as fn
options of the strategy item:
var strategies = [{
strategy: 'MyStrategy',
fn: function(subscriptions){} // subscriptions: [{topic:String, members:[], partitions:[]}]
subscriptions: ['kafka-test-topic'],
metadata: new Buffer() // metadata as Buffer or as plain Object required for your assignment function
}];
FAQs
Apache Kafka 0.9 client for Node.JS
The npm package no-kafka receives a total of 4,948 weekly downloads. As such, no-kafka popularity was classified as popular.
We found that no-kafka demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.