# Class: KafkaConsumer

## vertx-kafka-client-js/kafka_consumer~ KafkaConsumer

#### new KafkaConsumer()

Vert.x Kafka consumer.

Source:
  - vertx-kafka-client-js/kafka_consumer.js, line 37

### Methods

#### assign(topicPartitions, completionHandler) → {KafkaConsumer}

Manually assign a list of partition to this consumer.

Due to internal buffering of messages, when reassigning the old set of partitions may remain in effect (as observed by the record handler)} until some time after the given `completionHandler` is called. In contrast, the once the given `completionHandler` is called the KafkaConsumer#batchHandler will only see messages consistent with the new set of partitions.

##### Parameters:

Name | Type | Description
--- | --- | ---
`topicPartitions` | Array.<Object> | partitions which want assigned
`completionHandler` | function | handler called on operation completed

Source:
  - vertx-kafka-client-js/kafka_consumer.js, line 240

##### Returns:

current KafkaConsumer instance

Type
  KafkaConsumer

#### assignment(handler) → {KafkaConsumer}

Get the set of partitions currently assigned to this consumer.

##### Parameters:

Name | Type | Description
--- | --- | ---
`handler` | function | handler called on operation completed

Source:
  - vertx-kafka-client-js/kafka_consumer.js, line 276

##### Returns:

current KafkaConsumer instance

Type
  KafkaConsumer

#### batchHandler(handler) → {KafkaConsumer}

