mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-08-28 12:43:06 +08:00
Merge pull request #3858 from dansitu/master
Added definitions for kafka-node library
This commit is contained in:
@@ -0,0 +1,157 @@
|
||||
/// <reference path="kafka-node.d.ts" />
|
||||
|
||||
import kafka = require('kafka-node');
|
||||
|
||||
var basicClient = new kafka.Client('localhost:2181/', 'sendMessage');
|
||||
|
||||
var optionsClient = new kafka.Client('localhost:2181/', 'sendMessage', {
|
||||
sessionTimeout: 30000,
|
||||
spinDelay: 1000,
|
||||
retries: 0
|
||||
});
|
||||
optionsClient.close();
|
||||
optionsClient.close(function(){});
|
||||
|
||||
var producer = new kafka.Producer(basicClient);
|
||||
producer.on('error', function(error: Error){});
|
||||
producer.on('ready', function(){
|
||||
|
||||
var messages = [{
|
||||
topic: 'topicName',
|
||||
messages: ['message body'],
|
||||
partition: 0,
|
||||
attributes: 2
|
||||
}, {
|
||||
topic: 'topicName',
|
||||
messages: ['message body'],
|
||||
partition: 0
|
||||
}, {
|
||||
topic: 'topicName',
|
||||
messages: ['message body'],
|
||||
attributes: 0
|
||||
}, {
|
||||
topic: 'topicName',
|
||||
messages: ['message body']
|
||||
}, {
|
||||
topic: 'topicName',
|
||||
messages: [new kafka.KeyedMessage('key', 'message')]
|
||||
}];
|
||||
|
||||
producer.send(messages, function(err: Error){});
|
||||
producer.send(messages, function(err: Error, data: Object){});
|
||||
|
||||
producer.createTopics(['t'], true, function (err: Error, data: Object) {});
|
||||
producer.createTopics(['t'], false, function (err, data) {});
|
||||
// producer.createTopics(['t'], function (err: Error, data: Object) {}); // Omitting middle argument is not possible in TS
|
||||
|
||||
});
|
||||
|
||||
var highLevelProducer = new kafka.HighLevelProducer(basicClient);
|
||||
highLevelProducer.on('error', function(error: Error){});
|
||||
highLevelProducer.on('ready', function(){
|
||||
|
||||
var messages = [{
|
||||
topic: 'topicName',
|
||||
messages: ['message body'],
|
||||
attributes: 2
|
||||
}, {
|
||||
topic: 'topicName',
|
||||
messages: ['message body'],
|
||||
partition: 0
|
||||
}, {
|
||||
topic: 'topicName',
|
||||
messages: ['message body'],
|
||||
attributes: 0
|
||||
}, {
|
||||
topic: 'topicName',
|
||||
messages: ['message body']
|
||||
}, {
|
||||
topic: 'topicName',
|
||||
messages: [new kafka.KeyedMessage('key', 'message')]
|
||||
}];
|
||||
|
||||
producer.send(messages, function(err: Error){});
|
||||
producer.send(messages, function(err: Error, data: Object){});
|
||||
|
||||
producer.createTopics(['t'], true, function (err: Error, data: Object) {});
|
||||
producer.createTopics(['t'], false, function (err, data) {});
|
||||
// producer.createTopics(['t'], function (err: Error, data: Object) {}); // Omitting middle argument is not possible in TS
|
||||
|
||||
});
|
||||
|
||||
var fetchRequests = [{ topic: 'awesome' }];
|
||||
var consumer = new kafka.Consumer(basicClient, fetchRequests, {
|
||||
groupId: 'abcde',
|
||||
autoCommit: true
|
||||
});
|
||||
consumer.on('error', function(error: Error){});
|
||||
consumer.on('message', function(message){});
|
||||
|
||||
consumer.addTopics(['t1', 't2'], function (err, added) {});
|
||||
consumer.addTopics([{ topic: 't1', offset: 10 }], function (err, added) {}, true);
|
||||
|
||||
consumer.removeTopics(['t1', 't2'], function (err, removed) {});
|
||||
|
||||
consumer.commit(function (err, data) {});
|
||||
|
||||
consumer.setOffset('topic', 0, 0);
|
||||
|
||||
consumer.pause();
|
||||
consumer.resume();
|
||||
consumer.pauseTopics([
|
||||
'topic1',
|
||||
{ topic: 'topic2', partition: 0 }
|
||||
]);
|
||||
consumer.resumeTopics([
|
||||
'topic1',
|
||||
{ topic: 'topic2', partition: 0 }
|
||||
]);
|
||||
|
||||
consumer.close(true, function () {});
|
||||
|
||||
var fetchRequests = [{ topic: 'awesome' }];
|
||||
var hlConsumer = new kafka.HighLevelConsumer(basicClient, fetchRequests, {
|
||||
groupId: 'abcde',
|
||||
autoCommit: true
|
||||
});
|
||||
|
||||
hlConsumer.on('error', function(error: Error){});
|
||||
hlConsumer.on('message', function(message){});
|
||||
hlConsumer.addTopics(['t1', 't2'], function (err, added) {});
|
||||
hlConsumer.addTopics([{ topic: 't1', offset: 10 }], function (err, added) {}, true);
|
||||
|
||||
hlConsumer.removeTopics(['t1', 't2'], function (err, removed) {});
|
||||
|
||||
hlConsumer.commit(function (err, data) {});
|
||||
|
||||
hlConsumer.setOffset('topic', 0, 0);
|
||||
|
||||
hlConsumer.pause();
|
||||
hlConsumer.resume();
|
||||
hlConsumer.pauseTopics([
|
||||
'topic1',
|
||||
{ topic: 'topic2', partition: 0 }
|
||||
]);
|
||||
hlConsumer.resumeTopics([
|
||||
'topic1',
|
||||
{ topic: 'topic2', partition: 0 }
|
||||
]);
|
||||
|
||||
hlConsumer.close(true, function () {});
|
||||
|
||||
var offset = new kafka.Offset(basicClient);
|
||||
|
||||
offset.on('ready', function(){});
|
||||
|
||||
offset.fetch([
|
||||
{ topic: 't', partition: 0, time: Date.now(), maxNum: 1 },
|
||||
{ topic: 't' }
|
||||
], function (err, data) { });
|
||||
|
||||
offset.commit('groupId', [
|
||||
{ topic: 't', partition: 0, offset: 10 }
|
||||
], function (err, data) { });
|
||||
|
||||
offset.fetchCommits('groupId', [
|
||||
{ topic: 't', partition: 0 }
|
||||
], function (err, data) {});
|
||||
Vendored
+123
@@ -0,0 +1,123 @@
|
||||
// Type definitions for kafka-node 0.2.22
|
||||
// Project: https://github.com/SOHU-Co/kafka-node/
|
||||
// Definitions by: Daniel Imrie-Situnayake <https://github.com/dansitu/>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
declare module 'kafka-node' {
|
||||
|
||||
// # Classes
|
||||
export class Client {
|
||||
constructor(connectionString: string, clientId: string, options?: ZKOptions);
|
||||
close(callback?: Function): void;
|
||||
}
|
||||
|
||||
export class Producer {
|
||||
constructor(client: Client);
|
||||
on(eventName: string, cb: () => any): void;
|
||||
on(eventName: string, cb: (error: any) => any): void;
|
||||
send(payloads: Array<ProduceRequest>, cb: (error: any, data: any) => any): void;
|
||||
createTopics(topics: Array<string>, async: boolean, cb?: (error: any, data: any) => any): void;
|
||||
}
|
||||
|
||||
export class HighLevelProducer {
|
||||
constructor(client: Client);
|
||||
on(eventName: string, cb: () => any): void;
|
||||
on(eventName: string, cb: (error: any) => any): void;
|
||||
send(payloads: Array<ProduceRequest>, cb: (error: any, data: any) => any): void;
|
||||
createTopics(topics: Array<string>, async: boolean, cb?: (error: any, data: any) => any): void;
|
||||
}
|
||||
|
||||
export class Consumer {
|
||||
constructor(client: Client, fetchRequests: Array<Topic>, options: ConsumerOptions);
|
||||
on(eventName: string, cb: (message: string) => any): void;
|
||||
on(eventName: string, cb: (error: any) => any): void;
|
||||
addTopics(topics: Array<string>, cb: (error: any, added: boolean) => any): void;
|
||||
addTopics(topics: Array<Topic>, cb: (error: any, added: boolean) => any, fromOffset: boolean): void;
|
||||
removeTopics(topics: Array<string>, cb: (error: any, removed: boolean) => any): void;
|
||||
commit(cb: (error: any, data: any) => any): void;
|
||||
setOffset(topic: string, partition: number, offset: number): void;
|
||||
pause(): void;
|
||||
resume(): void;
|
||||
pauseTopics(topics: Array<any> /* Array<string|Topic> */): void;
|
||||
resumeTopics(topics: Array<any> /* Array<string|Topic> */): void;
|
||||
close(force: boolean, cb: () => any): void;
|
||||
}
|
||||
|
||||
export class HighLevelConsumer {
|
||||
constructor(client: Client, payloads: Array<Topic>, options: ConsumerOptions);
|
||||
on(eventName: string, cb: (message: string) => any): void;
|
||||
on(eventName: string, cb: (error: any) => any): void;
|
||||
addTopics(topics: Array<string>, cb: (error: any, added: boolean) => any): void;
|
||||
addTopics(topics: Array<Topic>, cb: (error: any, added: boolean) => any, fromOffset: boolean): void;
|
||||
removeTopics(topics: Array<string>, cb: (error: any, removed: boolean) => any): void;
|
||||
commit(cb: (error: any, data: any) => any): void;
|
||||
setOffset(topic: string, partition: number, offset: number): void;
|
||||
pause(): void;
|
||||
resume(): void;
|
||||
pauseTopics(topics: Array<any> /* Array<string|Topic> */): void;
|
||||
resumeTopics(topics: Array<any> /* Array<string|Topic> */): void;
|
||||
close(force: boolean, cb: () => any): void;
|
||||
}
|
||||
|
||||
export class Offset {
|
||||
constructor(client: Client);
|
||||
on(eventName: string, cb: () => any): void;
|
||||
fetch(payloads: Array<OffsetRequest>, cb: (error: any, data: any) => any): void;
|
||||
commit(groupId: string, payloads: Array<OffsetCommitRequest>, cb: (error: any, data: any) => any): void;
|
||||
fetchCommits(groupId: string, payloads: Array<OffsetFetchRequest>, cb: (error: any, data: any) => any): void;
|
||||
}
|
||||
|
||||
export class KeyedMessage {
|
||||
constructor(key: string, message: string);
|
||||
}
|
||||
|
||||
// # Interfaces
|
||||
export interface ZKOptions {
|
||||
sessionTimeout?: number;
|
||||
spinDelay?: number;
|
||||
retries?: number;
|
||||
}
|
||||
|
||||
export interface ProduceRequest {
|
||||
topic: string;
|
||||
messages: any; // Array<string> | Array<KeyedMessage> | string | KeyedMessage
|
||||
partition?: number;
|
||||
attributes?: number;
|
||||
}
|
||||
|
||||
export interface ConsumerOptions {
|
||||
groupId?: string;
|
||||
autoCommit?: boolean;
|
||||
autoCommitIntervalMs?: number;
|
||||
fetchMaxWaitMs?: number;
|
||||
fetchMinBytes?: number;
|
||||
fetchMaxBytes?: number;
|
||||
fromOffset?: boolean;
|
||||
encoding?: string;
|
||||
}
|
||||
|
||||
export interface Topic {
|
||||
topic: string;
|
||||
offset?: number;
|
||||
}
|
||||
|
||||
export interface OffsetRequest {
|
||||
topic: string;
|
||||
partition?: number;
|
||||
time?: number;
|
||||
maxNum?: number;
|
||||
}
|
||||
|
||||
export interface OffsetCommitRequest {
|
||||
topic: string;
|
||||
partition?: number;
|
||||
offset: number;
|
||||
metadata?: string;
|
||||
}
|
||||
|
||||
export interface OffsetFetchRequest {
|
||||
topic: string;
|
||||
partition?: number;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user