Package com.github.ddth.queue.impl
Class KafkaQueueFactory<T extends KafkaQueue<ID,DATA>,ID,DATA>
- java.lang.Object
-
- com.github.ddth.queue.impl.AbstractQueueFactory<T,ID,DATA>
-
- com.github.ddth.queue.impl.KafkaQueueFactory<T,ID,DATA>
-
- All Implemented Interfaces:
IQueueFactory<ID,DATA>,AutoCloseable
- Direct Known Subclasses:
UniversalKafkaQueueFactory,UniversalKafkaQueueFactory
public abstract class KafkaQueueFactory<T extends KafkaQueue<ID,DATA>,ID,DATA> extends AbstractQueueFactory<T,ID,DATA>
Factory to createKafkaQueueinstances.- Since:
- 0.4.1
- Author:
- Thanh Ba Nguyen
-
-
Field Summary
Fields Modifier and Type Field Description static StringSPEC_FIELD_BOOTSTRAP_SERVERSstatic StringSPEC_FIELD_CONSUMER_GROUP_IDstatic StringSPEC_FIELD_CONSUMER_PROPERTIESstatic StringSPEC_FIELD_PRODUCER_PROPERTIESstatic StringSPEC_FIELD_PRODUCER_TYPEstatic StringSPEC_FIELD_SEND_ASYNCstatic StringSPEC_FIELD_TOPIC
-
Constructor Summary
Constructors Constructor Description KafkaQueueFactory()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddestroy()StringgetDefaultBootstrapServers()Default Kafka bootstrap server list (formathost1:9092,host2:port2,host3:port3), passed to all queues created by this factory.StringgetDefaultConsumerGroupId()Default Kafka group-id to consume messages, passed to all queues created by this factory.PropertiesgetDefaultConsumerProps()Default custom configuration properties for Kafka consumer, passed to all queues created by this factory.protected com.github.ddth.kafka.KafkaClientgetDefaultKafkaClient()If allKafkaQueueinstances are connecting to one Kafka broker, it's a good idea to pre-create aKafkaClientinstance and share it amongstKafkaQueueinstances created from this factory by assigning it todefaultKafkaClient(seesetDefaultKafkaClient(KafkaClient)).PropertiesgetDefaultProducerProps()Default custom configuration properties for Kafka producer, passed to all queues created by this factory.com.github.ddth.kafka.KafkaClient.ProducerTypegetDefaultProducerType()Default Kafka's producer type, used to send messages (defaultKafkaClient.ProducerType.LEADER_ACK), passed to all queues created by this factory.booleangetDefaultSendAsync()Should messages sent to Kafka asynchronously (defaulttrue)?StringgetDefaultTopicName()Default name of Kafka topic to store queue messages, passed to all queues created by this factory.protected voidinitQueue(T queue, QueueSpec spec)Initialize a newly created queue instance.booleanisDefaultSendAsync()Should messages sent to Kafka asynchronously (defaulttrue)?voidsetDefaultBootstrapServers(String defaultBootstrapServers)Default Kafka bootstrap server list (formathost1:9092,host2:port2,host3:port3), passed to all queues created by this factory.voidsetDefaultConsumerGroupId(String defaultConsumerGroupId)Default Kafka group-id to consume messages, passed to all queues created by this factory.voidsetDefaultConsumerProps(Properties defaultConsumerProps)Default custom configuration properties for Kafka consumer, passed to all queues created by this factory.KafkaQueueFactory<T,ID,DATA>setDefaultKafkaClient(com.github.ddth.kafka.KafkaClient kafkaClient)If allKafkaQueueinstances are connecting to one Kafka broker, it's a good idea to pre-create aKafkaClientinstance and share it amongstKafkaQueueinstances created from this factory by assigning it todefaultKafkaClient(seesetDefaultKafkaClient(KafkaClient)).protected KafkaQueueFactory<T,ID,DATA>setDefaultKafkaClient(com.github.ddth.kafka.KafkaClient kafkaClient, boolean setMyOwnKafkaClient)If allKafkaQueueinstances are connecting to one Kafka broker, it's a good idea to pre-create aKafkaClientinstance and share it amongstKafkaQueueinstances created from this factory by assigning it todefaultKafkaClient(seesetDefaultKafkaClient(KafkaClient)).voidsetDefaultProducerProps(Properties defaultProducerProps)Default custom configuration properties for Kafka producer, passed to all queues created by this factory.voidsetDefaultProducerType(com.github.ddth.kafka.KafkaClient.ProducerType defaultProducerType)Default Kafka's producer type, used to send messages (defaultKafkaClient.ProducerType.LEADER_ACK), passed to all queues created by this factory.voidsetDefaultSendAsync(boolean defaultSendAsync)Should messages sent to Kafka asynchronously (defaulttrue)?voidsetDefaultTopicName(String defaultTopicName)Default name of Kafka topic to store queue messages, passed to all queues created by this factory.-
Methods inherited from class com.github.ddth.queue.impl.AbstractQueueFactory
close, createAndInitQueue, createQueueInstance, getDefaultEphemeralDisabled, getDefaultEphemeralMaxSize, getDefaultMaxSize, getQueue, init, isDefaultEphemeralDisabled, setDefaultEphemeralDisabled, setDefaultEphemeralMaxSize, setDefaultMaxSize
-
-
-
-
Field Detail
-
SPEC_FIELD_BOOTSTRAP_SERVERS
public static final String SPEC_FIELD_BOOTSTRAP_SERVERS
- See Also:
- Constant Field Values
-
SPEC_FIELD_TOPIC
public static final String SPEC_FIELD_TOPIC
- See Also:
- Constant Field Values
-
SPEC_FIELD_CONSUMER_GROUP_ID
public static final String SPEC_FIELD_CONSUMER_GROUP_ID
- See Also:
- Constant Field Values
-
SPEC_FIELD_PRODUCER_TYPE
public static final String SPEC_FIELD_PRODUCER_TYPE
- See Also:
- Constant Field Values
-
SPEC_FIELD_PRODUCER_PROPERTIES
public static final String SPEC_FIELD_PRODUCER_PROPERTIES
- See Also:
- Constant Field Values
-
SPEC_FIELD_CONSUMER_PROPERTIES
public static final String SPEC_FIELD_CONSUMER_PROPERTIES
- See Also:
- Constant Field Values
-
SPEC_FIELD_SEND_ASYNC
public static final String SPEC_FIELD_SEND_ASYNC
- See Also:
- Constant Field Values
-
-
Method Detail
-
getDefaultBootstrapServers
public String getDefaultBootstrapServers()
Default Kafka bootstrap server list (formathost1:9092,host2:port2,host3:port3), passed to all queues created by this factory.- Returns:
- Since:
- 0.6.2
-
setDefaultBootstrapServers
public void setDefaultBootstrapServers(String defaultBootstrapServers)
Default Kafka bootstrap server list (formathost1:9092,host2:port2,host3:port3), passed to all queues created by this factory.- Parameters:
defaultBootstrapServers-- Since:
- 0.6.2
-
getDefaultTopicName
public String getDefaultTopicName()
Default name of Kafka topic to store queue messages, passed to all queues created by this factory.- Returns:
- Since:
- 0.6.2
-
setDefaultTopicName
public void setDefaultTopicName(String defaultTopicName)
Default name of Kafka topic to store queue messages, passed to all queues created by this factory.- Parameters:
defaultTopicName-- Since:
- 0.6.2
-
getDefaultConsumerGroupId
public String getDefaultConsumerGroupId()
Default Kafka group-id to consume messages, passed to all queues created by this factory.- Returns:
- Since:
- 0.6.2
-
setDefaultConsumerGroupId
public void setDefaultConsumerGroupId(String defaultConsumerGroupId)
Default Kafka group-id to consume messages, passed to all queues created by this factory.- Parameters:
defaultConsumerGroupId-- Since:
- 0.6.2
-
getDefaultProducerType
public com.github.ddth.kafka.KafkaClient.ProducerType getDefaultProducerType()
Default Kafka's producer type, used to send messages (defaultKafkaClient.ProducerType.LEADER_ACK), passed to all queues created by this factory.- Returns:
-
setDefaultProducerType
public void setDefaultProducerType(com.github.ddth.kafka.KafkaClient.ProducerType defaultProducerType)
Default Kafka's producer type, used to send messages (defaultKafkaClient.ProducerType.LEADER_ACK), passed to all queues created by this factory.- Parameters:
defaultProducerType-
-
getDefaultProducerProps
public Properties getDefaultProducerProps()
Default custom configuration properties for Kafka producer, passed to all queues created by this factory.- Returns:
-
setDefaultProducerProps
public void setDefaultProducerProps(Properties defaultProducerProps)
Default custom configuration properties for Kafka producer, passed to all queues created by this factory.- Parameters:
defaultProducerProps-
-
getDefaultConsumerProps
public Properties getDefaultConsumerProps()
Default custom configuration properties for Kafka consumer, passed to all queues created by this factory.- Returns:
-
setDefaultConsumerProps
public void setDefaultConsumerProps(Properties defaultConsumerProps)
Default custom configuration properties for Kafka consumer, passed to all queues created by this factory.- Parameters:
defaultConsumerProps-
-
isDefaultSendAsync
public boolean isDefaultSendAsync()
Should messages sent to Kafka asynchronously (defaulttrue)?- Returns:
- Since:
- 0.6.2
-
getDefaultSendAsync
public boolean getDefaultSendAsync()
Should messages sent to Kafka asynchronously (defaulttrue)?- Since:
- 0.6.2
-
setDefaultSendAsync
public void setDefaultSendAsync(boolean defaultSendAsync)
Should messages sent to Kafka asynchronously (defaulttrue)?- Parameters:
defaultSendAsync-- Since:
- 0.6.2
-
getDefaultKafkaClient
protected com.github.ddth.kafka.KafkaClient getDefaultKafkaClient()
If allKafkaQueueinstances are connecting to one Kafka broker, it's a good idea to pre-create aKafkaClientinstance and share it amongstKafkaQueueinstances created from this factory by assigning it todefaultKafkaClient(seesetDefaultKafkaClient(KafkaClient)).- Returns:
- Since:
- 0.7.1
-
setDefaultKafkaClient
protected KafkaQueueFactory<T,ID,DATA> setDefaultKafkaClient(com.github.ddth.kafka.KafkaClient kafkaClient, boolean setMyOwnKafkaClient)
If allKafkaQueueinstances are connecting to one Kafka broker, it's a good idea to pre-create aKafkaClientinstance and share it amongstKafkaQueueinstances created from this factory by assigning it todefaultKafkaClient(seesetDefaultKafkaClient(KafkaClient)).- Parameters:
kafkaClient-setMyOwnKafkaClient-- Returns:
- Since:
- 0.7.1
-
setDefaultKafkaClient
public KafkaQueueFactory<T,ID,DATA> setDefaultKafkaClient(com.github.ddth.kafka.KafkaClient kafkaClient)
If allKafkaQueueinstances are connecting to one Kafka broker, it's a good idea to pre-create aKafkaClientinstance and share it amongstKafkaQueueinstances created from this factory by assigning it todefaultKafkaClient(seesetDefaultKafkaClient(KafkaClient)).- Parameters:
kafkaClient-- Returns:
- Since:
- 0.7.1
-
destroy
public void destroy()
- Overrides:
destroyin classAbstractQueueFactory<T extends KafkaQueue<ID,DATA>,ID,DATA>- Since:
- 0.7.1
-
initQueue
protected void initQueue(T queue, QueueSpec spec) throws Exception
Initialize a newly created queue instance.Called by
AbstractQueueFactory.createAndInitQueue(QueueSpec). Sub-class may override this method to implement its own business logic.- Overrides:
initQueuein classAbstractQueueFactory<T extends KafkaQueue<ID,DATA>,ID,DATA>- Throws:
Exception
-
-