Spring Integration Kafka Support

org.springframework.integration.kafka.core
Class DefaultConnectionFactory

java.lang.Object
  extended by org.springframework.integration.kafka.core.DefaultConnectionFactory
All Implemented Interfaces:
org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.InitializingBean, ConnectionFactory

public class DefaultConnectionFactory
extends java.lang.Object
implements org.springframework.beans.factory.InitializingBean, ConnectionFactory, org.springframework.beans.factory.DisposableBean

Default implementation of ConnectionFactory

Author:
Marius Bogoevici

Constructor Summary
DefaultConnectionFactory(Configuration configuration)
           
 
Method Summary
 void afterPropertiesSet()
           
 Connection connect(BrokerAddress brokerAddress)
          Create a connection to a Kafka broker, caching it internally
 void destroy()
           
 java.lang.String getClientId()
           
 Configuration getConfiguration()
           
 BrokerAddress getLeader(Partition partition)
          Return the leader for a single partition
 java.util.Map<Partition,BrokerAddress> getLeaders(java.lang.Iterable<Partition> partitions)
          Retrieve the leaders for a set of partitions.
 java.util.Collection<Partition> getPartitions(java.lang.String topic)
          Retrieves the partitions of a given topic
 void refreshLeaders(java.util.Collection<java.lang.String> topics)
          Refresh the broker connections and partition leader map.
 void setBufferSize(int bufferSize)
          The buffer size for this client
 void setClientId(java.lang.String clientId)
          A client name to be used throughout this connection.
 void setFetchMetadataTimeout(int fetchMetadataTimeout)
          The timeout on fetching metadata (e.g.
 void setMaxWait(int maxWait)
          The maximum amount of time that a server fetch operation will wait before returning (unless minFetchSizeInBytes) are available.
 void setMinBytes(int minBytes)
          The minimum amount of data that a server fetch operation will wait for before returning, unless maxWaitTimeInMs has elapsed.
 void setSocketTimeout(int socketTimeout)
          The socket timeout for this client
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultConnectionFactory

public DefaultConnectionFactory(Configuration configuration)
Method Detail

getConfiguration

public Configuration getConfiguration()

afterPropertiesSet

public void afterPropertiesSet()
                        throws java.lang.Exception
Specified by:
afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
Throws:
java.lang.Exception

destroy

public void destroy()
             throws java.lang.Exception
Specified by:
destroy in interface org.springframework.beans.factory.DisposableBean
Throws:
java.lang.Exception

setMinBytes

public void setMinBytes(int minBytes)
The minimum amount of data that a server fetch operation will wait for before returning, unless maxWaitTimeInMs has elapsed. In conjunction with setMaxWait(int), controls latency and throughput. Smaller values increase responsiveness, but may increase the number of poll operations, potentially reducing throughput and increasing CPU consumption.

Parameters:
minBytes - the amount of data to fetch

setMaxWait

public void setMaxWait(int maxWait)
The maximum amount of time that a server fetch operation will wait before returning (unless minFetchSizeInBytes) are available. In conjunction with setMinBytes(int), controls latency and throughput. Smaller intervals increase responsiveness, but may increase the number of poll operations, potentially increasing CPU consumption and reducing throughput.

Parameters:
maxWait - timeout to wait

getClientId

public java.lang.String getClientId()

setClientId

public void setClientId(java.lang.String clientId)
A client name to be used throughout this connection.

Parameters:
clientId - the client name

setBufferSize

public void setBufferSize(int bufferSize)
The buffer size for this client

Parameters:
bufferSize - the buffer size

setSocketTimeout

public void setSocketTimeout(int socketTimeout)
The socket timeout for this client

Parameters:
socketTimeout - the socket timeout

setFetchMetadataTimeout

public void setFetchMetadataTimeout(int fetchMetadataTimeout)
The timeout on fetching metadata (e.g. partition leaders)

Parameters:
fetchMetadataTimeout - timeout

getLeaders

public java.util.Map<Partition,BrokerAddress> getLeaders(java.lang.Iterable<Partition> partitions)
Description copied from interface: ConnectionFactory
Retrieve the leaders for a set of partitions.

Specified by:
getLeaders in interface ConnectionFactory
Parameters:
partitions - whose leaders are queried
Returns:
the broker associated with the provided topic and partition
See Also:
ConnectionFactory.getLeaders(Iterable)

getLeader

public BrokerAddress getLeader(Partition partition)
Description copied from interface: ConnectionFactory
Return the leader for a single partition

Specified by:
getLeader in interface ConnectionFactory
Parameters:
partition - the partition whose leader is queried
Returns:
the leader's address
See Also:
ConnectionFactory.getLeader(Partition)

connect

public Connection connect(BrokerAddress brokerAddress)
Description copied from interface: ConnectionFactory
Create a connection to a Kafka broker, caching it internally

Specified by:
connect in interface ConnectionFactory
Parameters:
brokerAddress - a broker address
Returns:
a working connection
See Also:
ConnectionFactory.connect(BrokerAddress)

refreshLeaders

public void refreshLeaders(java.util.Collection<java.lang.String> topics)
Description copied from interface: ConnectionFactory
Refresh the broker connections and partition leader map. To be called when the topology changes are detected (i.e. brokers leave and/or partition leaders change) and that results in fetch errors, for instance.

Specified by:
refreshLeaders in interface ConnectionFactory
Parameters:
topics - the topics for which to refresh the leaders
See Also:
ConnectionFactory.refreshLeaders(Collection)

getPartitions

public java.util.Collection<Partition> getPartitions(java.lang.String topic)
Description copied from interface: ConnectionFactory
Retrieves the partitions of a given topic

Specified by:
getPartitions in interface ConnectionFactory
Parameters:
topic - the topic to query for
Returns:
a list of partitions
See Also:
ConnectionFactory.getPartitions(String)

Spring Integration Kafka Support