Resume Strategies

The resume strategies allow users to implement strategies that point the consumer part of the routes to the last point of consumption. This allows Camel to skip reading and processing data that has already been consumed.

The resume strategies can be used to allow quicker stop and resume operations when consuming large data sources. For instance, imagine a scenario where the file consumer is reading a large file. Without a resume strategy, stopping and starting Camel would cause the consumer in the File component to read all the bytes of the given file at the initial offset (offset 0). The resume strategy allow integrations can point the consumer to the exact offset to resume the operations.

Support for resume varies according to the component. Initially, the support is available for the following components:

The resume strategies comes in 3 parts:

  • A DSL method that marks the route as supporting resume operations and points to an instance of a strategy implementation.

  • A set of core infrastructure that allow integrations to implement different types of strategies

  • Basic strategies implementations that can be extended to implement the specific resume strategies required by the integrations

The DSL method

The route needs to use the resumable() method followed by a resumableStrategy to point to an instance of the resume strategy in use.

This instance can be bound in the Context registry as follows:

getCamelContext().getRegistry().bind("testResumeStrategy", new MyTestResumeStrategy());


Or the instance can be constructed as follows:

    .resumable(new MyTestResumeStrategy())

The Resume API Interfaces

These are the core interfaces:

  • org.apache.camel.ResumeStrategy - the basic resume strategy

  • org.apache.camel.UpdatableConsumerResumeStrategy - an extension to the resume strategy to allow updatable strategies

  • org.apache.camel.ResumeCache - an interface for local cache for resumable information

These are the core classes supporting the strategies:

  • org.apache.camel.Resumable - an interface to allow users to work with abstract resumable entities (files, offsets, etc)

  • org.apache.camel.ResumableSet - an interface for resumables with a 1-to-many relationship

  • org.apache.camel.Offset - a generic offset without a concrete type (it may represent a long, a file name, etc)

These are the supporting classes:

  • - resumables handling support

  • - offset handling support

Basic Strategies

The basic strategies offer a component-specific skeleton that can be used to implement strategies.

  • AbstractKafkaResumeStrategy - a resume strategy from the camel-kafka component that uses Kafka as the store for the offsets.

public class KafkaResumeStrategy<K> extends AbstractKafkaResumeStrategy<K, Long> implements GenericFileResumeStrategy<File> {

    private static final Logger LOG = LoggerFactory.getLogger(KafkaResumeStrategy.class);
    public static final int CACHE_SIZE = 100;

    private final String topic;
    private final ResumeCache<K, Long> cache;

    public KafkaResumeStrategy(String topic,
                               ResumeCache<K, Long> cache,
                               DefaultProducerPropertyFactory producerPropertyFactory,
                               DefaultConsumerPropertyFactory consumerPropertyFactory)
        super(topic, cache, producerPropertyFactory.getProperties(), consumerPropertyFactory.getProperties());
        this.topic = topic;
        this.cache = cache;

    private Optional<Long> getLastOffset(GenericFileResumable<File> resumable) {
        final File addressable = resumable.getAddressable();
        return getLastOffset((K) addressable);

    public Optional<Long> getLastOffset(K addressable) {
        return cache.get(addressable);

    public void subscribe() {
        checkAndSubscribe(topic, 1);

    public void resume(GenericFileResumable<File> resumable) {
        final Optional<Long> lastOffsetOpt = getLastOffset(resumable);

        if (!lastOffsetOpt.isPresent()) {

        final long lastOffset = lastOffsetOpt.get();

    public void resume() {
        throw new UnsupportedOperationException("Cannot perform blind resume");

Local Cache Support

A sample local cache implemented using Caffeine.

public class SingleItemCache<K> implements ResumeCache<K, Long> {
    public static final int CACHE_SIZE = 100;
    private final Cache<K, Long> cache = Caffeine.newBuilder()

    public void add(K key, Long offsetValue) {
        cache.put(key, offsetValue);

    public Optional<Long> get(K key) {
        Long entry = cache.getIfPresent(key);

        if (entry == null) {
            return Optional.empty();

        return Optional.of(entry.longValue());

    public boolean isFull() {
        if (cache.estimatedSize() < CACHE_SIZE) {
            return true;

        return false;

Known Limitations

When using the converters with the file component, beware of the differences in the behavior from Reader and InputStream:

For instance, the behavior of:


Is different from the behavior of:


Reason: the skip method in the Reader will skip characters, whereas the same method on the InputStream will skip bytes.