Set the handler to be used when batches of messages are fetched from the Kafka server. Batch handlers need to take care not to block the event loop when dealing with large batches. It is better to process records individually using the [#handler(Handler) record handler] KafkaConsumer.

##### Parameters:

Name | Type | Description
--- | --- | ---
`handler` | function | handler called when batches of messages are fetched

Source:
  - vertx-kafka-client-js/kafka_consumer.js, line 585

##### Returns:

current KafkaConsumer instance

Type
  KafkaConsumer

#### beginningOffsets(topicPartition, handler)

Get the first offset for the given partitions.

##### Parameters:

Name | Type | Description
--- | --- | ---
`topicPartition` | Object | the partition to get the earliest offset.
`handler` | function | handler called on operation completed. Returns the earliest available offset for the given partition

Source:
  - vertx-kafka-client-js/kafka_consumer.js, line 665

#### close(completionHandler)

Close the consumer

##### Parameters:

Name | Type | Description
--- | --- | ---
`completionHandler` | function | handler called on operation completed

Source:
  - vertx-kafka-client-js/kafka_consumer.js, line 601

#### commit(completionHandler)

Commit current offsets for all the subscribed list of topics and partition.

##### Parameters:

Name | Type | Description
--- | --- | ---
`completionHandler` | function | handler called on operation completed

Source:
  - vertx-kafka-client-js/kafka_consumer.js, line 518

#### committed(topicPartition, handler)

Get the last committed offset for the given partition (whether the commit happened by this process or another).

##### Parameters:

Name | Type | Description
--- | --- | ---
`topicPartition` | Object | topic partition for getting last committed offset
`handler` | function | handler called on operation completed

Source:
  - vertx-kafka-client-js/kafka_consumer.js, line 540

#### endHandler(endHandler) → {KafkaConsumer}

##### Parameters:

Name | Type | Description
--- | --- | ---
`endHandler` | function |

Source:
  - vertx-kafka-client-js/kafka_consumer.js, line 171

##### Returns:

Type
  KafkaConsumer

#### endOffsets(topicPartition, handler)

Get the last offset for the given partition. The last offset of a partition is the offset of the upcoming message, i.e. the offset of the last available message + 1.

##### Parameters:

Name | Type | Description
--- | --- | ---
`topicPartition` | Object | the partition to get the end offset.
`handler` | function | handler called on operation completed. The end offset for the given partition.

Source:
  - vertx-kafka-client-js/kafka_consumer.js, line 686

#### exceptionHandler(handler) → {KafkaConsumer}

##### Parameters:

Name | Type | Description
--- | --- | ---
`handler` | function |

Source:
  - vertx-kafka-client-js/kafka_consumer.js, line 51

##### Returns:

Type
  KafkaConsumer

#### handler(handler) → {KafkaConsumer}

##### Parameters:

Name | Type | Description
--- | --- | ---
`handler` | function |

Source:
  - vertx-kafka-client-js/kafka_consumer.js, line 67

##### Returns:

Type
  KafkaConsumer

#### offsetsForTimes(topicPartition, timestamp, handler)

Look up the offset for the given partition by timestamp. Note: the result might be null in case for the given timestamp no offset can be found -- e.g., when the timestamp refers to the future

##### Parameters:

Name | Type | Description
--- | --- | ---
`topicPartition` | Object | TopicPartition to query.
`timestamp` | number | Timestamp to be used in the query.
`handler` | function | handler called on operation completed

Source:
  - vertx-kafka-client-js/kafka_consumer.js, line 645

#### partitionsAssignedHandler(handler) → {KafkaConsumer}

Set the handler called when topic partitions are assigned to the consumer

##### Parameters:

Name | Type | Description
--- | --- | ---
`handler` | function | handler called on assigned topic partitions

Source:
  - vertx-kafka-client-js/kafka_consumer.js, line 378

##### Returns:

current KafkaConsumer instance

Type
  KafkaConsumer

#### partitionsFor(topic, handler) → {KafkaConsumer}

Get metadata about the partitions for a given topic.

##### Parameters:

Name | Type | Description
--- | --- | ---
`topic` | string | topic partition for which getting partitions info
`handler` | function | handler called on operation completed

Source:
  - vertx-kafka-client-js/kafka_consumer.js, line 561

##### Returns:

current KafkaConsumer instance

Type
  KafkaConsumer

#### partitionsRevokedHandler(handler) → {KafkaConsumer}

Set the handler called when topic partitions are revoked to the consumer

##### Parameters:

Name | Type | Description
--- | --- | ---
`handler` | function | handler called on revoked topic partitions

Source:
  - vertx-kafka-client-js/kafka_consumer.js, line 361

##### Returns:

current KafkaConsumer instance

Type
  KafkaConsumer

#### pause(topicPartitions, completionHandler) → {KafkaConsumer}

Suspend fetching from the requested partitions.

Due to internal buffering of messages, the will continue to observe messages from the given `topicParations` until some time after the given `completionHandler` is called. In contrast, the once the given `completionHandler` is called the KafkaConsumer#batchHandler will not see messages from the given `topicParations`.

##### Parameters:

Name | Type | Description
--- | --- | ---
`topicPartitions` | Array.<Object> | topic partition from which suspend fetching
`completionHandler` | function | handler called on operation completed

Source:
  - vertx-kafka-client-js/kafka_consumer.js, line 93

##### Returns:

current KafkaConsumer instance

Type
  KafkaConsumer

#### paused(handler)

Get the set of partitions that were previously paused by a call to pause(Set).

##### Parameters:

Name | Type | Description
--- | --- | ---
`handler` | function | handler called on operation completed

Source:
  - vertx-kafka-client-js/kafka_consumer.js, line 341

#### pollTimeout(timeout) → {KafkaConsumer}

Sets the poll timeout (in ms) for the underlying native Kafka Consumer. Defaults to 1000. Setting timeout to a lower value results in a more 'responsive' client, because it will block for a shorter period if no data is available in the assigned partition and therefore allows subsequent actions to be executed with a shorter delay. At the same time, the client will poll more frequently and thus will potentially create a higher load on the Kafka Broker.

##### Parameters:

Name | Type | Description
--- | --- | ---
`timeout` | number | The time, in milliseconds, spent waiting in poll if data is not available in the buffer. If 0, returns immediately with any records that are available currently in the native Kafka consumer's buffer, else returns empty. Must not be negative.

Source:
  - vertx-kafka-client-js/kafka_consumer.js, line 709

##### Returns:

Type
  KafkaConsumer

#### position(partition, handler)

Get the offset of the next record that will be fetched (if a record with that offset exists).

##### Parameters:

Name | Type | Description
--- | --- | ---
`partition` | Object | The partition to get the position for
`handler` | function | handler called on operation completed

Source:
  - vertx-kafka-client-js/kafka_consumer.js, line 623

#### resume(topicPartitions, completionHandler) → {KafkaConsumer}

Resume specified partitions which have been paused with pause.

##### Parameters:

Name | Type | Description
--- | --- | ---
`topicPartitions` | Array.<Object> | topic partition from which resume fetching
`completionHandler` | function | handler called on operation completed

Source:
  - vertx-kafka-client-js/kafka_consumer.js, line 133

##### Returns:

current KafkaConsumer instance

Type
  KafkaConsumer

#### seek(topicPartition, offset, completionHandler) → {KafkaConsumer}

Overrides the fetch offsets that the consumer will use on the next poll.

Due to internal buffering of messages, the will continue to observe messages fetched with respect to the old offset until some time after the given `completionHandler` is called. In contrast, the once the given `completionHandler` is called the KafkaConsumer#batchHandler will only see messages consistent with the new offset.

##### Parameters:

Name | Type | Description
--- | --- | ---
`topicPartition` | Object | topic partition for which seek
`offset` | number | offset to seek inside the topic partition
`completionHandler` | function | handler called on operation completed

Source:
  - vertx-kafka-client-js/kafka_consumer.js, line 405

##### Returns:

current KafkaConsumer instance

Type
  KafkaConsumer

#### seekToBeginning(topicPartitions, completionHandler) → {KafkaConsumer}

Seek to the first offset for each of the given partitions.

Due to internal buffering of messages, the will continue to observe messages fetched with respect to the old offset until some time after the given `completionHandler` is called. In contrast, the once the given `completionHandler` is called the KafkaConsumer#batchHandler will only see messages consistent with the new offset.

##### Parameters:

Name | Type | Description
--- | --- | ---
`topicPartitions` | Array.<Object> | topic partition for which seek
`completionHandler` | function | handler called on operation completed

Source:
  - vertx-kafka-client-js/kafka_consumer.js, line 438

##### Returns:

current KafkaConsumer instance

Type
  KafkaConsumer

#### seekToEnd(topicPartitions, completionHandler) → {KafkaConsumer}

Seek to the last offset for each of the given partitions.

Due to internal buffering of messages, the will continue to observe messages fetched with respect to the old offset until some time after the given `completionHandler` is called. In contrast, the once the given `completionHandler` is called the KafkaConsumer#batchHandler will only see messages consistent with the new offset.

##### Parameters:

Name | Type | Description
--- | --- | ---
`topicPartitions` | Array.<Object> | topic partition for which seek
`completionHandler` | function | handler called on operation completed

Source:
  - vertx-kafka-client-js/kafka_consumer.js, line 483

##### Returns:

current KafkaConsumer instance

Type
  KafkaConsumer

#### subscribe(topics, completionHandler) → {KafkaConsumer}

Subscribe to the given list of topics to get dynamically assigned partitions.

Due to internal buffering of messages, when changing the subscribed topics the old set of topics may remain in effect (as observed by the record handler}) until some time after the given `completionHandler` is called. In contrast, the once the given `completionHandler` is called the KafkaConsumer#batchHandler will only see messages consistent with the new set of topics.

##### Parameters:

Name | Type | Description
--- | --- | ---
`topics` | Array.<string> | topics to subscribe to
`completionHandler` | function | handler called on operation completed

Source:
  - vertx-kafka-client-js/kafka_consumer.js, line 195

##### Returns:

current KafkaConsumer instance

Type
  KafkaConsumer

#### subscription(handler) → {KafkaConsumer}

Get the current subscription.

##### Parameters:

Name | Type | Description
--- | --- | ---
`handler` | function | handler called on operation completed

Source:
  - vertx-kafka-client-js/kafka_consumer.js, line 321

##### Returns:

current KafkaConsumer instance

Type
  KafkaConsumer

#### unsubscribe(completionHandler) → {KafkaConsumer}

Unsubscribe from topics currently subscribed with subscribe.

##### Parameters:

Name | Type | Description
--- | --- | ---
`completionHandler` | function | handler called on operation completed

Source:
  - vertx-kafka-client-js/kafka_consumer.js, line 297

##### Returns:

current KafkaConsumer instance

Type
  KafkaConsumer