new Client(globalConf, SubClientType, topicConf)
Base class for Consumer and Producer This should not be created independently, but rather is the base class on which both producer and consumer get their common functionality.
Parameters:
Name | Type | Description |
---|---|---|
globalConf | object | Global configuration in key value pairs. |
SubClientType | function | The function representing the subclient type. In C++ land this needs to be a class that inherits from Connection. |
topicConf | object | Topic configuration in key value pairs |
- Source:
Extends:
- Emitter
Members:
_metadata :Client~Metadata
Metadata object. Starts out empty but will be filled with information after the initial connect.
Type:
- Source:
Methods:
connect(metadataOptions, cb) → {Client}
Connect to the broker and receive its metadata. Connects to a broker by establishing the client and fetches its metadata.
Parameters:
Name | Type | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
metadataOptions | object | Options to be sent to the metadata.
Properties
|
||||||||||||
cb | Client~connectionCallback | Callback that indicates we are done connecting. |
- Source:
Returns:
- Type
- Client
connectedTime() → {number}
Find out how long we have been connected to Kafka.
- Source:
Returns:
- Type
- number
disconnect() → {function}
Disconnect from the Kafka client. This method will disconnect us from Kafka unless we are already in a disconnecting state. Use this when you're done reading or producing messages on a given client. It will also emit the disconnected event.
- Source:
Fires:
Returns:
- Type
- function
getClient() → {Connection}
Get the native Kafka client. You probably shouldn't use this, but if you want to execute methods directly on the c++ wrapper you can do it here.
- Source:
- See:
-
- connection.cc
Returns:
- Type
- Connection
getLastError() → {LibrdKafkaError}
Get the last error emitted if it exists.
- Source:
Returns:
- Type
- LibrdKafkaError
getMetadata(metadataOptions, cb)
Get client metadata.
Note: using a metadataOptions.topic
parameter has a potential side-effect.
A Topic object will be created, if it did not exist yet, with default options
and it will be cached by librdkafka.
A subsequent call to create the topic object with specific options (e.g. acks
) will return
the previous instance and the specific options will be silently ignored.
To avoid this side effect, the topic object can be created with the expected options before requesting metadata,
or the metadata request can be performed for all topics (by omitting metadataOptions.topic
).
Parameters:
Name | Type | Description | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
metadataOptions | object | Metadata options to pass to the client.
Properties
|
|||||||||
cb | Client~metadataCallback | Callback to fire with the metadata. |
- Source:
isConnected() → {boolean}
Whether or not we are connected to Kafka.
- Source:
Returns:
- Type
- boolean
offsetsForTimes(toppars, timeout, cb)
Query offsets for times from the broker. This function makes a call to the broker to get the offsets for times specified.
Parameters:
Name | Type | Description |
---|---|---|
toppars | Array.<TopicPartition> | Array of topic partitions. The offset in these should instead refer to a timestamp you want offsets for |
timeout | number | Number of ms to wait to recieve a response. |
cb | Client~offsetsForTimesCallback | Callback to fire with the filled in offsets. |
- Source:
queryWatermarkOffsets(topic, partition, timeout, cb)
Query offsets from the broker. This function makes a call to the broker to get the current low (oldest/beginning) and high (newest/end) offsets for a topic partition.
Parameters:
Name | Type | Description |
---|---|---|
topic | string | Topic to recieve offsets from. |
partition | number | Partition of the provided topic to recieve offsets from |
timeout | number | Number of ms to wait to recieve a response. |
cb | Client~watermarkOffsetsCallback | Callback to fire with the offsets. |
- Source:
Type Definitions:
connectionCallback(err, metadata)
This callback is used to pass metadata or an error after a successful connection
Parameters:
Name | Type | Description |
---|---|---|
err | Error | An error, if one occurred while connecting. |
metadata | Client~Metadata | Metadata object. |
- Source:
Metadata
Metadata object. This is the representation of Kafka metadata in JavaScript.
Type:
- object
Properties:
Name | Type | Description |
---|---|---|
orig_broker_id | number | The broker ID of the original bootstrap broker. |
orig_broker_name | string | The name of the original bootstrap broker. |
brokers | Array.<Client~MetadataBroker> | An array of broker objects |
topics | Array.<Client~MetadataTopic> | An array of topics. |
- Source:
MetadataBroker
Type:
- object
Properties:
Name | Type | Description |
---|---|---|
id | number | Broker ID |
host | string | Broker host |
port | number | Broker port. |
- Source:
MetadataPartition
Type:
- object
Properties:
Name | Type | Description |
---|---|---|
id | number | Partition id |
leader | number | Broker ID for the partition leader |
replicas | Array.<number> | Array of replica IDs |
isrs | Array.<number> | Arrqay of ISRS ids |
- Source:
MetadataTopic
Type:
- object
Properties:
Name | Type | Description |
---|---|---|
name | string | Topic name |
partitions | Array.<Client~MetadataPartition> | Array of partitions |
- Source:
offsetsForTimesCallback(err, toppars)
This callback is used to pass toppars or an error after a successful times query
Parameters:
Name | Type | Description |
---|---|---|
err | Error | An error, if one occurred while connecting. |
toppars | Array.<TopicPartition> | Topic partitions with offsets filled in |
- Source:
watermarkOffsets
Type:
- object
Properties:
Name | Type | Description |
---|---|---|
high | number | High (newest/end) offset |
low | number | Low (oldest/beginning) offset |
- Source:
watermarkOffsetsCallback(err, offsets)
This callback is used to pass offsets or an error after a successful query
Parameters:
Name | Type | Description |
---|---|---|
err | Error | An error, if one occurred while connecting. |
offsets | Client~watermarkOffsets | Watermark offsets |
- Source:
Events
disconnected
Disconnect event. Called after disconnection is finished.
Type:
- object
Properties:
Name | Type | Description |
---|---|---|
connectionOpened | date | when the connection was opened. |
- Source:
ready
Ready event. Called when the Client connects successfully
Type:
- object
Properties:
Name | Type | Description |
---|---|---|
name | string | the name of the broker. |
- Source: