public class ConsumerPool extends Object implements Closeable
| Modifier and Type | Class and Description |
|---|---|
(package private) static class |
ConsumerPool.PoolStats |
private class |
ConsumerPool.SimpleConsumerLease |
| Modifier and Type | Field and Description |
|---|---|
private String |
bootstrapServers |
private AtomicLong |
consumerClosedCountRef |
private AtomicLong |
consumerCreatedCountRef |
private byte[] |
demarcatorBytes |
private Charset |
headerCharacterSet |
private Pattern |
headerNamePattern |
private boolean |
honorTransactions |
private Map<String,Object> |
kafkaProperties |
private String |
keyEncoding |
private AtomicLong |
leasesObtainedCountRef |
private ComponentLog |
logger |
private long |
maxWaitMillis |
private BlockingQueue<ConsumerPool.SimpleConsumerLease> |
pooledLeases |
private RecordReaderFactory |
readerFactory |
private String |
securityProtocol |
private Pattern |
topicPattern |
private List<String> |
topics |
private RecordSetWriterFactory |
writerFactory |
| Constructor and Description |
|---|
ConsumerPool(int maxConcurrentLeases,
byte[] demarcator,
Map<String,Object> kafkaProperties,
List<String> topics,
long maxWaitMillis,
String keyEncoding,
String securityProtocol,
String bootstrapServers,
ComponentLog logger,
boolean honorTransactions,
Charset headerCharacterSet,
Pattern headerNamePattern)
Creates a pool of KafkaConsumer objects that will grow up to the maximum
indicated threads from the given context.
|
ConsumerPool(int maxConcurrentLeases,
byte[] demarcator,
Map<String,Object> kafkaProperties,
Pattern topics,
long maxWaitMillis,
String keyEncoding,
String securityProtocol,
String bootstrapServers,
ComponentLog logger,
boolean honorTransactions,
Charset headerCharacterSet,
Pattern headerNamePattern) |
ConsumerPool(int maxConcurrentLeases,
RecordReaderFactory readerFactory,
RecordSetWriterFactory writerFactory,
Map<String,Object> kafkaProperties,
List<String> topics,
long maxWaitMillis,
String securityProtocol,
String bootstrapServers,
ComponentLog logger,
boolean honorTransactions,
Charset headerCharacterSet,
Pattern headerNamePattern) |
ConsumerPool(int maxConcurrentLeases,
RecordReaderFactory readerFactory,
RecordSetWriterFactory writerFactory,
Map<String,Object> kafkaProperties,
Pattern topics,
long maxWaitMillis,
String securityProtocol,
String bootstrapServers,
ComponentLog logger,
boolean honorTransactions,
Charset headerCharacterSet,
Pattern headerNamePattern) |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes all consumers in the pool.
|
private void |
closeConsumer(org.apache.kafka.clients.consumer.Consumer<?,?> consumer) |
protected org.apache.kafka.clients.consumer.Consumer<byte[],byte[]> |
createKafkaConsumer()
Exposed as protected method for easier unit testing
|
(package private) ConsumerPool.PoolStats |
getPoolStats() |
ConsumerLease |
obtainConsumer(ProcessSession session,
ProcessContext processContext)
Obtains a consumer from the pool if one is available or lazily
initializes a new one if deemed necessary.
|
private final BlockingQueue<ConsumerPool.SimpleConsumerLease> pooledLeases
private final Pattern topicPattern
private final long maxWaitMillis
private final ComponentLog logger
private final byte[] demarcatorBytes
private final String keyEncoding
private final String securityProtocol
private final String bootstrapServers
private final boolean honorTransactions
private final RecordReaderFactory readerFactory
private final RecordSetWriterFactory writerFactory
private final Charset headerCharacterSet
private final Pattern headerNamePattern
private final AtomicLong consumerCreatedCountRef
private final AtomicLong consumerClosedCountRef
private final AtomicLong leasesObtainedCountRef
public ConsumerPool(int maxConcurrentLeases,
byte[] demarcator,
Map<String,Object> kafkaProperties,
List<String> topics,
long maxWaitMillis,
String keyEncoding,
String securityProtocol,
String bootstrapServers,
ComponentLog logger,
boolean honorTransactions,
Charset headerCharacterSet,
Pattern headerNamePattern)
maxConcurrentLeases - max allowable consumers at oncedemarcator - bytes to use as demarcator between messages; null or
empty means no demarcatorkafkaProperties - properties to use to initialize kafka consumerstopics - the topics to subscribe tomaxWaitMillis - maximum time to wait for a given lease to acquire
data before committingkeyEncoding - the encoding to use for the key of a kafka message if
foundsecurityProtocol - the security protocol usedbootstrapServers - the bootstrap serverslogger - the logger to report any errors/warningspublic ConsumerPool(int maxConcurrentLeases,
byte[] demarcator,
Map<String,Object> kafkaProperties,
Pattern topics,
long maxWaitMillis,
String keyEncoding,
String securityProtocol,
String bootstrapServers,
ComponentLog logger,
boolean honorTransactions,
Charset headerCharacterSet,
Pattern headerNamePattern)
public ConsumerPool(int maxConcurrentLeases,
RecordReaderFactory readerFactory,
RecordSetWriterFactory writerFactory,
Map<String,Object> kafkaProperties,
Pattern topics,
long maxWaitMillis,
String securityProtocol,
String bootstrapServers,
ComponentLog logger,
boolean honorTransactions,
Charset headerCharacterSet,
Pattern headerNamePattern)
public ConsumerPool(int maxConcurrentLeases,
RecordReaderFactory readerFactory,
RecordSetWriterFactory writerFactory,
Map<String,Object> kafkaProperties,
List<String> topics,
long maxWaitMillis,
String securityProtocol,
String bootstrapServers,
ComponentLog logger,
boolean honorTransactions,
Charset headerCharacterSet,
Pattern headerNamePattern)
public ConsumerLease obtainConsumer(ProcessSession session, ProcessContext processContext)
session - the session for which the consumer lease will be
associatedprocessContext - the ProcessContext for which the consumer
lease will be associatedprotected org.apache.kafka.clients.consumer.Consumer<byte[],byte[]> createKafkaConsumer()
org.apache.kafka.common.KafkaException - if unable to subscribe to the given topicspublic void close()
close in interface Closeableclose in interface AutoCloseableprivate void closeConsumer(org.apache.kafka.clients.consumer.Consumer<?,?> consumer)
ConsumerPool.PoolStats getPoolStats()
Copyright © 2022 Apache NiFi Project. All rights reserved.