Class SingleNodeKafkaResumeStrategy

java.lang.Object
org.apache.camel.processor.resume.kafka.SingleNodeKafkaResumeStrategy
All Implemented Interfaces:
AutoCloseable, org.apache.camel.CamelContextAware, KafkaResumeStrategy, org.apache.camel.resume.ResumeStrategy, org.apache.camel.Service

@JdkService("kafka-resume-strategy") public class SingleNodeKafkaResumeStrategy extends Object implements KafkaResumeStrategy, org.apache.camel.CamelContextAware
A resume strategy that publishes offsets to a Kafka topic. This resume strategy is suitable for single node integrations.
  • Nested Class Summary

    Nested classes/interfaces inherited from interface org.apache.camel.resume.ResumeStrategy

    org.apache.camel.resume.ResumeStrategy.UpdateCallBack
  • Field Summary

    Fields inherited from interface org.apache.camel.resume.ResumeStrategy

    DEFAULT_NAME
  • Constructor Summary

    Constructors
    Constructor
    Description
     
    Builds an instance of this class
    Builds an instance of this class
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
    protected void
    checkAndSubscribe(org.apache.kafka.clients.consumer.Consumer<byte[],byte[]> consumer, String topic)
    Subscribe to the topic if not subscribed yet
    void
    checkAndSubscribe(org.apache.kafka.clients.consumer.Consumer<byte[],byte[]> consumer, String topic, long remaining)
    Subscribe to the topic if not subscribed yet
    void
     
    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
    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
    protected void
    doAdd(org.apache.camel.resume.OffsetKey<?> key, org.apache.camel.resume.Offset<?> offsetValue)
     
    org.apache.camel.resume.ResumeAdapter
     
    org.apache.camel.CamelContext
     
     
    protected org.apache.kafka.clients.producer.Producer<byte[],byte[]>
     
    org.apache.camel.resume.ResumeStrategyConfiguration
     
    void
     
    void
    Loads the existing data into the cache
    protected void
    poll(org.apache.kafka.clients.consumer.Consumer<byte[],byte[]> consumer, CountDownLatch latch)
     
    protected void
    produce(byte[] key, byte[] message, org.apache.camel.resume.ResumeStrategy.UpdateCallBack updateCallBack)
    Sends data to a topic.
    void
    setAdapter(org.apache.camel.resume.ResumeAdapter adapter)
     
    void
    setCamelContext(org.apache.camel.CamelContext camelContext)
     
    void
    setPollDuration(Duration pollDuration)
     
    void
    setResumeStrategyConfiguration(org.apache.camel.resume.ResumeStrategyConfiguration resumeStrategyConfiguration)
     
    void
     
    void
     
    void
    updateLastOffset(org.apache.camel.resume.OffsetKey<?> offsetKey, org.apache.camel.resume.Offset<?> offset)
     
    void
    updateLastOffset(org.apache.camel.resume.OffsetKey<?> offsetKey, org.apache.camel.resume.Offset<?> offset, org.apache.camel.resume.ResumeStrategy.UpdateCallBack updateCallBack)
     
    <T extends org.apache.camel.resume.Resumable>
    void
    updateLastOffset(T offset)
     
    <T extends org.apache.camel.resume.Resumable>
    void
    updateLastOffset(T offset, org.apache.camel.resume.ResumeStrategy.UpdateCallBack updateCallBack)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.apache.camel.resume.ResumeStrategy

    getAdapter
  • Constructor Details

    • SingleNodeKafkaResumeStrategy

      public SingleNodeKafkaResumeStrategy()
    • 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 Details

    • produce

      protected void produce(byte[] key, byte[] message, org.apache.camel.resume.ResumeStrategy.UpdateCallBack updateCallBack)
      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
    • doAdd

      protected void doAdd(org.apache.camel.resume.OffsetKey<?> key, org.apache.camel.resume.Offset<?> offsetValue)
    • updateLastOffset

      public <T extends org.apache.camel.resume.Resumable> void updateLastOffset(T offset) throws Exception
      Specified by:
      updateLastOffset in interface org.apache.camel.resume.ResumeStrategy
      Throws:
      Exception
    • updateLastOffset

      public <T extends org.apache.camel.resume.Resumable> void updateLastOffset(T offset, org.apache.camel.resume.ResumeStrategy.UpdateCallBack updateCallBack) throws Exception
      Specified by:
      updateLastOffset in interface org.apache.camel.resume.ResumeStrategy
      Throws:
      Exception
    • updateLastOffset

      public void updateLastOffset(org.apache.camel.resume.OffsetKey<?> offsetKey, org.apache.camel.resume.Offset<?> offset) throws Exception
      Specified by:
      updateLastOffset in interface org.apache.camel.resume.ResumeStrategy
      Throws:
      Exception
    • updateLastOffset

      public void updateLastOffset(org.apache.camel.resume.OffsetKey<?> offsetKey, org.apache.camel.resume.Offset<?> offset, org.apache.camel.resume.ResumeStrategy.UpdateCallBack updateCallBack) throws Exception
      Specified by:
      updateLastOffset in interface org.apache.camel.resume.ResumeStrategy
      Throws:
      Exception
    • loadCache

      public void loadCache()
      Loads the existing data into the cache
      Specified by:
      loadCache in interface org.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 from
      remaining - 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 topic
      consumer - 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 interface org.apache.camel.resume.ResumeStrategy
    • setAdapter

      public void setAdapter(org.apache.camel.resume.ResumeAdapter adapter)
      Specified by:
      setAdapter in interface org.apache.camel.resume.ResumeStrategy
    • build

      public void build()
      Specified by:
      build in interface org.apache.camel.Service
    • init

      public void init()
      Specified by:
      init in interface org.apache.camel.Service
    • stop

      public void stop()
      Specified by:
      stop in interface org.apache.camel.Service
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface org.apache.camel.Service
      Throws:
      IOException
    • start

      public void start()
      Specified by:
      start in interface org.apache.camel.Service
    • getPollDuration

      public Duration getPollDuration()
    • setPollDuration

      public void setPollDuration(Duration pollDuration)
    • getProducer

      protected org.apache.kafka.clients.producer.Producer<byte[],byte[]> getProducer()
    • setResumeStrategyConfiguration

      public void setResumeStrategyConfiguration(org.apache.camel.resume.ResumeStrategyConfiguration resumeStrategyConfiguration)
      Specified by:
      setResumeStrategyConfiguration in interface org.apache.camel.resume.ResumeStrategy
    • getResumeStrategyConfiguration

      public org.apache.camel.resume.ResumeStrategyConfiguration getResumeStrategyConfiguration()
      Specified by:
      getResumeStrategyConfiguration in interface org.apache.camel.resume.ResumeStrategy
    • getCamelContext

      public org.apache.camel.CamelContext getCamelContext()
      Specified by:
      getCamelContext in interface org.apache.camel.CamelContextAware
    • setCamelContext

      public void setCamelContext(org.apache.camel.CamelContext camelContext)
      Specified by:
      setCamelContext in interface org.apache.camel.CamelContextAware