Class AbstractKafkaResumeStrategy<K,V>
- java.lang.Object
-
- org.apache.camel.processor.resume.kafka.AbstractKafkaResumeStrategy<K,V>
-
- All Implemented Interfaces:
AutoCloseable
,org.apache.camel.Service
,org.apache.camel.UpdatableConsumerResumeStrategy<K,V,org.apache.camel.Resumable<K,V>>
public abstract class AbstractKafkaResumeStrategy<K,V> extends Object implements org.apache.camel.UpdatableConsumerResumeStrategy<K,V,org.apache.camel.Resumable<K,V>>, org.apache.camel.Service
-
-
Field Summary
Fields Modifier and Type Field Description static int
UNLIMITED
-
Constructor Summary
Constructors Constructor Description AbstractKafkaResumeStrategy(String bootstrapServers, String topic, org.apache.camel.ResumeCache<K,V> resumeCache)
AbstractKafkaResumeStrategy(String topic, org.apache.camel.ResumeCache<K,V> resumeCache, Properties producerConfig, Properties consumerConfig)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
build()
void
checkAndSubscribe(String topic)
void
checkAndSubscribe(String topic, long remaining)
void
close()
org.apache.kafka.clients.consumer.ConsumerRecords<K,V>
consume()
Consumes message from the given topic until the predicate returns falseorg.apache.kafka.clients.consumer.ConsumerRecords<K,V>
consume(int retries)
static Properties
createConsumer(String bootstrapServers)
Creates a basic string-based consumerstatic Properties
createProducer(String bootstrapServers)
Creates a basic string-based producerprotected org.apache.kafka.clients.consumer.Consumer<K,V>
getConsumer()
long
getErrorCount()
Duration
getPollDuration()
protected org.apache.kafka.clients.producer.Producer<K,V>
getProducer()
List<Future<org.apache.kafka.clients.producer.RecordMetadata>>
getSentItems()
void
init()
protected void
loadCache()
void
produce(K key, V message)
Sends data to a topicvoid
setPollDuration(Duration pollDuration)
void
start()
void
stop()
abstract void
subscribe()
void
unsubscribe()
void
updateLastOffset(org.apache.camel.Resumable<K,V> offset)
-
-
-
Field Detail
-
UNLIMITED
public static final int UNLIMITED
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
AbstractKafkaResumeStrategy
public AbstractKafkaResumeStrategy(String bootstrapServers, String topic, org.apache.camel.ResumeCache<K,V> resumeCache)
-
AbstractKafkaResumeStrategy
public AbstractKafkaResumeStrategy(String topic, org.apache.camel.ResumeCache<K,V> resumeCache, Properties producerConfig, Properties consumerConfig)
-
-
Method Detail
-
createProducer
public static Properties createProducer(String bootstrapServers)
Creates a basic string-based producer- Parameters:
bootstrapServers
- the Kafka host- Returns:
- A set of default properties for producing string-based key/pair records from Kafka
-
createConsumer
public static Properties createConsumer(String bootstrapServers)
Creates a basic string-based consumer- Parameters:
bootstrapServers
- the Kafka host- Returns:
- A set of default properties for consuming string-based key/pair records from Kafka
-
produce
public void produce(K key, V message) throws ExecutionException, InterruptedException
Sends data to a topic- Parameters:
message
- the message to send- Throws:
ExecutionException
InterruptedException
-
updateLastOffset
public void updateLastOffset(org.apache.camel.Resumable<K,V> offset) throws Exception
-
checkAndSubscribe
public void checkAndSubscribe(String topic)
- Parameters:
topic
- the topic to consume the messages from
-
checkAndSubscribe
public void checkAndSubscribe(String topic, long remaining)
- Parameters:
topic
- the topic to consume the messages from
-
unsubscribe
public void unsubscribe()
-
consume
public org.apache.kafka.clients.consumer.ConsumerRecords<K,V> consume()
Consumes message from the given topic until the predicate returns false- Returns:
-
getErrorCount
public long getErrorCount()
-
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)
-
-