Spring Integration Kafka Support

org.springframework.integration.kafka.core
Class DefaultConnection

java.lang.Object
  extended by org.springframework.integration.kafka.core.DefaultConnection
All Implemented Interfaces:
Connection

public class DefaultConnection
extends java.lang.Object
implements Connection

A connection to a Kafka broker.

Author:
Marius Bogoevici

Constructor Summary
DefaultConnection(BrokerAddress brokerAddress, java.lang.String clientId, int bufferSize, int soTimeout, int minBytes, int maxWait)
           
 
Method Summary
 void close()
          Closes the connection to the broker.
 Result<java.lang.Void> commitOffsetsForConsumer(java.lang.String consumerId, java.util.Map<Partition,java.lang.Long> offsets)
          Update offsets in the native Kafka offset management system.
 Result<KafkaMessageBatch> fetch(FetchRequest... requests)
          Fetche data from Kafka.
 Result<java.lang.Long> fetchInitialOffset(long referenceTime, Partition... partitions)
          Fetch an actual offset in the partition, immediately before the given reference time, or the smallest and largest value, respectively, if the special values -1 (OffsetRequest.LatestTime()) and -2 (OffsetRequest.LatestTime()) are used .
 Result<java.lang.Long> fetchStoredOffsetsForConsumer(java.lang.String consumerId, Partition... partitions)
          Fetch offsets from the native Kafka offset management system.
 Result<BrokerAddress> findLeaders(java.lang.String... topics)
          Retrieve the leader broker addresses for all the partitions in the given topics.
 BrokerAddress getBrokerAddress()
          The broker address for this consumer
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultConnection

public DefaultConnection(BrokerAddress brokerAddress,
                         java.lang.String clientId,
                         int bufferSize,
                         int soTimeout,
                         int minBytes,
                         int maxWait)
Method Detail

getBrokerAddress

public BrokerAddress getBrokerAddress()
Description copied from interface: Connection
The broker address for this consumer

Specified by:
getBrokerAddress in interface Connection
Returns:
broker address
See Also:
Connection.getBrokerAddress()

close

public void close()
Description copied from interface: Connection
Closes the connection to the broker. No further operations are permitted.

Specified by:
close in interface Connection

fetch

public Result<KafkaMessageBatch> fetch(FetchRequest... requests)
                                throws ConsumerException
Fetche data from Kafka.

Specified by:
fetch in interface Connection
Parameters:
requests - a list of fetch operations
Returns:
a combination of messages and errors, depending on whether the invocation was successful or not
Throws:
ConsumerException - the ConsumerException if any underlying error

fetchStoredOffsetsForConsumer

public Result<java.lang.Long> fetchStoredOffsetsForConsumer(java.lang.String consumerId,
                                                            Partition... partitions)
                                                     throws ConsumerException
Description copied from interface: Connection
Fetch offsets from the native Kafka offset management system.

Specified by:
fetchStoredOffsetsForConsumer in interface Connection
Parameters:
consumerId - the id of the consumer
partitions - the list of partitions whose offsets are queried for
Returns:
any errors, an empty Result in case of success
Throws:
ConsumerException - the ConsumerException if any underlying error

fetchInitialOffset

public Result<java.lang.Long> fetchInitialOffset(long referenceTime,
                                                 Partition... partitions)
                                          throws ConsumerException
Description copied from interface: Connection
Fetch an actual offset in the partition, immediately before the given reference time, or the smallest and largest value, respectively, if the special values -1 (OffsetRequest.LatestTime()) and -2 (OffsetRequest.LatestTime()) are used . To be used to position the initial offset of a read operation.

Specified by:
fetchInitialOffset in interface Connection
Parameters:
referenceTime - The returned values will be before this time, if they exist. The special values -2 (OffsetRequest.LatestTime()) and -1 (OffsetRequest.LatestTime()) are supported.
partitions - the offsets, indexed by Partition
Returns:
any errors, an empty Result in case of success
Throws:
ConsumerException - the ConsumerException if any underlying error
See Also:
Connection.fetchInitialOffset(long, Partition...)

commitOffsetsForConsumer

public Result<java.lang.Void> commitOffsetsForConsumer(java.lang.String consumerId,
                                                       java.util.Map<Partition,java.lang.Long> offsets)
                                                throws ConsumerException
Description copied from interface: Connection
Update offsets in the native Kafka offset management system.

Specified by:
commitOffsetsForConsumer in interface Connection
Parameters:
consumerId - the id of the consumer
offsets - the offsets, indexed by Partition
Returns:
any errors, an empty Result in case of success
Throws:
ConsumerException - the ConsumerException if any underlying error

findLeaders

public Result<BrokerAddress> findLeaders(java.lang.String... topics)
                                  throws ConsumerException
Description copied from interface: Connection
Retrieve the leader broker addresses for all the partitions in the given topics.

Specified by:
findLeaders in interface Connection
Parameters:
topics - the topics whose partitions we query for
Returns:
broker addresses, indexed by Partition
Throws:
ConsumerException - the ConsumerException if any underlying error
See Also:
Connection.findLeaders(String...)

Spring Integration Kafka Support