Class SingleNodeKafkaResumeStrategy<T extends org.apache.camel.resume.Resumable>
- java.lang.Object
-
- org.apache.camel.processor.resume.kafka.SingleNodeKafkaResumeStrategy<T>
-
- All Implemented Interfaces:
AutoCloseable
,KafkaResumeStrategy<T>
,org.apache.camel.resume.ResumeStrategy
,org.apache.camel.resume.UpdatableConsumerResumeStrategy<T>
,org.apache.camel.Service
- Direct Known Subclasses:
MultiNodeKafkaResumeStrategy
public class SingleNodeKafkaResumeStrategy<T extends org.apache.camel.resume.Resumable> extends Object implements KafkaResumeStrategy<T>
A resume strategy that publishes offsets to a Kafka topic. This resume strategy is suitable for single node integrations.
-
-
Constructor Summary
Constructors Constructor Description SingleNodeKafkaResumeStrategy(KafkaResumeStrategyConfiguration resumeStrategyConfiguration)
Builds an instance of this classSingleNodeKafkaResumeStrategy(KafkaResumeStrategyConfiguration resumeStrategyConfiguration, ExecutorService executorService)
Builds an instance of this class
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
build()
protected void
checkAndSubscribe(org.apache.kafka.clients.consumer.Consumer<byte[],byte[]> consumer, String topic)
Subscribe to the topic if not subscribed yetvoid
checkAndSubscribe(org.apache.kafka.clients.consumer.Consumer<byte[],byte[]> consumer, String topic, long remaining)
Subscribe to the topic if not subscribed yetvoid
close()
protected org.apache.kafka.clients.consumer.ConsumerRecords<byte[],byte[]>
consume(int retries, org.apache.kafka.clients.consumer.Consumer<byte[],byte[]> consumer)
Consumes message from the topic previously setupprotected org.apache.kafka.clients.consumer.ConsumerRecords<byte[],byte[]>
consume(org.apache.kafka.clients.consumer.Consumer<byte[],byte[]> consumer)
Consumes message from the topic previously setupprotected void
doAdd(org.apache.camel.resume.OffsetKey<?> key, org.apache.camel.resume.Offset<?> offsetValue)
org.apache.camel.resume.ResumeAdapter
getAdapter()
Duration
getPollDuration()
protected org.apache.kafka.clients.producer.Producer<byte[],byte[]>
getProducer()
protected Collection<RecordError>
getProducerErrors()
Gets the set record of sent itemsprotected KafkaResumeStrategyConfiguration
getResumeStrategyConfiguration()
void
init()
void
loadCache()
Loads the existing data into the cacheprotected void
poll(org.apache.kafka.clients.consumer.Consumer<byte[],byte[]> consumer, CountDownLatch latch)
protected void
produce(byte[] key, byte[] message)
Sends data to a topic.void
resetProducerErrors()
Clear the producer errorsvoid
setAdapter(org.apache.camel.resume.ResumeAdapter adapter)
void
setPollDuration(Duration pollDuration)
void
start()
void
stop()
void
updateLastOffset(T offset)
-
-
-
Constructor Detail
-
SingleNodeKafkaResumeStrategy
public SingleNodeKafkaResumeStrategy(KafkaResumeStrategyConfiguration resumeStrategyConfiguration)
Builds an instance of this class- Parameters:
resumeStrategyConfiguration
- the configuration to use for this strategy instance
-
SingleNodeKafkaResumeStrategy
public SingleNodeKafkaResumeStrategy(KafkaResumeStrategyConfiguration resumeStrategyConfiguration, ExecutorService executorService)
Builds an instance of this class- Parameters:
resumeStrategyConfiguration
- the configuration to use for this strategy instance
-
-
Method Detail
-
produce
protected void produce(byte[] key, byte[] message) throws ExecutionException, InterruptedException
Sends data to a topic. The records will always be sent asynchronously. If there's an error, a producer error counter will be increased.- Parameters:
message
- the message to send- Throws:
ExecutionException
InterruptedException
- See Also:
getProducerErrors()
-
doAdd
protected void doAdd(org.apache.camel.resume.OffsetKey<?> key, org.apache.camel.resume.Offset<?> offsetValue)
-
loadCache
public void loadCache()
Loads the existing data into the cache- Specified by:
loadCache
in interfaceorg.apache.camel.resume.ResumeStrategy
-
poll
protected void poll(org.apache.kafka.clients.consumer.Consumer<byte[],byte[]> consumer, CountDownLatch latch)
-
checkAndSubscribe
protected void checkAndSubscribe(org.apache.kafka.clients.consumer.Consumer<byte[],byte[]> consumer, String topic)
Subscribe to the topic if not subscribed yet- Parameters:
topic
- the topic to consume the messages from
-
checkAndSubscribe
public void checkAndSubscribe(org.apache.kafka.clients.consumer.Consumer<byte[],byte[]> consumer, String topic, long remaining)
Subscribe to the topic if not subscribed yet- Parameters:
topic
- the topic to consume the messages fromremaining
- the number of messages to rewind from the last offset position (used to fill the cache)
-
consume
protected org.apache.kafka.clients.consumer.ConsumerRecords<byte[],byte[]> consume(org.apache.kafka.clients.consumer.Consumer<byte[],byte[]> consumer)
Consumes message from the topic previously setup- Returns:
- An instance of the consumer records
-
consume
protected org.apache.kafka.clients.consumer.ConsumerRecords<byte[],byte[]> consume(int retries, org.apache.kafka.clients.consumer.Consumer<byte[],byte[]> consumer)
Consumes message from the topic previously setup- Parameters:
retries
- how many times to retry consuming data from the topicconsumer
- the kafka consumer object instance to use- Returns:
- An instance of the consumer records
-
getAdapter
public org.apache.camel.resume.ResumeAdapter getAdapter()
- Specified by:
getAdapter
in interfaceorg.apache.camel.resume.ResumeStrategy
-
setAdapter
public void setAdapter(org.apache.camel.resume.ResumeAdapter adapter)
- Specified by:
setAdapter
in interfaceorg.apache.camel.resume.ResumeStrategy
-
getProducerErrors
protected Collection<RecordError> getProducerErrors()
Gets the set record of sent items- Returns:
- A collection with all the record errors
-
build
public void build()
- Specified by:
build
in interfaceorg.apache.camel.Service
-
init
public void init()
- Specified by:
init
in interfaceorg.apache.camel.Service
-
stop
public void stop()
- Specified by:
stop
in interfaceorg.apache.camel.Service
-
close
public void close() throws IOException
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceorg.apache.camel.Service
- Throws:
IOException
-
start
public void start()
- Specified by:
start
in interfaceorg.apache.camel.Service
-
getPollDuration
public Duration getPollDuration()
-
setPollDuration
public void setPollDuration(Duration pollDuration)
-
getProducer
protected org.apache.kafka.clients.producer.Producer<byte[],byte[]> getProducer()
-
resetProducerErrors
public void resetProducerErrors()
Clear the producer errors
-
getResumeStrategyConfiguration
protected KafkaResumeStrategyConfiguration getResumeStrategyConfiguration()
-
-