Class: Client

Client

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:
  • Emitter

_metadata :Client~Metadata

Metadata object. Starts out empty but will be filled with information after the initial connect.

Type:
Source:

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
Name Type Description
topic string Topic to fetch metadata for. Empty string is treated as empty.
allTopics boolean Fetch metadata for all topics, not just the ones we know about.
timeout int The timeout, in ms, to allow for fetching metadata. Defaults to 30000ms
cb Client~connectionCallback Callback that indicates we are done connecting.
Source:
Returns:
- Returns itself.
Type
Client

connectedTime() → {number}

Find out how long we have been connected to Kafka.

Source:
Returns:
- Milliseconds since the connection has been established.
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:
- Callback to call when disconnection is complete.
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:
- The native Kafka client.
Type
Connection

getLastError() → {LibrdKafkaError}

Get the last error emitted if it exists.

Source:
Returns:
- Returns the LibrdKafkaError or null if one hasn't been thrown.
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
Name Type Description
topic string Topic string for which to fetch metadata
timeout number Max time, in ms, to try to fetch metadata before timing out. Defaults to 3000.
cb Client~metadataCallback Callback to fire with the metadata.
Source:

isConnected() → {boolean}

Whether or not we are connected to Kafka.

Source:
Returns:
- Whether we are connected.
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: