public abstract class KafkaQueue extends Object implements IQueue, Closeable, AutoCloseable
IQueue.| Constructor and Description |
|---|
KafkaQueue() |
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
protected abstract IQueueMessage |
deserialize(byte[] msgData)
Deserilizes a queue message.
|
void |
destroy()
Destroy method.
|
int |
ephemeralSize()
Gets ephemeral-storage's number of items.
|
void |
finish(IQueueMessage msg)
Called when finish processing the message to cleanup ephemeral storage.
|
String |
getConsumerGroupId()
Kafka's group-id to consume messages.
|
String |
getKafkaBootstrapServers()
Kafka bootstrap server list (format
host1:9092,host2:port2,host3:port3). |
protected com.github.ddth.kafka.KafkaClient |
getKafkaClient() |
Properties |
getKafkaConsumerProperties()
Gets Kafka consumer's custom configuration properties.
|
Properties |
getKafkaProducerProperties()
Gets Kafka producer's custom configuration properties.
|
Collection<IQueueMessage> |
getOrphanMessages(long thresholdTimestampMs)
Gets all orphan messages (messages that were left in ephemeral storage
for a long time).
|
com.github.ddth.kafka.KafkaClient.ProducerType |
getProducerType() |
String |
getTopicName()
Name of Kafka topic to store queue messages.
|
KafkaQueue |
init()
Init method.
|
boolean |
moveFromEphemeralToQueueStorage(IQueueMessage msg)
Moves a message from ephemeral back to queue storage.
|
protected boolean |
putToQueue(IQueueMessage msg)
Puts a message to Kafka queue, partitioning message by
IQueueMessage.qId() |
boolean |
queue(IQueueMessage _msg)
Queues a message.
|
int |
queueSize()
Gets queue's number of items.
|
boolean |
requeue(IQueueMessage _msg)
Re-queues a message.
|
boolean |
requeueSilent(IQueueMessage msg)
Silently re-queues a message.
|
protected abstract byte[] |
serialize(IQueueMessage msg)
Serializes a queue message to store in Kafka.
|
KafkaQueue |
setConsumerGroupId(String consumerGroupId) |
KafkaQueue |
setKafkaBootstrapServers(String kafkaBootstrapServers)
Sets Kafka bootstrap server list (format
host1:9092,host2:port2,host3:port3). |
KafkaQueue |
setKafkaClient(com.github.ddth.kafka.KafkaClient kafkaClient)
An external
KafkaClient can be used. |
KafkaQueue |
setKafkaConsumerProperties(Properties kafkaConsumerConfigs)
Sets Kafka consumer's custom configuration properties.
|
KafkaQueue |
setKafkaProducerProperties(Properties kafkaProducerConfigs)
Sets Kafka producer's custom configuration properties.
|
KafkaQueue |
setProducerType(com.github.ddth.kafka.KafkaClient.ProducerType producerType) |
KafkaQueue |
setTopicName(String topicName) |
IQueueMessage |
take()
Takes a message out of queue.
|
protected IQueueMessage |
takeFromQueue()
Takes a message from Kafka queue.
|
public com.github.ddth.kafka.KafkaClient.ProducerType getProducerType()
public KafkaQueue setProducerType(com.github.ddth.kafka.KafkaClient.ProducerType producerType)
public String getKafkaBootstrapServers()
host1:9092,host2:port2,host3:port3).public KafkaQueue setKafkaBootstrapServers(String kafkaBootstrapServers)
host1:9092,host2:port2,host3:port3).kafkaBootstrapServers - public Properties getKafkaProducerProperties()
public KafkaQueue setKafkaProducerProperties(Properties kafkaProducerConfigs)
kafkaProducerConfigs - public Properties getKafkaConsumerProperties()
public KafkaQueue setKafkaConsumerProperties(Properties kafkaConsumerConfigs)
kafkaConsumerConfigs - public String getTopicName()
public KafkaQueue setTopicName(String topicName)
public String getConsumerGroupId()
public KafkaQueue setConsumerGroupId(String consumerGroupId)
protected com.github.ddth.kafka.KafkaClient getKafkaClient()
public KafkaQueue setKafkaClient(com.github.ddth.kafka.KafkaClient kafkaClient)
KafkaClient can be used. If not set,
KafkaQueue will automatically create a KafkaClient for
its own use.kafkaClient - public KafkaQueue init() throws Exception
Exceptionpublic void destroy()
public void close()
close in interface Closeableclose in interface AutoCloseableprotected abstract byte[] serialize(IQueueMessage msg) throws QueueException
msg - QueueExceptionprotected abstract IQueueMessage deserialize(byte[] msgData) throws QueueException
msgData - QueueExceptionprotected IQueueMessage takeFromQueue()
protected boolean putToQueue(IQueueMessage msg)
IQueueMessage.qId()msg - public boolean queue(IQueueMessage _msg)
Implementation flow:
public boolean requeue(IQueueMessage _msg)
Implementation flow:
Note: ephemeral storage implementation is optional, depends on implementation.
public boolean requeueSilent(IQueueMessage msg)
Implementation flow:
Note: ephemeral storage implementation is optional, depends on implementation.
requeueSilent in interface IQueuepublic void finish(IQueueMessage msg)
Implementation flow:
Note: ephemeral storage implementation is optional, depends on implementation.
public IQueueMessage take()
Implementation flow:
Note: ephemeral storage implementation is optional, depends on implementation.
public Collection<IQueueMessage> getOrphanMessages(long thresholdTimestampMs)
getOrphanMessages in interface IQueuethresholdTimestampMs - public boolean moveFromEphemeralToQueueStorage(IQueueMessage msg)
Implementation flow:
moveFromEphemeralToQueueStorage in interface IQueuetrue if a move has been made, false otherwise
(e.g. the message didn't exist in ephemeral storage)public int queueSize()
public int ephemeralSize()
Note: ephemeral storage implementation is optional, depends on implementation.
ephemeralSize in interface IQueueCopyright © 2016 DDTH. All rights reserved.