You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by or...@apache.org on 2022/03/01 18:24:06 UTC
[camel] branch main updated (a118f6e -> cfe69f6)
This is an automated email from the ASF dual-hosted git repository.
orpiske pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git.
from a118f6e CAMEL-17684 - Support ability to load properties from Vault/Secrets cloud services - GCP Secrets Manager
new 83d3697 CAMEL-15562: added a reusable kafka strategy
new 9aab52d CAMEL-15562: preliminary implementation of the user-facing resume API
new 0992cbc CAMEL-15562: cleanup the creation of the strategy factories
new 5547505 CAMEL-15562: removed the resume strategy option from components
new 4e1bd78 CAMEL-15562: fixed not starting strategies instances
new 63fc1e0 CAMEL-15562: further simplification of the API
new 6a55b31 CAMEL-15562: abstract the underlying cache so it's configurable
new e08ec3b CAMEL-15562: offset should skip when converting to InputStream
new ece9df5 CAMEL-17117: preliminary documentation for the resume strategy
new 3a56bea CAMEL-15562: fixed resumables availability check
new 616b50d CAMEL-15562: minor cleanups for the Kafka strategy
new de8389c CAMEL-155623: implement getters on the ResumeAware
new 1e76dd6 CAMEL-15562: use the service interface to avoid overlap in life cycle management
new bbd4a84 CAMEL-15562: simplify defining and setting the resume strategy
new 519f6ab CAMEL-15562: minor adjustments to the resume API log messages
new cfe69f6 CAMEL-15562: simplify the resumable processor lifecycle
The 16 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../camel/catalog/components/aws2-kinesis.json | 2 -
.../apache/camel/catalog/components/couchdb.json | 1 -
.../org/apache/camel/catalog/components/file.json | 1 -
.../org/apache/camel/catalog/components/kafka.json | 2 -
.../apache/camel/catalog/schemas/camel-spring.xsd | 101 +++++++
.../aws2/kinesis/Kinesis2ComponentConfigurer.java | 6 -
.../aws2/kinesis/Kinesis2EndpointConfigurer.java | 6 -
.../aws2/kinesis/Kinesis2EndpointUriFactory.java | 3 +-
.../camel/component/aws2/kinesis/aws2-kinesis.json | 2 -
.../aws2/kinesis/Kinesis2Configuration.java | 14 -
.../component/aws2/kinesis/Kinesis2Consumer.java | 7 +-
.../kinesis/consumer/KinesisResumeStrategy.java | 12 +-
.../couchdb/CouchDbEndpointConfigurer.java | 6 -
.../couchdb/CouchDbEndpointUriFactory.java | 3 +-
.../apache/camel/component/couchdb/couchdb.json | 1 -
.../component/couchdb/CouchDbChangesetTracker.java | 4 +-
.../camel/component/couchdb/CouchDbConsumer.java | 15 +-
.../camel/component/couchdb/CouchDbEndpoint.java | 15 -
.../couchdb/consumer/CouchDbResumeStrategy.java | 12 +-
...tory.java => CouchDbResumeStrategyFactory.java} | 10 +-
.../component/file/FileEndpointConfigurer.java | 6 -
.../component/file/FileEndpointUriFactory.java | 3 +-
.../org/apache/camel/component/file/file.json | 1 -
.../apache/camel/component/file/FileConsumer.java | 24 +-
.../apache/camel/component/file/FileEndpoint.java | 20 --
.../camel/component/file/GenericFileConverter.java | 5 +-
.../component/file/consumer/FileResumeSet.java | 8 +-
.../component/kafka/KafkaComponentConfigurer.java | 6 -
.../component/kafka/KafkaEndpointConfigurer.java | 6 -
.../component/kafka/KafkaEndpointUriFactory.java | 3 +-
.../org/apache/camel/component/kafka/kafka.json | 2 -
.../camel/component/kafka/KafkaConfiguration.java | 24 --
.../camel/component/kafka/KafkaConsumer.java | 15 +-
.../camel/component/kafka/KafkaFetchRecords.java | 10 +-
.../support/KafkaConsumerResumeStrategy.java | 12 +-
.../support/PartitionAssignmentListener.java | 13 +-
.../consumer/support/ResumeStrategyFactory.java | 13 +-
.../resume/kafka/AbstractKafkaResumeStrategy.java | 320 +++++++++++++++++++++
.../KafkaConsumerWithResumeRouteStrategyIT.java | 233 +++++++++++++++
.../KafkaConsumerWithResumeStrategyIT.java | 118 --------
.../src/test/resources/log4j2.properties | 5 +-
.../org/apache/camel/ExchangeConstantProvider.java | 3 +-
.../src/main/java/org/apache/camel/Exchange.java | 1 +
.../{ResumeStrategy.java => ResumeAware.java} | 18 +-
.../{ResumeStrategy.java => ResumeCache.java} | 34 ++-
.../main/java/org/apache/camel/ResumeStrategy.java | 2 +-
.../src/main/java/org/apache/camel/Route.java | 5 +
.../org/apache/camel/impl/engine/DefaultRoute.java | 11 +
.../docs/modules/eips/pages/resume-strategies.adoc | 179 ++++++++++++
.../apache/camel/model/ProcessorDefinition.java | 23 ++
.../apache/camel/model/ResumableDefinition.java | 66 +++++
.../camel/processor/resume/NoOffsetException.java} | 25 +-
.../processor/resume/ResumableCompletion.java | 61 ++++
.../camel/processor/resume/ResumableProcessor.java | 155 ++++++++++
.../org/apache/camel/reifier/ProcessorReifier.java | 3 +
.../org/apache/camel/reifier/ResumableReifier.java | 54 ++++
.../FileConsumerResumeFromOffsetStrategyTest.java | 48 +++-
.../file/FileConsumerResumeStrategyTest.java | 45 ++-
.../dsl/Aws2KinesisComponentBuilderFactory.java | 19 --
.../dsl/KafkaComponentBuilderFactory.java | 25 --
.../dsl/CouchDbEndpointBuilderFactory.java | 36 ---
.../endpoint/dsl/FileEndpointBuilderFactory.java | 38 ---
.../endpoint/dsl/KafkaEndpointBuilderFactory.java | 48 ----
.../dsl/Kinesis2EndpointBuilderFactory.java | 36 ---
64 files changed, 1481 insertions(+), 524 deletions(-)
rename components/camel-couchdb/src/main/java/org/apache/camel/component/couchdb/consumer/{CouchDdResumeStrategyFactory.java => CouchDbResumeStrategyFactory.java} (82%)
create mode 100644 components/camel-kafka/src/main/java/org/apache/camel/processor/resume/kafka/AbstractKafkaResumeStrategy.java
create mode 100644 components/camel-kafka/src/test/java/org/apache/camel/component/kafka/integration/KafkaConsumerWithResumeRouteStrategyIT.java
delete mode 100644 components/camel-kafka/src/test/java/org/apache/camel/component/kafka/integration/KafkaConsumerWithResumeStrategyIT.java
copy core/camel-api/src/main/java/org/apache/camel/{ResumeStrategy.java => ResumeAware.java} (64%)
copy core/camel-api/src/main/java/org/apache/camel/{ResumeStrategy.java => ResumeCache.java} (56%)
create mode 100644 core/camel-core-engine/src/main/docs/modules/eips/pages/resume-strategies.adoc
create mode 100644 core/camel-core-model/src/main/java/org/apache/camel/model/ResumableDefinition.java
copy core/{camel-api/src/main/java/org/apache/camel/ResumeStrategy.java => camel-core-processor/src/main/java/org/apache/camel/processor/resume/NoOffsetException.java} (57%)
create mode 100644 core/camel-core-processor/src/main/java/org/apache/camel/processor/resume/ResumableCompletion.java
create mode 100644 core/camel-core-processor/src/main/java/org/apache/camel/processor/resume/ResumableProcessor.java
create mode 100644 core/camel-core-reifier/src/main/java/org/apache/camel/reifier/ResumableReifier.java
[camel] 10/16: CAMEL-15562: fixed resumables availability check
Posted by or...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 3a56bea57ddc8a5ce74db41e6be8c4d8c538803d
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Thu Feb 24 14:58:21 2022 +0100
CAMEL-15562: fixed resumables availability check
---
.../org/apache/camel/component/file/consumer/FileResumeSet.java | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/components/camel-file/src/main/java/org/apache/camel/component/file/consumer/FileResumeSet.java b/components/camel-file/src/main/java/org/apache/camel/component/file/consumer/FileResumeSet.java
index 780f77b..0493186 100644
--- a/components/camel-file/src/main/java/org/apache/camel/component/file/consumer/FileResumeSet.java
+++ b/components/camel-file/src/main/java/org/apache/camel/component/file/consumer/FileResumeSet.java
@@ -59,6 +59,12 @@ public final class FileResumeSet implements ResumableSet<File> {
* @return true if there are resumable files or false otherwise
*/
public boolean hasResumables() {
- return outputFiles != null && outputFiles.length != inputFiles.length;
+ if (outputFiles != null && outputFiles.length > 0) {
+ if (outputFiles.length != inputFiles.length) {
+ return true;
+ }
+ }
+
+ return false;
}
}
[camel] 09/16: CAMEL-17117: preliminary documentation for the resume strategy
Posted by or...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
commit ece9df55eca1fad0878ecf48a916c06a2afd6e5b
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Thu Feb 24 10:06:34 2022 +0100
CAMEL-17117: preliminary documentation for the resume strategy
---
.../docs/modules/eips/pages/resume-strategies.adoc | 179 +++++++++++++++++++++
1 file changed, 179 insertions(+)
diff --git a/core/camel-core-engine/src/main/docs/modules/eips/pages/resume-strategies.adoc b/core/camel-core-engine/src/main/docs/modules/eips/pages/resume-strategies.adoc
new file mode 100644
index 0000000..b284b4c
--- /dev/null
+++ b/core/camel-core-engine/src/main/docs/modules/eips/pages/resume-strategies.adoc
@@ -0,0 +1,179 @@
+= Resume Strategies
+:doctitle: Resume Strategies
+:shortname: resume
+:description: Provide strategies to allow consuming data from specific offsets
+:since:
+:supportlevel: Experimental
+
+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.
+
+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 `resumableStrategyRef` to point to an instance of the resume strategy in use. This instance needs to be bound in the Context registry.
+
+[source,java]
+----
+getCamelContext().getRegistry().bind("testResumeStrategy", testResumeStrategy);
+
+from("some:component")
+ .process(this::process)
+ .resumable().resumableStrategyRef("testResumeStrategy");
+----
+
+
+=== The Core 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*:
+
+* org.apache.camel.support.Resumables: resumables handling support
+* org.apache.camel.support.Offsets: 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.
+
+
+[source,java]
+----
+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);
+ }
+
+ @Override
+ public void subscribe() {
+ checkAndSubscribe(topic, 1);
+ }
+
+ @Override
+ public void resume(GenericFileResumable<File> resumable) {
+ final Optional<Long> lastOffsetOpt = getLastOffset(resumable);
+
+ if (!lastOffsetOpt.isPresent()) {
+ return;
+ }
+
+ final long lastOffset = lastOffsetOpt.get();
+ resumable.updateLastOffset(lastOffset);
+ }
+
+ @Override
+ public void resume() {
+ throw new UnsupportedOperationException("Cannot perform blind resume");
+ }
+}
+----
+
+
+=== Local Cache Support
+
+A sample local cache implemented using https://github.com/ben-manes/caffeine[Caffeine].
+
+[source,java]
+----
+public class SingleItemCache<K> implements ResumeCache<K, Long> {
+ public static final int CACHE_SIZE = 100;
+ private final Cache<K, Long> cache = Caffeine.newBuilder()
+ .maximumSize(CACHE_SIZE)
+ .build();
+
+ @Override
+ public void add(K key, Long offsetValue) {
+ cache.put(key, offsetValue);
+ }
+
+ @Override
+ public Optional<Long> get(K key) {
+ Long entry = cache.getIfPresent(key);
+
+ if (entry == null) {
+ return Optional.empty();
+ }
+
+ return Optional.of(entry.longValue());
+ }
+
+ @Override
+ public boolean isFull() {
+ if (cache.estimatedSize() < CACHE_SIZE) {
+ return true;
+ }
+
+ return false;
+ }
+}
+----
+
+
+
+=== Known Limitations, Bugs and Other Notes
+
+* When using the converters with the file component, beware of the differences in the behavior from `Reader` and `InputStream`:
+
+For instance, the behavior of:
+
+[source,java]
+----
+from("file:{{input.dir}}?noop=true&fileName={{input.file}}")
+ .convertBodyTo(Reader.class)
+ .process(this::process)
+ .resumable().resumableStrategyRef("testResumeStrategy");
+----
+
+Is different from the behavior of:
+
+[source,java]
+----
+from("file:{{input.dir}}?noop=true&fileName={{input.file}}")
+ .convertBodyTo(InputStream.class)
+ .process(this::process)
+ .resumable().resumableStrategyRef("testResumeStrategy");
+----
+
+*Reason*: the `skip` method in the Reader will skip characters, whereas the same method on the InputStream will skip bytes.
[camel] 01/16: CAMEL-15562: added a reusable kafka strategy
Posted by or...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 83d369772fb69125dc058b00dd33ef3938da13bf
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Tue Feb 1 12:40:44 2022 +0100
CAMEL-15562: added a reusable kafka strategy
This introduces a basic Kafka strategy that can be extended to publish
offsets to a Kafka topic
---
.../resume/kafka/AbstractKafkaResumeStrategy.java | 281 +++++++++++++++++++++
1 file changed, 281 insertions(+)
diff --git a/components/camel-kafka/src/main/java/org/apache/camel/processor/resume/kafka/AbstractKafkaResumeStrategy.java b/components/camel-kafka/src/main/java/org/apache/camel/processor/resume/kafka/AbstractKafkaResumeStrategy.java
new file mode 100644
index 0000000..c8bd037
--- /dev/null
+++ b/components/camel-kafka/src/main/java/org/apache/camel/processor/resume/kafka/AbstractKafkaResumeStrategy.java
@@ -0,0 +1,281 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.camel.processor.resume.kafka;
+
+import java.time.Duration;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.TreeMap;
+import java.util.UUID;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+
+import org.apache.camel.Resumable;
+import org.apache.camel.UpdatableConsumerResumeStrategy;
+import org.apache.camel.util.StringHelper;
+import org.apache.kafka.clients.consumer.Consumer;
+import org.apache.kafka.clients.consumer.ConsumerConfig;
+import org.apache.kafka.clients.consumer.ConsumerRebalanceListener;
+import org.apache.kafka.clients.consumer.ConsumerRecord;
+import org.apache.kafka.clients.consumer.ConsumerRecords;
+import org.apache.kafka.clients.consumer.KafkaConsumer;
+import org.apache.kafka.clients.producer.KafkaProducer;
+import org.apache.kafka.clients.producer.Producer;
+import org.apache.kafka.clients.producer.ProducerConfig;
+import org.apache.kafka.clients.producer.ProducerRecord;
+import org.apache.kafka.clients.producer.RecordMetadata;
+import org.apache.kafka.common.TopicPartition;
+import org.apache.kafka.common.serialization.StringDeserializer;
+import org.apache.kafka.common.serialization.StringSerializer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public abstract class AbstractKafkaResumeStrategy<K, V> implements UpdatableConsumerResumeStrategy<K, V, Resumable<K, V>> {
+ private static final Logger LOG = LoggerFactory.getLogger(AbstractKafkaResumeStrategy.class);
+
+ private final String topic;
+
+ private Consumer<K, V> consumer;
+ private Producer<K, V> producer;
+ private long errorCount;
+
+ private Map<K, List<V>> processedItems = new TreeMap<>();
+ private List<Future<RecordMetadata>> sentItems = new ArrayList<>();
+ private boolean subscribed;
+ private Properties producerConfig;
+ private Properties consumerConfig;
+
+ public AbstractKafkaResumeStrategy(String bootstrapServers, String topic) {
+ this.topic = topic;
+
+ this.producerConfig = createProducer(bootstrapServers);
+ this.consumerConfig = createConsumer(bootstrapServers);
+ }
+
+ public AbstractKafkaResumeStrategy(String bootstrapServers, String topic, Properties producerConfig,
+ Properties consumerConfig) {
+ this.topic = topic;
+ this.producerConfig = producerConfig;
+ this.consumerConfig = consumerConfig;
+ }
+
+ public void start() throws Exception {
+ consumer = new KafkaConsumer<>(consumerConfig);
+ producer = new KafkaProducer<>(producerConfig);
+
+ loadProcessedItems(processedItems);
+ }
+
+ private Properties createProducer(String bootstrapServers) {
+ Properties config = new Properties();
+
+ config.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());
+ config.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());
+
+ StringHelper.notEmpty(bootstrapServers, "bootstrapServers");
+ config.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);
+
+ // set up the producer to remove all batching on send, we want all sends
+ // to be fully synchronous
+ config.putIfAbsent(ProducerConfig.ACKS_CONFIG, "1");
+ config.putIfAbsent(ProducerConfig.BATCH_SIZE_CONFIG, "0");
+
+ return config;
+ }
+
+ private Properties createConsumer(String bootstrapServers) {
+ Properties config = new Properties();
+
+ config.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class.getName());
+ config.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class.getName());
+
+ StringHelper.notEmpty(bootstrapServers, "bootstrapServers");
+ config.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);
+
+ String groupId = UUID.randomUUID().toString();
+ LOG.debug("Creating consumer with {}[{}]", ConsumerConfig.GROUP_ID_CONFIG, groupId);
+
+ config.put(ConsumerConfig.GROUP_ID_CONFIG, groupId);
+ config.put(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, Boolean.TRUE.toString());
+
+ return config;
+ }
+
+ /**
+ * Sends data to a topic
+ *
+ * @param topic the topic to send data to
+ * @param message the message to send
+ * @throws ExecutionException
+ * @throws InterruptedException
+ */
+ public void produce(String topic, K key, V message) throws ExecutionException, InterruptedException {
+ ProducerRecord<K, V> record = new ProducerRecord<>(topic, key, message);
+
+ errorCount = 0;
+ Future<RecordMetadata> future = producer.send(record, (recordMetadata, e) -> {
+ if (e != null) {
+ LOG.error("Failed to send message {}", e.getMessage(), e);
+ errorCount++;
+ }
+ });
+
+ sentItems.add(future);
+ }
+
+ @Override
+ public void updateLastOffset(Resumable<K, V> offset) throws Exception {
+ K key = offset.getAddressable();
+ V offsetValue = offset.getLastOffset().offset();
+
+ LOG.debug("Updating offset on Kafka with key {} to {}", key, offsetValue);
+
+ produce(topic, key, offsetValue);
+
+ // TODO: this leaks. It must be fixed for merge
+ var entries = processedItems.computeIfAbsent(key, k -> new ArrayList<>());
+ entries.add(offsetValue);
+ }
+
+ protected void loadProcessedItems(Map<K, List<V>> processed) throws Exception {
+ loadProcessedItems(processed, -1);
+ }
+
+ protected void loadProcessedItems(Map<K, List<V>> processed, int limit) throws Exception {
+ subscribe();
+
+ LOG.debug("Loading records from topic {}", topic);
+
+ ConsumerRecords<K, V> records;
+
+ do {
+ records = consume();
+
+ if (records.isEmpty()) {
+ break;
+ }
+
+ for (ConsumerRecord<K, V> record : records) {
+ V value = record.value();
+
+ LOG.trace("Read from Kafka: {}", value);
+ var entries = processed.computeIfAbsent(record.key(), k -> new ArrayList<>());
+ entries.add(record.value());
+
+ if (processed.size() >= limit) {
+ break;
+ }
+ }
+ } while (true);
+
+ LOG.debug("Loaded {} records", processed.size());
+ unsubscribe();
+ }
+
+ // TODO: bad method ...
+ /**
+ * @param topic the topic to consume the messages from
+ */
+ public void checkAndSubscribe(String topic) {
+ if (!subscribed) {
+ consumer.subscribe(Collections.singletonList(topic));
+
+ subscribed = true;
+ }
+ }
+
+ // TODO: bad method ...
+ /**
+ * @param topic the topic to consume the messages from
+ */
+ public void checkAndSubscribe(String topic, long remaining) {
+ if (!subscribed) {
+ consumer.subscribe(Collections.singletonList(topic), new ConsumerRebalanceListener() {
+ @Override
+ public void onPartitionsRevoked(Collection<TopicPartition> collection) {
+
+ }
+
+ @Override
+ public void onPartitionsAssigned(Collection<TopicPartition> assignments) {
+ consumer.seekToEnd(assignments);
+ for (TopicPartition assignment : assignments) {
+ final long endPosition = consumer.position(assignment);
+ final long startPosition = endPosition - remaining;
+
+ if (startPosition >= 0) {
+ consumer.seek(assignment, startPosition);
+ } else {
+ LOG.info(
+ "Ignoring the seek command because the initial offset is negative (the topic is likely empty)");
+ }
+ }
+ }
+ });
+
+ subscribed = true;
+ }
+ }
+
+ public abstract void subscribe() throws Exception;
+
+ // TODO: bad method
+ public void unsubscribe() {
+ consumer.unsubscribe();
+ }
+
+ /**
+ * Consumes message from the given topic until the predicate returns false
+ *
+ * @return
+ */
+ public ConsumerRecords<K, V> consume() {
+ int retries = 10;
+
+ return consume(retries);
+ }
+
+ public ConsumerRecords<K, V> consume(int retries) {
+ while (retries > 0) {
+ ConsumerRecords<K, V> records = consumer.poll(Duration.ofMillis(100));
+ if (!records.isEmpty()) {
+ return records;
+ }
+ retries--;
+ }
+
+ return ConsumerRecords.empty();
+ }
+
+ protected Map<K, List<V>> getProcessedItems() {
+ return processedItems;
+ }
+
+ public long getErrorCount() {
+ return errorCount;
+ }
+
+ public List<Future<RecordMetadata>> getSentItems() {
+ return Collections.unmodifiableList(sentItems);
+ }
+
+}
[camel] 14/16: CAMEL-15562: simplify defining and setting the resume strategy
Posted by or...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
commit bbd4a84d5c75fbf8bf27f23f3bf537a8b4cd3e93
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Tue Mar 1 12:54:22 2022 +0100
CAMEL-15562: simplify defining and setting the resume strategy
---
.../integration/KafkaConsumerWithResumeRouteStrategyIT.java | 2 +-
.../java/org/apache/camel/model/ProcessorDefinition.java | 10 ++++++++++
.../java/org/apache/camel/model/ResumableDefinition.java | 12 +++++++++---
.../main/java/org/apache/camel/reifier/ResumableReifier.java | 2 +-
.../file/FileConsumerResumeFromOffsetStrategyTest.java | 4 ++--
.../camel/component/file/FileConsumerResumeStrategyTest.java | 2 +-
6 files changed, 24 insertions(+), 8 deletions(-)
diff --git a/components/camel-kafka/src/test/java/org/apache/camel/component/kafka/integration/KafkaConsumerWithResumeRouteStrategyIT.java b/components/camel-kafka/src/test/java/org/apache/camel/component/kafka/integration/KafkaConsumerWithResumeRouteStrategyIT.java
index c6a27ca..dbc9d91 100644
--- a/components/camel-kafka/src/test/java/org/apache/camel/component/kafka/integration/KafkaConsumerWithResumeRouteStrategyIT.java
+++ b/components/camel-kafka/src/test/java/org/apache/camel/component/kafka/integration/KafkaConsumerWithResumeRouteStrategyIT.java
@@ -225,7 +225,7 @@ public class KafkaConsumerWithResumeRouteStrategyIT extends BaseEmbeddedKafkaTes
.routeId("resume-strategy-route")
.setHeader(Exchange.OFFSET,
constant(Resumables.of("key", RANDOM_VALUE)))
- .resumable().resumableStrategyRef("resumeStrategy")
+ .resumable().resumeStrategy("resumeStrategy")
.to("mock:result");
}
};
diff --git a/core/camel-core-model/src/main/java/org/apache/camel/model/ProcessorDefinition.java b/core/camel-core-model/src/main/java/org/apache/camel/model/ProcessorDefinition.java
index 7769c3e..f6f2b19 100644
--- a/core/camel-core-model/src/main/java/org/apache/camel/model/ProcessorDefinition.java
+++ b/core/camel-core-model/src/main/java/org/apache/camel/model/ProcessorDefinition.java
@@ -44,6 +44,7 @@ import org.apache.camel.Expression;
import org.apache.camel.LoggingLevel;
import org.apache.camel.Predicate;
import org.apache.camel.Processor;
+import org.apache.camel.ResumeStrategy;
import org.apache.camel.builder.DataFormatClause;
import org.apache.camel.builder.EndpointConsumerBuilder;
import org.apache.camel.builder.EndpointProducerBuilder;
@@ -3787,6 +3788,15 @@ public abstract class ProcessorDefinition<Type extends ProcessorDefinition<Type>
return answer;
}
+ public ResumableDefinition resumable(ResumeStrategy resumeStrategy) {
+ ResumableDefinition answer = new ResumableDefinition();
+
+ answer.setResumeStrategy(resumeStrategy);
+
+ addOutput(answer);
+ return answer;
+ }
+
// Properties
// -------------------------------------------------------------------------
diff --git a/core/camel-core-model/src/main/java/org/apache/camel/model/ResumableDefinition.java b/core/camel-core-model/src/main/java/org/apache/camel/model/ResumableDefinition.java
index 3a92d32..a2f4611 100644
--- a/core/camel-core-model/src/main/java/org/apache/camel/model/ResumableDefinition.java
+++ b/core/camel-core-model/src/main/java/org/apache/camel/model/ResumableDefinition.java
@@ -22,8 +22,8 @@ import javax.xml.bind.annotation.XmlTransient;
import org.apache.camel.ResumeStrategy;
-public class ResumableDefinition extends OutputExpressionNode {
- @XmlAttribute(required = true)
+public class ResumableDefinition extends NoOutputDefinition<ResumableDefinition> {
+ @XmlAttribute(required = true, name = "resumeStrategy")
private String resumeStrategyRef;
@XmlTransient
@@ -52,9 +52,15 @@ public class ResumableDefinition extends OutputExpressionNode {
// Fluent API
// -------------------------------------------------------------------------
- public ResumableDefinition resumableStrategyRef(String resumeStrategyRef) {
+ public ResumableDefinition resumeStrategy(String resumeStrategyRef) {
setResumeStrategyRef(resumeStrategyRef);
return this;
}
+
+ public ResumableDefinition resumeStrategy(ResumeStrategy resumeStrategy) {
+ setResumeStrategy(resumeStrategy);
+
+ return this;
+ }
}
diff --git a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/ResumableReifier.java b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/ResumableReifier.java
index ecf626a..9fcb1a5 100644
--- a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/ResumableReifier.java
+++ b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/ResumableReifier.java
@@ -25,7 +25,7 @@ import org.apache.camel.model.ResumableDefinition;
import org.apache.camel.processor.resume.ResumableProcessor;
import org.apache.camel.util.ObjectHelper;
-public class ResumableReifier extends ExpressionReifier<ResumableDefinition> {
+public class ResumableReifier extends ProcessorReifier<ResumableDefinition> {
protected ResumableReifier(Route route, ProcessorDefinition<?> definition) {
super(route, ResumableDefinition.class.cast(definition));
diff --git a/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerResumeFromOffsetStrategyTest.java b/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerResumeFromOffsetStrategyTest.java
index 2db4785..a084eb8 100644
--- a/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerResumeFromOffsetStrategyTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerResumeFromOffsetStrategyTest.java
@@ -110,12 +110,12 @@ public class FileConsumerResumeFromOffsetStrategyTest extends ContextTestSupport
from(fileUri("resumeOff?noop=true&recursive=true"))
.setHeader(Exchange.OFFSET,
constant(Resumables.of("resume-none.txt", 3)))
- .resumable().resumableStrategyRef("resumeStrategy")
+ .resumable().resumeStrategy("resumeStrategy")
.log("${body}")
.convertBodyTo(String.class).to("mock:result");
from(fileUri("resumeMissingOffset?noop=true&recursive=true"))
- .resumable().resumableStrategyRef("resumeStrategy")
+ .resumable().resumeStrategy("resumeStrategy")
.log("${body}")
.convertBodyTo(String.class).to("mock:result");
diff --git a/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerResumeStrategyTest.java b/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerResumeStrategyTest.java
index bf662ee..470a459 100644
--- a/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerResumeStrategyTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerResumeStrategyTest.java
@@ -103,7 +103,7 @@ public class FileConsumerResumeStrategyTest extends ContextTestSupport {
from(fileUri("resume?noop=true&recursive=true"))
.process(e -> setOffset(e))
- .resumable().resumableStrategyRef("testResumeStrategy")
+ .resumable().resumeStrategy("testResumeStrategy")
.convertBodyTo(String.class)
.to("mock:result");
}
[camel] 05/16: CAMEL-15562: fixed not starting strategies instances
Posted by or...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 4e1bd78bb25cb13e5ec066ce824a4b969549582a
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Mon Feb 14 18:10:27 2022 +0100
CAMEL-15562: fixed not starting strategies instances
---
.../org/apache/camel/component/kafka/KafkaConsumer.java | 14 +++++++++++++-
.../kafka/consumer/support/ResumeStrategyFactory.java | 3 +--
.../KafkaConsumerWithResumeRouteStrategyIT.java | 3 +--
.../java/org/apache/camel/reifier/ResumableReifier.java | 1 +
4 files changed, 16 insertions(+), 5 deletions(-)
diff --git a/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/KafkaConsumer.java b/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/KafkaConsumer.java
index 20226f5..eaefec2 100644
--- a/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/KafkaConsumer.java
+++ b/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/KafkaConsumer.java
@@ -25,6 +25,8 @@ import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;
import org.apache.camel.Processor;
+import org.apache.camel.ResumeAware;
+import org.apache.camel.component.kafka.consumer.support.KafkaConsumerResumeStrategy;
import org.apache.camel.spi.StateRepository;
import org.apache.camel.support.BridgeExceptionHandlerToErrorHandler;
import org.apache.camel.support.DefaultConsumer;
@@ -35,7 +37,7 @@ import org.apache.kafka.clients.consumer.ConsumerConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class KafkaConsumer extends DefaultConsumer {
+public class KafkaConsumer extends DefaultConsumer implements ResumeAware<KafkaConsumerResumeStrategy> {
private static final Logger LOG = LoggerFactory.getLogger(KafkaConsumer.class);
@@ -45,6 +47,7 @@ public class KafkaConsumer extends DefaultConsumer {
private final List<KafkaFetchRecords> tasks = new ArrayList<>();
private volatile boolean stopOffsetRepo;
private PollExceptionStrategy pollExceptionStrategy;
+ private KafkaConsumerResumeStrategy resumeStrategy;
public KafkaConsumer(KafkaEndpoint endpoint, Processor processor) {
super(endpoint, processor);
@@ -52,6 +55,15 @@ public class KafkaConsumer extends DefaultConsumer {
}
@Override
+ public void setResumeStrategy(KafkaConsumerResumeStrategy resumeStrategy) {
+ this.resumeStrategy = resumeStrategy;
+ }
+
+ public KafkaConsumerResumeStrategy getResumeStrategy() {
+ return resumeStrategy;
+ }
+
+ @Override
protected void doBuild() throws Exception {
super.doBuild();
if (endpoint.getComponent().getPollExceptionStrategy() != null) {
diff --git a/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/consumer/support/ResumeStrategyFactory.java b/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/consumer/support/ResumeStrategyFactory.java
index 2db61f1..d1656f86 100644
--- a/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/consumer/support/ResumeStrategyFactory.java
+++ b/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/consumer/support/ResumeStrategyFactory.java
@@ -56,8 +56,7 @@ public final class ResumeStrategyFactory {
public static KafkaConsumerResumeStrategy newResumeStrategy(KafkaConsumer kafkaConsumer) {
// When using resumable routes, which register the strategy via service, it takes priority over everything else
- KafkaConsumerResumeStrategy resumableRouteStrategy
- = kafkaConsumer.getEndpoint().getCamelContext().hasService(KafkaConsumerResumeStrategy.class);
+ KafkaConsumerResumeStrategy resumableRouteStrategy = kafkaConsumer.getResumeStrategy();
if (resumableRouteStrategy != null) {
return resumableRouteStrategy;
diff --git a/components/camel-kafka/src/test/java/org/apache/camel/component/kafka/integration/KafkaConsumerWithResumeRouteStrategyIT.java b/components/camel-kafka/src/test/java/org/apache/camel/component/kafka/integration/KafkaConsumerWithResumeRouteStrategyIT.java
index 5b0e828..1f95f30 100644
--- a/components/camel-kafka/src/test/java/org/apache/camel/component/kafka/integration/KafkaConsumerWithResumeRouteStrategyIT.java
+++ b/components/camel-kafka/src/test/java/org/apache/camel/component/kafka/integration/KafkaConsumerWithResumeRouteStrategyIT.java
@@ -48,8 +48,8 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
public class KafkaConsumerWithResumeRouteStrategyIT extends BaseEmbeddedKafkaTestSupport {
private static final Logger LOG = LoggerFactory.getLogger(KafkaConsumerWithResumeRouteStrategyIT.class);
-
private static final String TOPIC = "resumable-route-tp";
+ private static final int RANDOM_VALUE = ThreadLocalRandom.current().nextInt(1, 1000);
@EndpointInject("mock:result")
private MockEndpoint result;
@@ -57,7 +57,6 @@ public class KafkaConsumerWithResumeRouteStrategyIT extends BaseEmbeddedKafkaTes
@BindToRegistry("resumeStrategy")
private TestKafkaConsumerResumeStrategy resumeStrategy;
private CountDownLatch messagesLatch;
- private static final int RANDOM_VALUE = ThreadLocalRandom.current().nextInt(1, 1000);
private KafkaProducer<Object, Object> producer;
private static class TestKafkaConsumerResumeStrategy
diff --git a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/ResumableReifier.java b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/ResumableReifier.java
index d6f683e..6eba53f 100644
--- a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/ResumableReifier.java
+++ b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/ResumableReifier.java
@@ -38,6 +38,7 @@ public class ResumableReifier extends ExpressionReifier<ResumableDefinition> {
ResumeStrategy resumeStrategy = resolveResumeStrategy();
ObjectHelper.notNull(resumeStrategy, "resumeStrategy", definition);
+ resumeStrategy.start();
route.setResumeStrategy(resumeStrategy);
Expression expression = createExpression(definition.getExpression());
[camel] 08/16: CAMEL-15562: offset should skip when converting to InputStream
Posted by or...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
commit e08ec3b33fef91c388cfdf77b527286b2909847c
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Thu Feb 24 09:00:41 2022 +0100
CAMEL-15562: offset should skip when converting to InputStream
---
.../java/org/apache/camel/component/file/GenericFileConverter.java | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/components/camel-file/src/main/java/org/apache/camel/component/file/GenericFileConverter.java b/components/camel-file/src/main/java/org/apache/camel/component/file/GenericFileConverter.java
index 63c1edf..cffc53d 100644
--- a/components/camel-file/src/main/java/org/apache/camel/component/file/GenericFileConverter.java
+++ b/components/camel-file/src/main/java/org/apache/camel/component/file/GenericFileConverter.java
@@ -121,7 +121,10 @@ public final class GenericFileConverter {
} else {
LOG.debug("Read file {} (no charset)", f);
}
- return IOHelper.toInputStream(f, charset);
+ InputStream inputStream = IOHelper.toInputStream(f, charset);
+ inputStream.skip(file.getLastOffset().offset());
+
+ return inputStream;
}
}
if (exchange != null) {
[camel] 02/16: CAMEL-15562: preliminary implementation of the user-facing resume API
Posted by or...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 9aab52d4d37c20a254702527428f67e9f1a7b46b
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Wed Feb 2 17:00:49 2022 +0100
CAMEL-15562: preliminary implementation of the user-facing resume API
---
.../apache/camel/catalog/schemas/camel-spring.xsd | 101 +++++++++
.../kinesis/consumer/KinesisResumeStrategy.java | 2 +-
.../KinesisUserConfigurationResumeStrategy.java | 5 +
.../couchdb/consumer/CouchDbResumeStrategy.java | 2 +-
.../LatestUpdateSequenceResumeStrategy.java | 5 +
.../camel/component/kafka/KafkaFetchRecords.java | 6 +-
.../support/KafkaConsumerResumeStrategy.java | 2 +-
.../support/OffsetKafkaConsumerResumeStrategy.java | 5 +
.../support/PartitionAssignmentListener.java | 13 +-
.../consumer/support/ResumeStrategyFactory.java | 5 +
.../SeekPolicyKafkaConsumerResumeStrategy.java | 5 +
.../resume/kafka/AbstractKafkaResumeStrategy.java | 58 ++++-
.../KafkaConsumerWithResumeRouteStrategyIT.java | 239 +++++++++++++++++++++
.../KafkaConsumerWithResumeStrategyIT.java | 5 +
.../src/test/resources/log4j2.properties | 5 +-
.../main/java/org/apache/camel/ResumeAware.java | 10 +-
.../main/java/org/apache/camel/ResumeStrategy.java | 9 +-
.../src/main/java/org/apache/camel/Route.java | 5 +
.../org/apache/camel/impl/engine/DefaultRoute.java | 11 +
.../apache/camel/model/ProcessorDefinition.java | 13 ++
.../apache/camel/model/ResumableDefinition.java | 60 ++++++
.../processor/resume/ResumableCompletion.java | 61 ++++++
.../camel/processor/resume/ResumableProcessor.java | 151 +++++++++++++
.../org/apache/camel/reifier/ProcessorReifier.java | 3 +
.../org/apache/camel/reifier/ResumableReifier.java | 57 +++++
.../FileConsumerResumeFromOffsetStrategyTest.java | 5 +
.../file/FileConsumerResumeStrategyTest.java | 5 +
27 files changed, 820 insertions(+), 28 deletions(-)
diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-spring.xsd b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-spring.xsd
index f397503..2316c1d 100644
--- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-spring.xsd
+++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-spring.xsd
@@ -10510,6 +10510,107 @@ Reference to the rest-dsl.
</xs:attribute>
</xs:complexType>
+ <xs:complexType name="resumableDefinition">
+ <xs:complexContent>
+ <xs:extension base="tns:processorDefinition">
+ <xs:sequence>
+ <xs:choice>
+ <xs:element ref="tns:expressionDefinition"/>
+ <xs:element ref="tns:csimple"/>
+ <xs:element ref="tns:constant"/>
+ <xs:element ref="tns:datasonnet"/>
+ <xs:element ref="tns:exchangeProperty"/>
+ <xs:element ref="tns:groovy"/>
+ <xs:element ref="tns:header"/>
+ <xs:element ref="tns:hl7terser"/>
+ <xs:element ref="tns:joor"/>
+ <xs:element ref="tns:jsonpath"/>
+ <xs:element ref="tns:language"/>
+ <xs:element ref="tns:method"/>
+ <xs:element ref="tns:mvel"/>
+ <xs:element ref="tns:ognl"/>
+ <xs:element ref="tns:ref"/>
+ <xs:element ref="tns:simple"/>
+ <xs:element ref="tns:spel"/>
+ <xs:element ref="tns:tokenize"/>
+ <xs:element ref="tns:xtokenize"/>
+ <xs:element ref="tns:xpath"/>
+ <xs:element ref="tns:xquery"/>
+ </xs:choice>
+ <xs:choice maxOccurs="unbounded" minOccurs="0">
+ <xs:element ref="tns:aggregate"/>
+ <xs:element ref="tns:bean"/>
+ <xs:element ref="tns:doCatch"/>
+ <xs:element ref="tns:when"/>
+ <xs:element ref="tns:choice"/>
+ <xs:element ref="tns:otherwise"/>
+ <xs:element ref="tns:circuitBreaker"/>
+ <xs:element ref="tns:claimCheck"/>
+ <xs:element ref="tns:convertBodyTo"/>
+ <xs:element ref="tns:delay"/>
+ <xs:element ref="tns:dynamicRouter"/>
+ <xs:element ref="tns:enrich"/>
+ <xs:element ref="tns:filter"/>
+ <xs:element ref="tns:doFinally"/>
+ <xs:element ref="tns:idempotentConsumer"/>
+ <xs:element ref="tns:inOnly"/>
+ <xs:element ref="tns:inOut"/>
+ <xs:element ref="tns:intercept"/>
+ <xs:element ref="tns:interceptFrom"/>
+ <xs:element ref="tns:interceptSendToEndpoint"/>
+ <xs:element ref="tns:kamelet"/>
+ <xs:element ref="tns:loadBalance"/>
+ <xs:element ref="tns:log"/>
+ <xs:element ref="tns:loop"/>
+ <xs:element ref="tns:marshal"/>
+ <xs:element ref="tns:multicast"/>
+ <xs:element ref="tns:onCompletion"/>
+ <xs:element ref="tns:onException"/>
+ <xs:element ref="tns:onFallback"/>
+ <xs:element ref="tns:pipeline"/>
+ <xs:element ref="tns:policy"/>
+ <xs:element ref="tns:pollEnrich"/>
+ <xs:element ref="tns:process"/>
+ <xs:element ref="tns:recipientList"/>
+ <xs:element ref="tns:removeHeader"/>
+ <xs:element ref="tns:removeHeaders"/>
+ <xs:element ref="tns:removeProperties"/>
+ <xs:element ref="tns:removeProperty"/>
+ <xs:element ref="tns:resequence"/>
+ <xs:element ref="tns:rollback"/>
+ <xs:element ref="tns:route"/>
+ <xs:element ref="tns:routingSlip"/>
+ <xs:element ref="tns:saga"/>
+ <xs:element ref="tns:sample"/>
+ <xs:element ref="tns:script"/>
+ <xs:element ref="tns:setBody"/>
+ <xs:element ref="tns:setExchangePattern"/>
+ <xs:element ref="tns:setHeader"/>
+ <xs:element ref="tns:setProperty"/>
+ <xs:element ref="tns:sort"/>
+ <xs:element ref="tns:split"/>
+ <xs:element ref="tns:step"/>
+ <xs:element ref="tns:stop"/>
+ <xs:element ref="tns:doSwitch"/>
+ <xs:element ref="tns:threads"/>
+ <xs:element ref="tns:throttle"/>
+ <xs:element ref="tns:throwException"/>
+ <xs:element ref="tns:to"/>
+ <xs:element ref="tns:toD"/>
+ <xs:element ref="tns:transacted"/>
+ <xs:element ref="tns:transform"/>
+ <xs:element ref="tns:doTry"/>
+ <xs:element ref="tns:unmarshal"/>
+ <xs:element ref="tns:validate"/>
+ <xs:element ref="tns:wireTap"/>
+ <xs:element ref="tns:serviceCall"/>
+ </xs:choice>
+ </xs:sequence>
+ <xs:attribute name="resumeStrategyRef" type="xs:string" use="required"/>
+ </xs:extension>
+ </xs:complexContent>
+ </xs:complexType>
+
<xs:complexType name="rollbackDefinition">
<xs:complexContent>
<xs:extension base="tns:noOutputDefinition">
diff --git a/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/kinesis/consumer/KinesisResumeStrategy.java b/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/kinesis/consumer/KinesisResumeStrategy.java
index b6a000d..6c3ae6f 100644
--- a/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/kinesis/consumer/KinesisResumeStrategy.java
+++ b/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/kinesis/consumer/KinesisResumeStrategy.java
@@ -20,7 +20,7 @@ package org.apache.camel.component.aws2.kinesis.consumer;
import org.apache.camel.ResumeStrategy;
import software.amazon.awssdk.services.kinesis.model.GetShardIteratorRequest;
-public interface KinesisResumeStrategy extends ResumeStrategy<GetShardIteratorRequest.Builder> {
+public interface KinesisResumeStrategy extends ResumeStrategy {
void setRequestBuilder(GetShardIteratorRequest.Builder builder);
}
diff --git a/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/kinesis/consumer/KinesisUserConfigurationResumeStrategy.java b/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/kinesis/consumer/KinesisUserConfigurationResumeStrategy.java
index 5633443..e5c92fc 100644
--- a/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/kinesis/consumer/KinesisUserConfigurationResumeStrategy.java
+++ b/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/kinesis/consumer/KinesisUserConfigurationResumeStrategy.java
@@ -46,4 +46,9 @@ public class KinesisUserConfigurationResumeStrategy implements KinesisResumeStra
resumable.startingSequenceNumber(configuration.getSequenceNumber());
}
}
+
+ @Override
+ public void start() throws Exception {
+
+ }
}
diff --git a/components/camel-couchdb/src/main/java/org/apache/camel/component/couchdb/consumer/CouchDbResumeStrategy.java b/components/camel-couchdb/src/main/java/org/apache/camel/component/couchdb/consumer/CouchDbResumeStrategy.java
index b03b31d..14d87d4 100644
--- a/components/camel-couchdb/src/main/java/org/apache/camel/component/couchdb/consumer/CouchDbResumeStrategy.java
+++ b/components/camel-couchdb/src/main/java/org/apache/camel/component/couchdb/consumer/CouchDbResumeStrategy.java
@@ -22,6 +22,6 @@ import org.apache.camel.ResumeStrategy;
/**
* Defines a resumable strategy usable by the CouchDB component
*/
-public interface CouchDbResumeStrategy extends ResumeStrategy<CouchDbResumable> {
+public interface CouchDbResumeStrategy extends ResumeStrategy {
void setResumable(CouchDbResumable resumable);
}
diff --git a/components/camel-couchdb/src/main/java/org/apache/camel/component/couchdb/consumer/LatestUpdateSequenceResumeStrategy.java b/components/camel-couchdb/src/main/java/org/apache/camel/component/couchdb/consumer/LatestUpdateSequenceResumeStrategy.java
index 277d842..04679d8 100644
--- a/components/camel-couchdb/src/main/java/org/apache/camel/component/couchdb/consumer/LatestUpdateSequenceResumeStrategy.java
+++ b/components/camel-couchdb/src/main/java/org/apache/camel/component/couchdb/consumer/LatestUpdateSequenceResumeStrategy.java
@@ -36,4 +36,9 @@ public final class LatestUpdateSequenceResumeStrategy implements CouchDbResumeSt
resumable.updateLastOffset(clientWrapper.getLatestUpdateSequence());
}
+
+ @Override
+ public void start() throws Exception {
+
+ }
}
diff --git a/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/KafkaFetchRecords.java b/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/KafkaFetchRecords.java
index ed49fdf..deeef3c 100644
--- a/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/KafkaFetchRecords.java
+++ b/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/KafkaFetchRecords.java
@@ -28,6 +28,7 @@ import java.util.regex.Pattern;
import org.apache.camel.component.kafka.consumer.CommitManager;
import org.apache.camel.component.kafka.consumer.CommitManagers;
+import org.apache.camel.component.kafka.consumer.support.KafkaConsumerResumeStrategy;
import org.apache.camel.component.kafka.consumer.support.KafkaRecordProcessorFacade;
import org.apache.camel.component.kafka.consumer.support.PartitionAssignmentListener;
import org.apache.camel.component.kafka.consumer.support.ProcessingResult;
@@ -136,9 +137,12 @@ class KafkaFetchRecords implements Runnable {
}
private void subscribe() {
+ KafkaConsumerResumeStrategy userProvidedStrategy
+ = kafkaConsumer.getEndpoint().getCamelContext().hasService(KafkaConsumerResumeStrategy.class);
+
PartitionAssignmentListener listener = new PartitionAssignmentListener(
threadId, kafkaConsumer.getEndpoint().getConfiguration(), consumer, lastProcessedOffset,
- this::isRunnable, commitManager);
+ this::isRunnable, commitManager, userProvidedStrategy);
if (LOG.isInfoEnabled()) {
LOG.info("Subscribing {} to {}", threadId, getPrintableTopic());
diff --git a/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/consumer/support/KafkaConsumerResumeStrategy.java b/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/consumer/support/KafkaConsumerResumeStrategy.java
index c433745..35eb879 100644
--- a/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/consumer/support/KafkaConsumerResumeStrategy.java
+++ b/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/consumer/support/KafkaConsumerResumeStrategy.java
@@ -27,7 +27,7 @@ import org.apache.kafka.clients.consumer.Consumer;
* the component is set up to use more than one of them. As such, implementations are responsible for ensuring the
* thread-safety of the operations within the resume method.
*/
-public interface KafkaConsumerResumeStrategy extends ResumeStrategy<KafkaResumable> {
+public interface KafkaConsumerResumeStrategy extends ResumeStrategy {
void setConsumer(Consumer<?, ?> consumer);
default void resume(KafkaResumable resumable) {
diff --git a/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/consumer/support/OffsetKafkaConsumerResumeStrategy.java b/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/consumer/support/OffsetKafkaConsumerResumeStrategy.java
index 4502831..3875184 100644
--- a/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/consumer/support/OffsetKafkaConsumerResumeStrategy.java
+++ b/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/consumer/support/OffsetKafkaConsumerResumeStrategy.java
@@ -73,4 +73,9 @@ public class OffsetKafkaConsumerResumeStrategy implements KafkaConsumerResumeStr
public void resume(KafkaResumable resumable) {
resume();
}
+
+ @Override
+ public void start() throws Exception {
+
+ }
}
diff --git a/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/consumer/support/PartitionAssignmentListener.java b/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/consumer/support/PartitionAssignmentListener.java
index efedbe5..fe19147 100644
--- a/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/consumer/support/PartitionAssignmentListener.java
+++ b/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/consumer/support/PartitionAssignmentListener.java
@@ -38,7 +38,6 @@ public class PartitionAssignmentListener implements ConsumerRebalanceListener {
private final String threadId;
private final KafkaConfiguration configuration;
- private final Consumer consumer;
private final Map<String, Long> lastProcessedOffset;
private final KafkaConsumerResumeStrategy resumeStrategy;
private final CommitManager commitManager;
@@ -46,15 +45,21 @@ public class PartitionAssignmentListener implements ConsumerRebalanceListener {
public PartitionAssignmentListener(String threadId, KafkaConfiguration configuration,
Consumer consumer, Map<String, Long> lastProcessedOffset,
- Supplier<Boolean> stopStateSupplier, CommitManager commitManager) {
+ Supplier<Boolean> stopStateSupplier, CommitManager commitManager,
+ KafkaConsumerResumeStrategy resumeStrategy) {
this.threadId = threadId;
this.configuration = configuration;
- this.consumer = consumer;
this.lastProcessedOffset = lastProcessedOffset;
this.commitManager = commitManager;
this.stopStateSupplier = stopStateSupplier;
- this.resumeStrategy = ResumeStrategyFactory.newResumeStrategy(configuration);
+ if (resumeStrategy == null) {
+ LOG.info("No resume strategy was provided ... checking for builtins ...");
+ this.resumeStrategy = ResumeStrategyFactory.newResumeStrategy(configuration);
+ } else {
+ LOG.info("Using user-provided strategy");
+ this.resumeStrategy = resumeStrategy;
+ }
resumeStrategy.setConsumer(consumer);
}
diff --git a/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/consumer/support/ResumeStrategyFactory.java b/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/consumer/support/ResumeStrategyFactory.java
index 3465ef5..67707de 100644
--- a/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/consumer/support/ResumeStrategyFactory.java
+++ b/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/consumer/support/ResumeStrategyFactory.java
@@ -40,6 +40,11 @@ public final class ResumeStrategyFactory {
public void resume() {
}
+
+ @Override
+ public void start() throws Exception {
+
+ }
}
private static final NoOpKafkaConsumerResumeStrategy NO_OP_RESUME_STRATEGY = new NoOpKafkaConsumerResumeStrategy();
diff --git a/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/consumer/support/SeekPolicyKafkaConsumerResumeStrategy.java b/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/consumer/support/SeekPolicyKafkaConsumerResumeStrategy.java
index 91db91b..46fd974 100644
--- a/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/consumer/support/SeekPolicyKafkaConsumerResumeStrategy.java
+++ b/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/consumer/support/SeekPolicyKafkaConsumerResumeStrategy.java
@@ -58,4 +58,9 @@ public class SeekPolicyKafkaConsumerResumeStrategy implements KafkaConsumerResum
public void resume(KafkaResumable resumable) {
resume();
}
+
+ @Override
+ public void start() throws Exception {
+
+ }
}
diff --git a/components/camel-kafka/src/main/java/org/apache/camel/processor/resume/kafka/AbstractKafkaResumeStrategy.java b/components/camel-kafka/src/main/java/org/apache/camel/processor/resume/kafka/AbstractKafkaResumeStrategy.java
index c8bd037..4fad434 100644
--- a/components/camel-kafka/src/main/java/org/apache/camel/processor/resume/kafka/AbstractKafkaResumeStrategy.java
+++ b/components/camel-kafka/src/main/java/org/apache/camel/processor/resume/kafka/AbstractKafkaResumeStrategy.java
@@ -17,6 +17,7 @@
package org.apache.camel.processor.resume.kafka;
+import java.io.IOException;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Collection;
@@ -30,6 +31,7 @@ import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import org.apache.camel.Resumable;
+import org.apache.camel.Service;
import org.apache.camel.UpdatableConsumerResumeStrategy;
import org.apache.camel.util.StringHelper;
import org.apache.kafka.clients.consumer.Consumer;
@@ -49,7 +51,9 @@ import org.apache.kafka.common.serialization.StringSerializer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public abstract class AbstractKafkaResumeStrategy<K, V> implements UpdatableConsumerResumeStrategy<K, V, Resumable<K, V>> {
+public abstract class AbstractKafkaResumeStrategy<K, V>
+ implements UpdatableConsumerResumeStrategy<K, V, Resumable<K, V>>, Service {
+ public static final int UNLIMITED = -1;
private static final Logger LOG = LoggerFactory.getLogger(AbstractKafkaResumeStrategy.class);
private final String topic;
@@ -71,20 +75,13 @@ public abstract class AbstractKafkaResumeStrategy<K, V> implements UpdatableCons
this.consumerConfig = createConsumer(bootstrapServers);
}
- public AbstractKafkaResumeStrategy(String bootstrapServers, String topic, Properties producerConfig,
+ public AbstractKafkaResumeStrategy(String topic, Properties producerConfig,
Properties consumerConfig) {
this.topic = topic;
this.producerConfig = producerConfig;
this.consumerConfig = consumerConfig;
}
- public void start() throws Exception {
- consumer = new KafkaConsumer<>(consumerConfig);
- producer = new KafkaProducer<>(producerConfig);
-
- loadProcessedItems(processedItems);
- }
-
private Properties createProducer(String bootstrapServers) {
Properties config = new Properties();
@@ -157,7 +154,7 @@ public abstract class AbstractKafkaResumeStrategy<K, V> implements UpdatableCons
}
protected void loadProcessedItems(Map<K, List<V>> processed) throws Exception {
- loadProcessedItems(processed, -1);
+ loadProcessedItems(processed, UNLIMITED);
}
protected void loadProcessedItems(Map<K, List<V>> processed, int limit) throws Exception {
@@ -181,7 +178,7 @@ public abstract class AbstractKafkaResumeStrategy<K, V> implements UpdatableCons
var entries = processed.computeIfAbsent(record.key(), k -> new ArrayList<>());
entries.add(record.value());
- if (processed.size() >= limit) {
+ if (limit != UNLIMITED && processed.size() >= limit) {
break;
}
}
@@ -278,4 +275,43 @@ public abstract class AbstractKafkaResumeStrategy<K, V> implements UpdatableCons
return Collections.unmodifiableList(sentItems);
}
+ @Override
+ public void build() {
+ Service.super.build();
+ }
+
+ @Override
+ public void init() {
+ Service.super.init();
+
+ LOG.debug("Initializing the Kafka resume strategy");
+ if (consumer == null) {
+ consumer = new KafkaConsumer<>(consumerConfig);
+ }
+
+ if (producer == null) {
+ producer = new KafkaProducer<>(producerConfig);
+ }
+ }
+
+ @Override
+ public void stop() {
+
+ }
+
+ @Override
+ public void close() throws IOException {
+ Service.super.close();
+ }
+
+ @Override
+ public void start() {
+ LOG.info("Starting the kafka resume strategy");
+
+ try {
+ loadProcessedItems(processedItems);
+ } catch (Exception e) {
+ LOG.error("Failed to load already processed items: {}", e.getMessage(), e);
+ }
+ }
}
diff --git a/components/camel-kafka/src/test/java/org/apache/camel/component/kafka/integration/KafkaConsumerWithResumeRouteStrategyIT.java b/components/camel-kafka/src/test/java/org/apache/camel/component/kafka/integration/KafkaConsumerWithResumeRouteStrategyIT.java
new file mode 100644
index 0000000..5b0e828
--- /dev/null
+++ b/components/camel-kafka/src/test/java/org/apache/camel/component/kafka/integration/KafkaConsumerWithResumeRouteStrategyIT.java
@@ -0,0 +1,239 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.kafka.integration;
+
+import java.util.Collections;
+import java.util.Properties;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.camel.BindToRegistry;
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Offset;
+import org.apache.camel.Resumable;
+import org.apache.camel.Service;
+import org.apache.camel.UpdatableConsumerResumeStrategy;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.kafka.consumer.support.KafkaConsumerResumeStrategy;
+import org.apache.camel.component.kafka.consumer.support.KafkaResumable;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.resume.Resumables;
+import org.apache.kafka.clients.consumer.Consumer;
+import org.apache.kafka.clients.producer.KafkaProducer;
+import org.apache.kafka.clients.producer.ProducerRecord;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class KafkaConsumerWithResumeRouteStrategyIT extends BaseEmbeddedKafkaTestSupport {
+ private static final Logger LOG = LoggerFactory.getLogger(KafkaConsumerWithResumeRouteStrategyIT.class);
+
+ private static final String TOPIC = "resumable-route-tp";
+
+ @EndpointInject("mock:result")
+ private MockEndpoint result;
+
+ @BindToRegistry("resumeStrategy")
+ private TestKafkaConsumerResumeStrategy resumeStrategy;
+ private CountDownLatch messagesLatch;
+ private static final int RANDOM_VALUE = ThreadLocalRandom.current().nextInt(1, 1000);
+ private KafkaProducer<Object, Object> producer;
+
+ private static class TestKafkaConsumerResumeStrategy
+ implements KafkaConsumerResumeStrategy,
+ UpdatableConsumerResumeStrategy<String, Integer, Resumable<String, Integer>>, Service {
+ private final CountDownLatch messagesLatch;
+ private boolean resumeCalled;
+ private boolean consumerIsNull = true;
+ private boolean startCalled;
+ private boolean offsetNull = true;
+ private boolean offsetAddressableNull = true;
+ private boolean offsetAddressableEmpty = true;
+ private boolean offsetValueNull = true;
+ private boolean offsetValueEmpty = true;
+ private int lastOffset;
+
+ public TestKafkaConsumerResumeStrategy(CountDownLatch messagesLatch) {
+ this.messagesLatch = messagesLatch;
+ }
+
+ @Override
+ public void setConsumer(Consumer<?, ?> consumer) {
+ if (consumer != null) {
+ consumerIsNull = false;
+ }
+ }
+
+ @Override
+ public void resume(KafkaResumable resumable) {
+ resumeCalled = true;
+
+ }
+
+ @Override
+ public void resume() {
+ resumeCalled = true;
+ }
+
+ public boolean isResumeCalled() {
+ return resumeCalled;
+ }
+
+ public boolean isConsumerIsNull() {
+ return consumerIsNull;
+ }
+
+ @Override
+ public void start() {
+ LOG.warn("Start was called");
+ startCalled = true;
+ }
+
+ @Override
+ public void stop() {
+
+ }
+
+ @Override
+ public void init() {
+ Service.super.init();
+ LOG.warn("Init was called");
+ }
+
+ public boolean isStartCalled() {
+ return startCalled;
+ }
+
+ @Override
+ public void updateLastOffset(Resumable<String, Integer> offset) {
+ try {
+ if (offset != null) {
+ offsetNull = false;
+
+ String addressable = offset.getAddressable();
+ if (addressable != null) {
+ offsetAddressableNull = false;
+ offsetAddressableEmpty = addressable.isEmpty() || addressable.isBlank();
+
+ }
+
+ Offset<Integer> offsetValue = offset.getLastOffset();
+ if (offsetValue != null) {
+ offsetValueNull = false;
+
+ if (offsetValue.offset() != null) {
+ offsetValueEmpty = false;
+ lastOffset = offsetValue.offset();
+ }
+ }
+ }
+ } finally {
+ messagesLatch.countDown();
+ }
+ }
+
+ public boolean isOffsetNull() {
+ return offsetNull;
+ }
+
+ public boolean isOffsetAddressableNull() {
+ return offsetAddressableNull;
+ }
+
+ public boolean isOffsetValueNull() {
+ return offsetValueNull;
+ }
+
+ public boolean isOffsetAddressableEmpty() {
+ return offsetAddressableEmpty;
+ }
+
+ public boolean isOffsetValueEmpty() {
+ return offsetValueEmpty;
+ }
+ }
+
+ @BeforeEach
+ public void before() {
+ Properties props = getDefaultProperties();
+
+ for (int i = 0; i < 10; i++) {
+ producer = new org.apache.kafka.clients.producer.KafkaProducer<>(props);
+ producer.send(new ProducerRecord<>(TOPIC, String.valueOf(i)));
+ }
+ }
+
+ @Override
+ protected void doPreSetup() throws Exception {
+ super.doPreSetup();
+
+ messagesLatch = new CountDownLatch(1);
+ resumeStrategy = new TestKafkaConsumerResumeStrategy(messagesLatch);
+ }
+
+ @Test
+ // @Timeout(value = 30)
+ public void testOffsetIsBeingChecked() throws InterruptedException {
+ assertTrue(messagesLatch.await(100, TimeUnit.SECONDS), "The resume was not called");
+
+ assertTrue(resumeStrategy.isResumeCalled(),
+ "The resume strategy should have been called when the partition was assigned");
+ assertFalse(resumeStrategy.isConsumerIsNull(),
+ "The consumer passed to the strategy should not be null");
+ assertTrue(resumeStrategy.isStartCalled(),
+ "The resume strategy should have been started");
+ assertFalse(resumeStrategy.isOffsetNull(),
+ "The offset should not be null");
+ assertFalse(resumeStrategy.isOffsetAddressableNull(),
+ "The offset addressable should not be null");
+ assertFalse(resumeStrategy.isOffsetAddressableEmpty(),
+ "The offset addressable should not be empty");
+ assertFalse(resumeStrategy.isOffsetValueNull(),
+ "The offset value should not be null");
+ assertFalse(resumeStrategy.isOffsetValueEmpty(),
+ "The offset value should not be empty");
+ assertEquals(RANDOM_VALUE, resumeStrategy.lastOffset, "the offsets don't match");
+ }
+
+ @AfterEach
+ public void after() {
+ kafkaAdminClient.deleteTopics(Collections.singletonList(TOPIC));
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("kafka:" + TOPIC + "?groupId=" + TOPIC + "_GROUP&autoCommitIntervalMs=1000"
+ + "&autoOffsetReset=earliest&consumersCount=1")
+ .routeId("resume-strategy-route")
+ .setHeader("CamelOffset",
+ constant(Resumables.of("key", RANDOM_VALUE)))
+ .resumable().header("CamelOffset").resumableStrategyRef("resumeStrategy")
+ .to("mock:result");
+ }
+ };
+ }
+}
diff --git a/components/camel-kafka/src/test/java/org/apache/camel/component/kafka/integration/KafkaConsumerWithResumeStrategyIT.java b/components/camel-kafka/src/test/java/org/apache/camel/component/kafka/integration/KafkaConsumerWithResumeStrategyIT.java
index c9f9b95..fb8bae5 100644
--- a/components/camel-kafka/src/test/java/org/apache/camel/component/kafka/integration/KafkaConsumerWithResumeStrategyIT.java
+++ b/components/camel-kafka/src/test/java/org/apache/camel/component/kafka/integration/KafkaConsumerWithResumeStrategyIT.java
@@ -78,6 +78,11 @@ public class KafkaConsumerWithResumeStrategyIT extends BaseEmbeddedKafkaTestSupp
public boolean isConsumerIsNull() {
return consumerIsNull;
}
+
+ @Override
+ public void start() throws Exception {
+
+ }
}
@Override
diff --git a/components/camel-kafka/src/test/resources/log4j2.properties b/components/camel-kafka/src/test/resources/log4j2.properties
index 1c24e24..72b19cf 100644
--- a/components/camel-kafka/src/test/resources/log4j2.properties
+++ b/components/camel-kafka/src/test/resources/log4j2.properties
@@ -32,11 +32,14 @@ logger.camel.name=org.apache.camel
logger.camel.level=INFO
logger.camelKafka.name=org.apache.camel.component.kafka
-logger.camelKafka.level=INFO
+logger.camelKafka.level=DEBUG
logger.idem.name=org.apache.camel.processor.idempotent
logger.idem.level=INFO
+logger.resume.name=org.apache.camel.processor.resume.kafka
+logger.resume.level=INFO
+
logger.kafka.name=org.apache.kafka
logger.kafka.level=INFO
diff --git a/components/camel-couchdb/src/main/java/org/apache/camel/component/couchdb/consumer/CouchDbResumeStrategy.java b/core/camel-api/src/main/java/org/apache/camel/ResumeAware.java
similarity index 73%
copy from components/camel-couchdb/src/main/java/org/apache/camel/component/couchdb/consumer/CouchDbResumeStrategy.java
copy to core/camel-api/src/main/java/org/apache/camel/ResumeAware.java
index b03b31d..a04168f 100644
--- a/components/camel-couchdb/src/main/java/org/apache/camel/component/couchdb/consumer/CouchDbResumeStrategy.java
+++ b/core/camel-api/src/main/java/org/apache/camel/ResumeAware.java
@@ -15,13 +15,9 @@
* limitations under the License.
*/
-package org.apache.camel.component.couchdb.consumer;
+package org.apache.camel;
-import org.apache.camel.ResumeStrategy;
+public interface ResumeAware<T extends ResumeStrategy> {
-/**
- * Defines a resumable strategy usable by the CouchDB component
- */
-public interface CouchDbResumeStrategy extends ResumeStrategy<CouchDbResumable> {
- void setResumable(CouchDbResumable resumable);
+ void setResumeStrategy(T resumeStrategy);
}
diff --git a/core/camel-api/src/main/java/org/apache/camel/ResumeStrategy.java b/core/camel-api/src/main/java/org/apache/camel/ResumeStrategy.java
index e8c7f28..a271cd4 100644
--- a/core/camel-api/src/main/java/org/apache/camel/ResumeStrategy.java
+++ b/core/camel-api/src/main/java/org/apache/camel/ResumeStrategy.java
@@ -21,7 +21,7 @@ package org.apache.camel;
* Defines a strategy for handling resume operations. Implementations can define different ways to handle how to resume
* processing records.
*/
-public interface ResumeStrategy<T> {
+public interface ResumeStrategy {
/**
* A consumer, iterator or value class that can be used to set the index position from which to resume from. The
@@ -29,4 +29,11 @@ public interface ResumeStrategy<T> {
*
*/
void resume();
+
+ /**
+ * Starts the resume strategy
+ *
+ * @throws Exception
+ */
+ void start() throws Exception;
}
diff --git a/core/camel-api/src/main/java/org/apache/camel/Route.java b/core/camel-api/src/main/java/org/apache/camel/Route.java
index a575690..2d4e0cd 100644
--- a/core/camel-api/src/main/java/org/apache/camel/Route.java
+++ b/core/camel-api/src/main/java/org/apache/camel/Route.java
@@ -373,4 +373,9 @@ public interface Route extends RuntimeConfiguration {
*/
void addErrorHandlerFactoryReference(ErrorHandlerFactory source, ErrorHandlerFactory target);
+ /**
+ * Sets the resume strategy for the route
+ */
+ void setResumeStrategy(ResumeStrategy resumeStrategy);
+
}
diff --git a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultRoute.java b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultRoute.java
index 49f2a62..c102175 100644
--- a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultRoute.java
+++ b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultRoute.java
@@ -33,6 +33,8 @@ import org.apache.camel.ErrorHandlerFactory;
import org.apache.camel.NamedNode;
import org.apache.camel.Navigate;
import org.apache.camel.Processor;
+import org.apache.camel.ResumeAware;
+import org.apache.camel.ResumeStrategy;
import org.apache.camel.Route;
import org.apache.camel.RouteAware;
import org.apache.camel.Service;
@@ -87,6 +89,7 @@ public class DefaultRoute extends ServiceSupport implements Route {
private ShutdownRunningTask shutdownRunningTask;
private final Map<String, Processor> onCompletions = new HashMap<>();
private final Map<String, Processor> onExceptions = new HashMap<>();
+ private ResumeStrategy resumeStrategy;
// camel-core-model
private ErrorHandlerFactory errorHandlerFactory;
@@ -626,6 +629,10 @@ public class DefaultRoute extends ServiceSupport implements Route {
if (consumer instanceof RouteIdAware) {
((RouteIdAware) consumer).setRouteId(this.getId());
}
+
+ if (consumer instanceof ResumeAware) {
+ ((ResumeAware) consumer).setResumeStrategy(resumeStrategy);
+ }
}
if (processor instanceof Service) {
services.add((Service) processor);
@@ -699,4 +706,8 @@ public class DefaultRoute extends ServiceSupport implements Route {
return consumer instanceof Suspendable && consumer instanceof SuspendableService;
}
+ @Override
+ public void setResumeStrategy(ResumeStrategy resumeStrategy) {
+ this.resumeStrategy = resumeStrategy;
+ }
}
diff --git a/core/camel-core-model/src/main/java/org/apache/camel/model/ProcessorDefinition.java b/core/camel-core-model/src/main/java/org/apache/camel/model/ProcessorDefinition.java
index a5831df..cb0c74b 100644
--- a/core/camel-core-model/src/main/java/org/apache/camel/model/ProcessorDefinition.java
+++ b/core/camel-core-model/src/main/java/org/apache/camel/model/ProcessorDefinition.java
@@ -3774,6 +3774,19 @@ public abstract class ProcessorDefinition<Type extends ProcessorDefinition<Type>
return (Type) this;
}
+ /**
+ * This defines the route as resumable, which allows the route to work with the endpoints and components to manage
+ * the state of consumers and resume upon restart
+ *
+ * @return The expression to create the Resumable
+ */
+ public ExpressionClause<ResumableDefinition> resumable() {
+ ResumableDefinition answer = new ResumableDefinition();
+
+ addOutput(answer);
+ return createAndSetExpression(answer);
+ }
+
// Properties
// -------------------------------------------------------------------------
diff --git a/core/camel-core-model/src/main/java/org/apache/camel/model/ResumableDefinition.java b/core/camel-core-model/src/main/java/org/apache/camel/model/ResumableDefinition.java
new file mode 100644
index 0000000..3a92d32
--- /dev/null
+++ b/core/camel-core-model/src/main/java/org/apache/camel/model/ResumableDefinition.java
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.camel.model;
+
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlTransient;
+
+import org.apache.camel.ResumeStrategy;
+
+public class ResumableDefinition extends OutputExpressionNode {
+ @XmlAttribute(required = true)
+ private String resumeStrategyRef;
+
+ @XmlTransient
+ private ResumeStrategy resumeStrategy;
+
+ @Override
+ public String getShortName() {
+ return "resumable";
+ }
+
+ public String getResumeStrategyRef() {
+ return resumeStrategyRef;
+ }
+
+ public void setResumeStrategyRef(String resumeStrategyRef) {
+ this.resumeStrategyRef = resumeStrategyRef;
+ }
+
+ public ResumeStrategy getResumeStrategy() {
+ return resumeStrategy;
+ }
+
+ public void setResumeStrategy(ResumeStrategy resumeStrategy) {
+ this.resumeStrategy = resumeStrategy;
+ }
+
+ // Fluent API
+ // -------------------------------------------------------------------------
+ public ResumableDefinition resumableStrategyRef(String resumeStrategyRef) {
+ setResumeStrategyRef(resumeStrategyRef);
+
+ return this;
+ }
+}
diff --git a/core/camel-core-processor/src/main/java/org/apache/camel/processor/resume/ResumableCompletion.java b/core/camel-core-processor/src/main/java/org/apache/camel/processor/resume/ResumableCompletion.java
new file mode 100644
index 0000000..62dba42
--- /dev/null
+++ b/core/camel-core-processor/src/main/java/org/apache/camel/processor/resume/ResumableCompletion.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.camel.processor.resume;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Resumable;
+import org.apache.camel.ResumeStrategy;
+import org.apache.camel.UpdatableConsumerResumeStrategy;
+import org.apache.camel.spi.Synchronization;
+import org.apache.camel.support.ExchangeHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ResumableCompletion implements Synchronization {
+ private static final Logger LOG = LoggerFactory.getLogger(ResumableCompletion.class);
+
+ private final ResumeStrategy resumeStrategy;
+ private final Resumable<?, ?> resumable;
+
+ public ResumableCompletion(ResumeStrategy resumeStrategy, Resumable<?, ?> resumable) {
+ this.resumeStrategy = resumeStrategy;
+ this.resumable = resumable;
+ }
+
+ @Override
+ public void onComplete(Exchange exchange) {
+ if (!ExchangeHelper.isFailureHandled(exchange)) {
+ if (resumeStrategy instanceof UpdatableConsumerResumeStrategy) {
+ UpdatableConsumerResumeStrategy updatableConsumerResumeStrategy
+ = (UpdatableConsumerResumeStrategy) resumeStrategy;
+ try {
+ updatableConsumerResumeStrategy.updateLastOffset(resumable);
+ } catch (Exception e) {
+ LOG.error("Unable to update the offset: {}", e.getMessage(), e);
+ }
+ } else {
+ LOG.warn("Cannot perform an offset update because the strategy is not updatable");
+ }
+ }
+ }
+
+ @Override
+ public void onFailure(Exchange exchange) {
+ LOG.warn("Skipping offset update for {} due to failure in processing", resumable.getAddressable());
+ }
+}
diff --git a/core/camel-core-processor/src/main/java/org/apache/camel/processor/resume/ResumableProcessor.java b/core/camel-core-processor/src/main/java/org/apache/camel/processor/resume/ResumableProcessor.java
new file mode 100644
index 0000000..35cf8af
--- /dev/null
+++ b/core/camel-core-processor/src/main/java/org/apache/camel/processor/resume/ResumableProcessor.java
@@ -0,0 +1,151 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.camel.processor.resume;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+
+import org.apache.camel.AsyncCallback;
+import org.apache.camel.AsyncProcessor;
+import org.apache.camel.CamelContext;
+import org.apache.camel.CamelContextAware;
+import org.apache.camel.Exchange;
+import org.apache.camel.Expression;
+import org.apache.camel.Navigate;
+import org.apache.camel.Processor;
+import org.apache.camel.Resumable;
+import org.apache.camel.ResumeStrategy;
+import org.apache.camel.spi.IdAware;
+import org.apache.camel.spi.RouteIdAware;
+import org.apache.camel.spi.Synchronization;
+import org.apache.camel.support.AsyncProcessorConverterHelper;
+import org.apache.camel.support.AsyncProcessorSupport;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ResumableProcessor extends AsyncProcessorSupport
+ implements Navigate<Processor>, CamelContextAware, IdAware, RouteIdAware {
+ private static final Logger LOG = LoggerFactory.getLogger(ResumableProcessor.class);
+ private CamelContext camelContext;
+ private ResumeStrategy resumeStrategy;
+ private AsyncProcessor processor;
+ private final Expression offsetExpression;
+ private String id;
+ private String routeId;
+
+ private static class ResumableProcessorCallback implements AsyncCallback {
+
+ private final Exchange exchange;
+ private final Synchronization completion;
+ private final AsyncCallback callback;
+
+ public ResumableProcessorCallback(Exchange exchange, Synchronization completion, AsyncCallback callback) {
+ this.exchange = exchange;
+ this.completion = completion;
+ this.callback = callback;
+ }
+
+ @Override
+ public void done(boolean doneSync) {
+ try {
+ if (exchange.isFailed()) {
+ completion.onFailure(exchange);
+ } else {
+ completion.onComplete(exchange);
+ }
+ } finally {
+ callback.done(doneSync);
+ }
+ }
+ }
+
+ public ResumableProcessor(Expression offsetExpression, ResumeStrategy resumeStrategy, Processor processor) {
+ this.resumeStrategy = Objects.requireNonNull(resumeStrategy);
+ this.processor = AsyncProcessorConverterHelper.convert(processor);
+ this.offsetExpression = offsetExpression;
+
+ LOG.info("Enabling the resumable strategy of type: {}", resumeStrategy.getClass().getSimpleName());
+ }
+
+ @Override
+ public boolean process(final Exchange exchange, final AsyncCallback callback) {
+ Object offset = exchange.getMessage().getHeader("CamelOffset");
+
+ if (offset instanceof Resumable) {
+ Resumable<?, ?> resumable = (Resumable<?, ?>) offset;
+
+ LOG.warn("Processing the resumable: {}", resumable.getAddressable());
+ LOG.warn("Processing the resumable of type: {}", resumable.getLastOffset().offset());
+
+ final Synchronization onCompletion = new ResumableCompletion(resumeStrategy, resumable);
+ final AsyncCallback target = new ResumableProcessorCallback(exchange, onCompletion, callback);
+ return processor.process(exchange, target);
+
+ } else {
+ LOG.warn("Cannot update the last offset because it's not available");
+ }
+
+ return processor.process(exchange, callback);
+ }
+
+ @Override
+ public CamelContext getCamelContext() {
+ return camelContext;
+ }
+
+ @Override
+ public void setCamelContext(CamelContext camelContext) {
+ this.camelContext = camelContext;
+ }
+
+ @Override
+ public String getId() {
+ return id;
+ }
+
+ @Override
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ @Override
+ public String getRouteId() {
+ return routeId;
+ }
+
+ @Override
+ public void setRouteId(String routeId) {
+ this.routeId = routeId;
+ }
+
+ @Override
+ public List<Processor> next() {
+ if (!hasNext()) {
+ return null;
+ }
+ List<Processor> answer = new ArrayList<>(1);
+ answer.add(processor);
+ return answer;
+ }
+
+ @Override
+ public boolean hasNext() {
+ return processor != null;
+ }
+}
diff --git a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/ProcessorReifier.java b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/ProcessorReifier.java
index 2ee8bbd..42695ca 100644
--- a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/ProcessorReifier.java
+++ b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/ProcessorReifier.java
@@ -78,6 +78,7 @@ import org.apache.camel.model.RemoveHeadersDefinition;
import org.apache.camel.model.RemovePropertiesDefinition;
import org.apache.camel.model.RemovePropertyDefinition;
import org.apache.camel.model.ResequenceDefinition;
+import org.apache.camel.model.ResumableDefinition;
import org.apache.camel.model.RollbackDefinition;
import org.apache.camel.model.RouteDefinition;
import org.apache.camel.model.RouteDefinitionHelper;
@@ -313,6 +314,8 @@ public abstract class ProcessorReifier<T extends ProcessorDefinition<?>> extends
return new WhenSkipSendToEndpointReifier(route, definition);
} else if (definition instanceof WhenDefinition) {
return new WhenReifier(route, definition);
+ } else if (definition instanceof ResumableDefinition) {
+ return new ResumableReifier(route, definition);
}
return null;
}
diff --git a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/ResumableReifier.java b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/ResumableReifier.java
new file mode 100644
index 0000000..d6f683e
--- /dev/null
+++ b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/ResumableReifier.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.camel.reifier;
+
+import org.apache.camel.Expression;
+import org.apache.camel.Processor;
+import org.apache.camel.ResumeStrategy;
+import org.apache.camel.Route;
+import org.apache.camel.model.ProcessorDefinition;
+import org.apache.camel.model.ResumableDefinition;
+import org.apache.camel.processor.resume.ResumableProcessor;
+import org.apache.camel.util.ObjectHelper;
+
+public class ResumableReifier extends ExpressionReifier<ResumableDefinition> {
+ protected ResumableReifier(Route route, ProcessorDefinition<?> definition) {
+ super(route, ResumableDefinition.class.cast(definition));
+
+ }
+
+ @Override
+ public Processor createProcessor() throws Exception {
+ Processor childProcessor = createChildProcessor(false);
+
+ ResumeStrategy resumeStrategy = resolveResumeStrategy();
+ ObjectHelper.notNull(resumeStrategy, "resumeStrategy", definition);
+ route.setResumeStrategy(resumeStrategy);
+
+ Expression expression = createExpression(definition.getExpression());
+
+ return new ResumableProcessor(expression, resumeStrategy, childProcessor);
+ }
+
+ protected ResumeStrategy resolveResumeStrategy() {
+ String ref = parseString(definition.getResumeStrategyRef());
+
+ if (ref != null) {
+ definition.setResumeStrategy(mandatoryLookup(ref, ResumeStrategy.class));
+ }
+
+ return definition.getResumeStrategy();
+ }
+}
diff --git a/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerResumeFromOffsetStrategyTest.java b/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerResumeFromOffsetStrategyTest.java
index 62c4560..f12941d 100644
--- a/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerResumeFromOffsetStrategyTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerResumeFromOffsetStrategyTest.java
@@ -44,6 +44,11 @@ public class FileConsumerResumeFromOffsetStrategyTest extends ContextTestSupport
public void resume() {
// NO-OP
}
+
+ @Override
+ public void start() throws Exception {
+
+ }
}
@DisplayName("Tests whether we can resume from an offset")
diff --git a/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerResumeStrategyTest.java b/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerResumeStrategyTest.java
index 129399c..d70134e 100644
--- a/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerResumeStrategyTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerResumeStrategyTest.java
@@ -47,6 +47,11 @@ public class FileConsumerResumeStrategyTest extends ContextTestSupport {
resumeSet.resumeEach(f -> !processedFiles.contains(f.getName()));
}
}
+
+ @Override
+ public void start() throws Exception {
+
+ }
}
@Test
[camel] 07/16: CAMEL-15562: abstract the underlying cache so it's configurable
Posted by or...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 6a55b310a0606c290d99bb41d77ce08df35c9c82
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Wed Feb 23 14:57:44 2022 +0100
CAMEL-15562: abstract the underlying cache so it's configurable
---
.../resume/kafka/AbstractKafkaResumeStrategy.java | 40 +++++++----------
.../main/java/org/apache/camel/ResumeCache.java | 52 ++++++++++++++++++++++
2 files changed, 68 insertions(+), 24 deletions(-)
diff --git a/components/camel-kafka/src/main/java/org/apache/camel/processor/resume/kafka/AbstractKafkaResumeStrategy.java b/components/camel-kafka/src/main/java/org/apache/camel/processor/resume/kafka/AbstractKafkaResumeStrategy.java
index 4fad434..a779c00 100644
--- a/components/camel-kafka/src/main/java/org/apache/camel/processor/resume/kafka/AbstractKafkaResumeStrategy.java
+++ b/components/camel-kafka/src/main/java/org/apache/camel/processor/resume/kafka/AbstractKafkaResumeStrategy.java
@@ -23,14 +23,13 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
-import java.util.Map;
import java.util.Properties;
-import java.util.TreeMap;
import java.util.UUID;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import org.apache.camel.Resumable;
+import org.apache.camel.ResumeCache;
import org.apache.camel.Service;
import org.apache.camel.UpdatableConsumerResumeStrategy;
import org.apache.camel.util.StringHelper;
@@ -62,24 +61,30 @@ public abstract class AbstractKafkaResumeStrategy<K, V>
private Producer<K, V> producer;
private long errorCount;
- private Map<K, List<V>> processedItems = new TreeMap<>();
- private List<Future<RecordMetadata>> sentItems = new ArrayList<>();
+ private final List<Future<RecordMetadata>> sentItems = new ArrayList<>();
+ private final ResumeCache<K, V> resumeCache;
private boolean subscribed;
private Properties producerConfig;
private Properties consumerConfig;
- public AbstractKafkaResumeStrategy(String bootstrapServers, String topic) {
+ public AbstractKafkaResumeStrategy(String bootstrapServers, String topic, ResumeCache<K, V> resumeCache) {
this.topic = topic;
this.producerConfig = createProducer(bootstrapServers);
this.consumerConfig = createConsumer(bootstrapServers);
+ this.resumeCache = resumeCache;
+
+ init();
}
- public AbstractKafkaResumeStrategy(String topic, Properties producerConfig,
+ public AbstractKafkaResumeStrategy(String topic, ResumeCache<K, V> resumeCache, Properties producerConfig,
Properties consumerConfig) {
this.topic = topic;
+ this.resumeCache = resumeCache;
this.producerConfig = producerConfig;
this.consumerConfig = consumerConfig;
+
+ init();
}
private Properties createProducer(String bootstrapServers) {
@@ -148,22 +153,15 @@ public abstract class AbstractKafkaResumeStrategy<K, V>
produce(topic, key, offsetValue);
- // TODO: this leaks. It must be fixed for merge
- var entries = processedItems.computeIfAbsent(key, k -> new ArrayList<>());
- entries.add(offsetValue);
- }
-
- protected void loadProcessedItems(Map<K, List<V>> processed) throws Exception {
- loadProcessedItems(processed, UNLIMITED);
+ resumeCache.add(key, offsetValue);
}
- protected void loadProcessedItems(Map<K, List<V>> processed, int limit) throws Exception {
+ protected void loadCache() throws Exception {
subscribe();
LOG.debug("Loading records from topic {}", topic);
ConsumerRecords<K, V> records;
-
do {
records = consume();
@@ -175,16 +173,14 @@ public abstract class AbstractKafkaResumeStrategy<K, V>
V value = record.value();
LOG.trace("Read from Kafka: {}", value);
- var entries = processed.computeIfAbsent(record.key(), k -> new ArrayList<>());
- entries.add(record.value());
+ resumeCache.add(record.key(), record.value());
- if (limit != UNLIMITED && processed.size() >= limit) {
+ if (resumeCache.isFull()) {
break;
}
}
} while (true);
- LOG.debug("Loaded {} records", processed.size());
unsubscribe();
}
@@ -263,10 +259,6 @@ public abstract class AbstractKafkaResumeStrategy<K, V>
return ConsumerRecords.empty();
}
- protected Map<K, List<V>> getProcessedItems() {
- return processedItems;
- }
-
public long getErrorCount() {
return errorCount;
}
@@ -309,7 +301,7 @@ public abstract class AbstractKafkaResumeStrategy<K, V>
LOG.info("Starting the kafka resume strategy");
try {
- loadProcessedItems(processedItems);
+ loadCache();
} catch (Exception e) {
LOG.error("Failed to load already processed items: {}", e.getMessage(), e);
}
diff --git a/core/camel-api/src/main/java/org/apache/camel/ResumeCache.java b/core/camel-api/src/main/java/org/apache/camel/ResumeCache.java
new file mode 100644
index 0000000..0abe2e6
--- /dev/null
+++ b/core/camel-api/src/main/java/org/apache/camel/ResumeCache.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.camel;
+
+import java.util.Optional;
+
+/**
+ * This cache stored the resumed data from a {@link ResumeStrategy}.
+ *
+ * @param <K> the type of the key
+ * @param <V> the type of the offset value
+ */
+public interface ResumeCache<K, V> {
+
+ /**
+ * Adds a value to the cache
+ *
+ * @param key the key to add
+ * @param offsetValue the offset value
+ */
+ void add(K key, V offsetValue);
+
+ /**
+ * Checks whether the cache is full
+ *
+ * @return true if full, or false otherwise
+ */
+ boolean isFull();
+
+ /**
+ * Gets the offset value for the key
+ *
+ * @param key the key
+ * @return the key
+ */
+ Optional<V> get(K key);
+}
[camel] 11/16: CAMEL-15562: minor cleanups for the Kafka strategy
Posted by or...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 616b50d4851e712ae563e337e7f12c155697b1c9
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Mon Feb 28 13:51:57 2022 +0100
CAMEL-15562: minor cleanups for the Kafka strategy
---
.../resume/kafka/AbstractKafkaResumeStrategy.java | 37 ++++++++++++++--------
1 file changed, 24 insertions(+), 13 deletions(-)
diff --git a/components/camel-kafka/src/main/java/org/apache/camel/processor/resume/kafka/AbstractKafkaResumeStrategy.java b/components/camel-kafka/src/main/java/org/apache/camel/processor/resume/kafka/AbstractKafkaResumeStrategy.java
index a779c00..079d936 100644
--- a/components/camel-kafka/src/main/java/org/apache/camel/processor/resume/kafka/AbstractKafkaResumeStrategy.java
+++ b/components/camel-kafka/src/main/java/org/apache/camel/processor/resume/kafka/AbstractKafkaResumeStrategy.java
@@ -87,7 +87,13 @@ public abstract class AbstractKafkaResumeStrategy<K, V>
init();
}
- private Properties createProducer(String bootstrapServers) {
+ /**
+ * Creates a basic string-based producer
+ *
+ * @param bootstrapServers the Kafka host
+ * @return A set of default properties for producing string-based key/pair records from Kafka
+ */
+ public static Properties createProducer(String bootstrapServers) {
Properties config = new Properties();
config.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());
@@ -96,15 +102,16 @@ public abstract class AbstractKafkaResumeStrategy<K, V>
StringHelper.notEmpty(bootstrapServers, "bootstrapServers");
config.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);
- // set up the producer to remove all batching on send, we want all sends
- // to be fully synchronous
- config.putIfAbsent(ProducerConfig.ACKS_CONFIG, "1");
- config.putIfAbsent(ProducerConfig.BATCH_SIZE_CONFIG, "0");
-
return config;
}
- private Properties createConsumer(String bootstrapServers) {
+ /**
+ * Creates a basic string-based consumer
+ *
+ * @param bootstrapServers the Kafka host
+ * @return A set of default properties for consuming string-based key/pair records from Kafka
+ */
+ public static Properties createConsumer(String bootstrapServers) {
Properties config = new Properties();
config.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class.getName());
@@ -124,13 +131,12 @@ public abstract class AbstractKafkaResumeStrategy<K, V>
/**
* Sends data to a topic
- *
- * @param topic the topic to send data to
+ *
* @param message the message to send
* @throws ExecutionException
* @throws InterruptedException
*/
- public void produce(String topic, K key, V message) throws ExecutionException, InterruptedException {
+ public void produce(K key, V message) throws ExecutionException, InterruptedException {
ProducerRecord<K, V> record = new ProducerRecord<>(topic, key, message);
errorCount = 0;
@@ -151,7 +157,7 @@ public abstract class AbstractKafkaResumeStrategy<K, V>
LOG.debug("Updating offset on Kafka with key {} to {}", key, offsetValue);
- produce(topic, key, offsetValue);
+ produce(key, offsetValue);
resumeCache.add(key, offsetValue);
}
@@ -231,9 +237,14 @@ public abstract class AbstractKafkaResumeStrategy<K, V>
public abstract void subscribe() throws Exception;
- // TODO: bad method
public void unsubscribe() {
- consumer.unsubscribe();
+ try {
+ consumer.unsubscribe();
+ } catch (IllegalStateException e) {
+ LOG.warn("The consumer is likely already closed. Skipping unsubscribing from {}", topic);
+ } catch (Exception e) {
+ LOG.error("Error unsubscribing from the Kafka topic {}: {}", topic, e.getMessage(), e);
+ }
}
/**
[camel] 12/16: CAMEL-155623: implement getters on the ResumeAware
Posted by or...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
commit de8389ccc863928126bcc85b0123275bd3e28770
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Tue Mar 1 10:44:03 2022 +0100
CAMEL-155623: implement getters on the ResumeAware
This ensures compliance with others xxxAware classes
---
.../apache/camel/component/couchdb/CouchDbConsumer.java | 1 +
.../org/apache/camel/component/file/FileConsumer.java | 6 ++++++
.../org/apache/camel/component/kafka/KafkaConsumer.java | 1 +
.../src/main/java/org/apache/camel/ResumeAware.java | 15 +++++++++++++++
4 files changed, 23 insertions(+)
diff --git a/components/camel-couchdb/src/main/java/org/apache/camel/component/couchdb/CouchDbConsumer.java b/components/camel-couchdb/src/main/java/org/apache/camel/component/couchdb/CouchDbConsumer.java
index 1a22bf3..615823c 100644
--- a/components/camel-couchdb/src/main/java/org/apache/camel/component/couchdb/CouchDbConsumer.java
+++ b/components/camel-couchdb/src/main/java/org/apache/camel/component/couchdb/CouchDbConsumer.java
@@ -44,6 +44,7 @@ public class CouchDbConsumer extends DefaultConsumer implements ResumeAware<Couc
this.resumeStrategy = resumeStrategy;
}
+ @Override
public CouchDbResumeStrategy getResumeStrategy() {
return resumeStrategy;
}
diff --git a/components/camel-file/src/main/java/org/apache/camel/component/file/FileConsumer.java b/components/camel-file/src/main/java/org/apache/camel/component/file/FileConsumer.java
index 1b3ae3b..1f5ca77 100644
--- a/components/camel-file/src/main/java/org/apache/camel/component/file/FileConsumer.java
+++ b/components/camel-file/src/main/java/org/apache/camel/component/file/FileConsumer.java
@@ -307,7 +307,13 @@ public class FileConsumer extends GenericFileConsumer<File> implements ResumeAwa
}
@Override
+ public FileConsumerResumeStrategy getResumeStrategy() {
+ return resumeStrategy;
+ }
+
+ @Override
public void setResumeStrategy(FileConsumerResumeStrategy resumeStrategy) {
this.resumeStrategy = resumeStrategy;
}
+
}
diff --git a/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/KafkaConsumer.java b/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/KafkaConsumer.java
index eaefec2..692a505 100644
--- a/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/KafkaConsumer.java
+++ b/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/KafkaConsumer.java
@@ -59,6 +59,7 @@ public class KafkaConsumer extends DefaultConsumer implements ResumeAware<KafkaC
this.resumeStrategy = resumeStrategy;
}
+ @Override
public KafkaConsumerResumeStrategy getResumeStrategy() {
return resumeStrategy;
}
diff --git a/core/camel-api/src/main/java/org/apache/camel/ResumeAware.java b/core/camel-api/src/main/java/org/apache/camel/ResumeAware.java
index a04168f..6ee69db 100644
--- a/core/camel-api/src/main/java/org/apache/camel/ResumeAware.java
+++ b/core/camel-api/src/main/java/org/apache/camel/ResumeAware.java
@@ -17,7 +17,22 @@
package org.apache.camel;
+/**
+ * An interface to represent an object which wishes to support resume operations using a {@link ResumeStrategy}.
+ */
public interface ResumeAware<T extends ResumeStrategy> {
+ /**
+ * Injects the {@link ResumeStrategy} instance into the object
+ *
+ * @param resumeStrategy the resume strategy
+ */
void setResumeStrategy(T resumeStrategy);
+
+ /**
+ * Gets the {@link ResumeStrategy} instance
+ *
+ * @return the resume strategy
+ */
+ T getResumeStrategy();
}
[camel] 16/16: CAMEL-15562: simplify the resumable processor lifecycle
Posted by or...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
commit cfe69f612a76f6ae9222209c045eed940fd276c1
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Tue Mar 1 13:37:19 2022 +0100
CAMEL-15562: simplify the resumable processor lifecycle
---
.../java/org/apache/camel/processor/resume/ResumableProcessor.java | 4 +++-
.../src/main/java/org/apache/camel/reifier/ResumableReifier.java | 1 -
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/core/camel-core-processor/src/main/java/org/apache/camel/processor/resume/ResumableProcessor.java b/core/camel-core-processor/src/main/java/org/apache/camel/processor/resume/ResumableProcessor.java
index ebc4d78..a31196c 100644
--- a/core/camel-core-processor/src/main/java/org/apache/camel/processor/resume/ResumableProcessor.java
+++ b/core/camel-core-processor/src/main/java/org/apache/camel/processor/resume/ResumableProcessor.java
@@ -80,7 +80,8 @@ public class ResumableProcessor extends AsyncProcessorSupport
@Override
protected void doStart() throws Exception {
- LOG.debug("Enabling the resumable strategy of type: {}", resumeStrategy.getClass().getSimpleName());
+ LOG.info("Starting the resumable strategy: {}", resumeStrategy.getClass().getSimpleName());
+ resumeStrategy.start();
super.doStart();
}
@@ -150,4 +151,5 @@ public class ResumableProcessor extends AsyncProcessorSupport
public boolean hasNext() {
return processor != null;
}
+
}
diff --git a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/ResumableReifier.java b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/ResumableReifier.java
index 9fcb1a5..1d19634 100644
--- a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/ResumableReifier.java
+++ b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/ResumableReifier.java
@@ -37,7 +37,6 @@ public class ResumableReifier extends ProcessorReifier<ResumableDefinition> {
ResumeStrategy resumeStrategy = resolveResumeStrategy();
ObjectHelper.notNull(resumeStrategy, "resumeStrategy", definition);
- resumeStrategy.start();
route.setResumeStrategy(resumeStrategy);
return new ResumableProcessor(resumeStrategy, childProcessor);
[camel] 06/16: CAMEL-15562: further simplification of the API
Posted by or...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 63fc1e07e814a5146731e9747345a4b6dc2919c8
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Mon Feb 21 15:43:55 2022 +0100
CAMEL-15562: further simplification of the API
- standardize the offset header
- fixed tests
---
.../KafkaConsumerWithResumeRouteStrategyIT.java | 5 +--
.../org/apache/camel/ExchangeConstantProvider.java | 3 +-
.../src/main/java/org/apache/camel/Exchange.java | 1 +
.../apache/camel/model/ProcessorDefinition.java | 4 +--
.../camel/processor/resume/NoOffsetException.java | 41 ++++++++++++++++++++++
.../camel/processor/resume/ResumableProcessor.java | 11 +++---
.../org/apache/camel/reifier/ResumableReifier.java | 5 +--
.../FileConsumerResumeFromOffsetStrategyTest.java | 24 +++++++++++--
.../file/FileConsumerResumeStrategyTest.java | 15 ++++++--
9 files changed, 87 insertions(+), 22 deletions(-)
diff --git a/components/camel-kafka/src/test/java/org/apache/camel/component/kafka/integration/KafkaConsumerWithResumeRouteStrategyIT.java b/components/camel-kafka/src/test/java/org/apache/camel/component/kafka/integration/KafkaConsumerWithResumeRouteStrategyIT.java
index 1f95f30..aeb5de3 100644
--- a/components/camel-kafka/src/test/java/org/apache/camel/component/kafka/integration/KafkaConsumerWithResumeRouteStrategyIT.java
+++ b/components/camel-kafka/src/test/java/org/apache/camel/component/kafka/integration/KafkaConsumerWithResumeRouteStrategyIT.java
@@ -24,6 +24,7 @@ import java.util.concurrent.TimeUnit;
import org.apache.camel.BindToRegistry;
import org.apache.camel.EndpointInject;
+import org.apache.camel.Exchange;
import org.apache.camel.Offset;
import org.apache.camel.Resumable;
import org.apache.camel.Service;
@@ -228,9 +229,9 @@ public class KafkaConsumerWithResumeRouteStrategyIT extends BaseEmbeddedKafkaTes
from("kafka:" + TOPIC + "?groupId=" + TOPIC + "_GROUP&autoCommitIntervalMs=1000"
+ "&autoOffsetReset=earliest&consumersCount=1")
.routeId("resume-strategy-route")
- .setHeader("CamelOffset",
+ .setHeader(Exchange.OFFSET,
constant(Resumables.of("key", RANDOM_VALUE)))
- .resumable().header("CamelOffset").resumableStrategyRef("resumeStrategy")
+ .resumable().resumableStrategyRef("resumeStrategy")
.to("mock:result");
}
};
diff --git a/core/camel-api/src/generated/java/org/apache/camel/ExchangeConstantProvider.java b/core/camel-api/src/generated/java/org/apache/camel/ExchangeConstantProvider.java
index a9e6e6f..b9ff62d 100644
--- a/core/camel-api/src/generated/java/org/apache/camel/ExchangeConstantProvider.java
+++ b/core/camel-api/src/generated/java/org/apache/camel/ExchangeConstantProvider.java
@@ -11,7 +11,7 @@ public class ExchangeConstantProvider {
private static final Map<String, String> MAP;
static {
- Map<String, String> map = new HashMap<>(151);
+ Map<String, String> map = new HashMap<>(152);
map.put("ACCEPT_CONTENT_TYPE", "CamelAcceptContentType");
map.put("AGGREGATED_COLLECTION_GUARD", "CamelAggregatedCollectionGuard");
map.put("AGGREGATED_COMPLETED_BY", "CamelAggregatedCompletedBy");
@@ -114,6 +114,7 @@ public class ExchangeConstantProvider {
map.put("MULTICAST_COMPLETE", "CamelMulticastComplete");
map.put("MULTICAST_INDEX", "CamelMulticastIndex");
map.put("NOTIFY_EVENT", "CamelNotifyEvent");
+ map.put("OFFSET", "CamelOffset");
map.put("ON_COMPLETION", "CamelOnCompletion");
map.put("ON_COMPLETION_ROUTE_IDS", "CamelOnCompletionRouteIds");
map.put("OVERRULE_FILE_NAME", "CamelOverruleFileName");
diff --git a/core/camel-api/src/main/java/org/apache/camel/Exchange.java b/core/camel-api/src/main/java/org/apache/camel/Exchange.java
index 7cce1f2..c44b73c 100644
--- a/core/camel-api/src/main/java/org/apache/camel/Exchange.java
+++ b/core/camel-api/src/main/java/org/apache/camel/Exchange.java
@@ -194,6 +194,7 @@ public interface Exchange {
String ON_COMPLETION = "CamelOnCompletion";
String ON_COMPLETION_ROUTE_IDS = "CamelOnCompletionRouteIds";
+ String OFFSET = "CamelOffset";
String OVERRULE_FILE_NAME = "CamelOverruleFileName";
String PARENT_UNIT_OF_WORK = "CamelParentUnitOfWork";
diff --git a/core/camel-core-model/src/main/java/org/apache/camel/model/ProcessorDefinition.java b/core/camel-core-model/src/main/java/org/apache/camel/model/ProcessorDefinition.java
index cb0c74b..7769c3e 100644
--- a/core/camel-core-model/src/main/java/org/apache/camel/model/ProcessorDefinition.java
+++ b/core/camel-core-model/src/main/java/org/apache/camel/model/ProcessorDefinition.java
@@ -3780,11 +3780,11 @@ public abstract class ProcessorDefinition<Type extends ProcessorDefinition<Type>
*
* @return The expression to create the Resumable
*/
- public ExpressionClause<ResumableDefinition> resumable() {
+ public ResumableDefinition resumable() {
ResumableDefinition answer = new ResumableDefinition();
addOutput(answer);
- return createAndSetExpression(answer);
+ return answer;
}
// Properties
diff --git a/core/camel-core-processor/src/main/java/org/apache/camel/processor/resume/NoOffsetException.java b/core/camel-core-processor/src/main/java/org/apache/camel/processor/resume/NoOffsetException.java
new file mode 100644
index 0000000..3621a70
--- /dev/null
+++ b/core/camel-core-processor/src/main/java/org/apache/camel/processor/resume/NoOffsetException.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.camel.processor.resume;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.RuntimeCamelException;
+
+/**
+ * An exception thrown if no camel offset header could be found on the message.
+ */
+public class NoOffsetException extends RuntimeCamelException {
+
+ private final Exchange exchange;
+
+ public NoOffsetException(Exchange exchange) {
+ super("There was no " + Exchange.OFFSET + " header defined on the message exchange: " + exchange);
+ this.exchange = exchange;
+ }
+
+ /**
+ * The exchange which caused this failure
+ */
+ public Exchange getExchange() {
+ return exchange;
+ }
+}
diff --git a/core/camel-core-processor/src/main/java/org/apache/camel/processor/resume/ResumableProcessor.java b/core/camel-core-processor/src/main/java/org/apache/camel/processor/resume/ResumableProcessor.java
index 35cf8af..4c64a1c 100644
--- a/core/camel-core-processor/src/main/java/org/apache/camel/processor/resume/ResumableProcessor.java
+++ b/core/camel-core-processor/src/main/java/org/apache/camel/processor/resume/ResumableProcessor.java
@@ -26,7 +26,6 @@ import org.apache.camel.AsyncProcessor;
import org.apache.camel.CamelContext;
import org.apache.camel.CamelContextAware;
import org.apache.camel.Exchange;
-import org.apache.camel.Expression;
import org.apache.camel.Navigate;
import org.apache.camel.Processor;
import org.apache.camel.Resumable;
@@ -45,7 +44,6 @@ public class ResumableProcessor extends AsyncProcessorSupport
private CamelContext camelContext;
private ResumeStrategy resumeStrategy;
private AsyncProcessor processor;
- private final Expression offsetExpression;
private String id;
private String routeId;
@@ -75,17 +73,16 @@ public class ResumableProcessor extends AsyncProcessorSupport
}
}
- public ResumableProcessor(Expression offsetExpression, ResumeStrategy resumeStrategy, Processor processor) {
+ public ResumableProcessor(ResumeStrategy resumeStrategy, Processor processor) {
this.resumeStrategy = Objects.requireNonNull(resumeStrategy);
this.processor = AsyncProcessorConverterHelper.convert(processor);
- this.offsetExpression = offsetExpression;
LOG.info("Enabling the resumable strategy of type: {}", resumeStrategy.getClass().getSimpleName());
}
@Override
public boolean process(final Exchange exchange, final AsyncCallback callback) {
- Object offset = exchange.getMessage().getHeader("CamelOffset");
+ Object offset = exchange.getMessage().getHeader(Exchange.OFFSET);
if (offset instanceof Resumable) {
Resumable<?, ?> resumable = (Resumable<?, ?>) offset;
@@ -98,10 +95,10 @@ public class ResumableProcessor extends AsyncProcessorSupport
return processor.process(exchange, target);
} else {
+ exchange.setException(new NoOffsetException(exchange));
LOG.warn("Cannot update the last offset because it's not available");
+ return true;
}
-
- return processor.process(exchange, callback);
}
@Override
diff --git a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/ResumableReifier.java b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/ResumableReifier.java
index 6eba53f..ecf626a 100644
--- a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/ResumableReifier.java
+++ b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/ResumableReifier.java
@@ -17,7 +17,6 @@
package org.apache.camel.reifier;
-import org.apache.camel.Expression;
import org.apache.camel.Processor;
import org.apache.camel.ResumeStrategy;
import org.apache.camel.Route;
@@ -41,9 +40,7 @@ public class ResumableReifier extends ExpressionReifier<ResumableDefinition> {
resumeStrategy.start();
route.setResumeStrategy(resumeStrategy);
- Expression expression = createExpression(definition.getExpression());
-
- return new ResumableProcessor(expression, resumeStrategy, childProcessor);
+ return new ResumableProcessor(resumeStrategy, childProcessor);
}
protected ResumeStrategy resolveResumeStrategy() {
diff --git a/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerResumeFromOffsetStrategyTest.java b/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerResumeFromOffsetStrategyTest.java
index 2ef283c..fdf0315 100644
--- a/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerResumeFromOffsetStrategyTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerResumeFromOffsetStrategyTest.java
@@ -55,7 +55,7 @@ public class FileConsumerResumeFromOffsetStrategyTest extends ContextTestSupport
}
}
- @DisplayName("Tests whether we can resume from an offset")
+ @DisplayName("Tests whether it can resume from an offset")
@Test
public void testResumeFromOffset() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
@@ -63,7 +63,7 @@ public class FileConsumerResumeFromOffsetStrategyTest extends ContextTestSupport
Map<String, Object> headers = new HashMap<>();
headers.put(Exchange.FILE_NAME, "resume-from-offset.txt");
- headers.put("CamelOffset", Resumables.of("resume-from-offset.txt", 3L));
+ headers.put(Exchange.OFFSET, Resumables.of("resume-from-offset.txt", 3L));
template.sendBodyAndHeaders(fileUri("resumeOff"), "01234567890", headers);
@@ -71,6 +71,17 @@ public class FileConsumerResumeFromOffsetStrategyTest extends ContextTestSupport
assertMockEndpointsSatisfied();
}
+ @DisplayName("Tests whether it a missing offset causes a failure")
+ @Test
+ public void testMissingOffset() throws InterruptedException {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedBodiesReceivedInAnyOrder("34567890");
+
+ template.sendBodyAndHeader(fileUri("resumeMissingOffset"), "01234567890", Exchange.FILE_NAME, "resume-from-offset.txt");
+
+ mock.assertIsNotSatisfied();
+ }
+
@DisplayName("Tests whether we can start from the beginning (i.e.: no resume strategy)")
@Test
public void testNoResume() throws Exception {
@@ -92,7 +103,14 @@ public class FileConsumerResumeFromOffsetStrategyTest extends ContextTestSupport
bindToRegistry("resumeStrategy", new TestResumeStrategy());
from(fileUri("resumeOff?noop=true&recursive=true"))
- .resumable().header("CamelOffset").resumableStrategyRef("resumeStrategy")
+ .setHeader(Exchange.OFFSET,
+ constant(Resumables.of("resume-none.txt", 3)))
+ .resumable().resumableStrategyRef("resumeStrategy")
+ .log("${body}")
+ .convertBodyTo(String.class).to("mock:result");
+
+ from(fileUri("resumeMissingOffset?noop=true&recursive=true"))
+ .resumable().resumableStrategyRef("resumeStrategy")
.log("${body}")
.convertBodyTo(String.class).to("mock:result");
diff --git a/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerResumeStrategyTest.java b/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerResumeStrategyTest.java
index e867cf2..5adb2dd 100644
--- a/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerResumeStrategyTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerResumeStrategyTest.java
@@ -59,7 +59,7 @@ public class FileConsumerResumeStrategyTest extends ContextTestSupport {
private static Map<String, Object> headerFor(int num) {
String name = num + ".txt";
- return Map.of(Exchange.FILE_NAME, name, "id", Resumables.of(name, num));
+ return Map.of(Exchange.FILE_NAME, name);
}
@Test
@@ -67,7 +67,6 @@ public class FileConsumerResumeStrategyTest extends ContextTestSupport {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedBodiesReceivedInAnyOrder("3", "4", "5", "6");
-
template.sendBodyAndHeaders(fileUri("resume"), "0", headerFor(0));
template.sendBodyAndHeaders(fileUri("resume"), "1", headerFor(1));
template.sendBodyAndHeaders(fileUri("resume"), "2", headerFor(2));
@@ -80,6 +79,15 @@ public class FileConsumerResumeStrategyTest extends ContextTestSupport {
assertMockEndpointsSatisfied();
}
+ private void setOffset(Exchange exchange) {
+ String body = exchange.getMessage().getBody(String.class);
+
+ if (body != null) {
+ Integer num = Integer.valueOf(body);
+ exchange.getMessage().setHeader(Exchange.OFFSET, Resumables.of(body + ".txt", num));
+ }
+ }
+
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@@ -89,7 +97,8 @@ public class FileConsumerResumeStrategyTest extends ContextTestSupport {
bindToRegistry("testResumeStrategy", new TestResumeStrategy());
from(fileUri("resume?noop=true&recursive=true"))
- .resumable().header("id").resumableStrategyRef("testResumeStrategy")
+ .process(e -> setOffset(e))
+ .resumable().resumableStrategyRef("testResumeStrategy")
.convertBodyTo(String.class)
.to("mock:result");
}
[camel] 04/16: CAMEL-15562: removed the resume strategy option from components
Posted by or...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 554750528de670885cd36914097cfabe78c6de60
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Tue Feb 8 17:20:53 2022 +0100
CAMEL-15562: removed the resume strategy option from components
- removed the resume strategy option from the file component
- removed the resume strategy option from Kafka component
- removed the resume strategy option from the CouchDB component
- removed the resume strategy option from the AWS 2 Kinesis component
---
.../camel/catalog/components/aws2-kinesis.json | 2 -
.../apache/camel/catalog/components/couchdb.json | 1 -
.../org/apache/camel/catalog/components/file.json | 1 -
.../org/apache/camel/catalog/components/kafka.json | 2 -
.../aws2/kinesis/Kinesis2ComponentConfigurer.java | 6 -
.../aws2/kinesis/Kinesis2EndpointConfigurer.java | 6 -
.../aws2/kinesis/Kinesis2EndpointUriFactory.java | 3 +-
.../camel/component/aws2/kinesis/aws2-kinesis.json | 2 -
.../aws2/kinesis/Kinesis2Configuration.java | 14 ---
.../component/aws2/kinesis/Kinesis2Consumer.java | 7 +-
.../couchdb/CouchDbEndpointConfigurer.java | 6 -
.../couchdb/CouchDbEndpointUriFactory.java | 3 +-
.../apache/camel/component/couchdb/couchdb.json | 1 -
.../component/couchdb/CouchDbChangesetTracker.java | 4 +-
.../camel/component/couchdb/CouchDbConsumer.java | 14 ++-
.../camel/component/couchdb/CouchDbEndpoint.java | 15 ---
...tory.java => CouchDbResumeStrategyFactory.java} | 10 +-
.../component/file/FileEndpointConfigurer.java | 6 -
.../component/file/FileEndpointUriFactory.java | 3 +-
.../org/apache/camel/component/file/file.json | 1 -
.../apache/camel/component/file/FileConsumer.java | 18 +--
.../apache/camel/component/file/FileEndpoint.java | 20 ----
.../component/kafka/KafkaComponentConfigurer.java | 6 -
.../component/kafka/KafkaEndpointConfigurer.java | 6 -
.../component/kafka/KafkaEndpointUriFactory.java | 3 +-
.../org/apache/camel/component/kafka/kafka.json | 2 -
.../camel/component/kafka/KafkaConfiguration.java | 24 ----
.../consumer/support/ResumeStrategyFactory.java | 5 -
.../KafkaConsumerWithResumeStrategyIT.java | 123 ---------------------
.../FileConsumerResumeFromOffsetStrategyTest.java | 18 ++-
.../file/FileConsumerResumeStrategyTest.java | 26 +++--
.../dsl/Aws2KinesisComponentBuilderFactory.java | 19 ----
.../dsl/KafkaComponentBuilderFactory.java | 25 -----
.../dsl/CouchDbEndpointBuilderFactory.java | 36 ------
.../endpoint/dsl/FileEndpointBuilderFactory.java | 38 -------
.../endpoint/dsl/KafkaEndpointBuilderFactory.java | 48 --------
.../dsl/Kinesis2EndpointBuilderFactory.java | 36 ------
37 files changed, 70 insertions(+), 490 deletions(-)
diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/aws2-kinesis.json b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/aws2-kinesis.json
index a498481..6902ece 100644
--- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/aws2-kinesis.json
+++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/aws2-kinesis.json
@@ -36,7 +36,6 @@
"bridgeErrorHandler": { "kind": "property", "displayName": "Bridge Error Handler", "group": "consumer", "label": "consumer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a me [...]
"iteratorType": { "kind": "property", "displayName": "Iterator Type", "group": "consumer", "label": "consumer", "required": false, "type": "object", "javaType": "software.amazon.awssdk.services.kinesis.model.ShardIteratorType", "enum": [ "AT_SEQUENCE_NUMBER", "AFTER_SEQUENCE_NUMBER", "TRIM_HORIZON", "LATEST", "AT_TIMESTAMP", "null" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "TRIM_HORIZON", "configurationClass": "org.apache.camel.component.aws2.kinesi [...]
"maxResultsPerRequest": { "kind": "property", "displayName": "Max Results Per Request", "group": "consumer", "label": "consumer", "required": false, "type": "integer", "javaType": "int", "deprecated": false, "autowired": false, "secret": false, "defaultValue": 1, "configurationClass": "org.apache.camel.component.aws2.kinesis.Kinesis2Configuration", "configurationField": "configuration", "description": "Maximum number of records that will be fetched in each poll" },
- "resumeStrategy": { "kind": "property", "displayName": "Resume Strategy", "group": "consumer", "label": "consumer", "required": false, "type": "object", "javaType": "org.apache.camel.component.aws2.kinesis.consumer.KinesisResumeStrategy", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "KinesisUserConfigurationResumeStrategy", "configurationClass": "org.apache.camel.component.aws2.kinesis.Kinesis2Configuration", "configurationField": "configuration", "descri [...]
"sequenceNumber": { "kind": "property", "displayName": "Sequence Number", "group": "consumer", "label": "consumer", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.aws2.kinesis.Kinesis2Configuration", "configurationField": "configuration", "description": "The sequence number to start polling from. Required if iteratorType is set to AFTER_SEQUENCE_NUMBER or [...]
"shardClosed": { "kind": "property", "displayName": "Shard Closed", "group": "consumer", "label": "consumer", "required": false, "type": "object", "javaType": "org.apache.camel.component.aws2.kinesis.Kinesis2ShardClosedStrategyEnum", "enum": [ "ignore", "fail", "silent" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "ignore", "configurationClass": "org.apache.camel.component.aws2.kinesis.Kinesis2Configuration", "configurationField": "configuration", "des [...]
"shardId": { "kind": "property", "displayName": "Shard Id", "group": "consumer", "label": "consumer", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.aws2.kinesis.Kinesis2Configuration", "configurationField": "configuration", "description": "Defines which shardId in the Kinesis stream to get records from" },
@@ -60,7 +59,6 @@
"bridgeErrorHandler": { "kind": "parameter", "displayName": "Bridge Error Handler", "group": "consumer", "label": "consumer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a m [...]
"iteratorType": { "kind": "parameter", "displayName": "Iterator Type", "group": "consumer", "label": "consumer", "required": false, "type": "object", "javaType": "software.amazon.awssdk.services.kinesis.model.ShardIteratorType", "enum": [ "AT_SEQUENCE_NUMBER", "AFTER_SEQUENCE_NUMBER", "TRIM_HORIZON", "LATEST", "AT_TIMESTAMP", "null" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "TRIM_HORIZON", "configurationClass": "org.apache.camel.component.aws2.kines [...]
"maxResultsPerRequest": { "kind": "parameter", "displayName": "Max Results Per Request", "group": "consumer", "label": "consumer", "required": false, "type": "integer", "javaType": "int", "deprecated": false, "autowired": false, "secret": false, "defaultValue": 1, "configurationClass": "org.apache.camel.component.aws2.kinesis.Kinesis2Configuration", "configurationField": "configuration", "description": "Maximum number of records that will be fetched in each poll" },
- "resumeStrategy": { "kind": "parameter", "displayName": "Resume Strategy", "group": "consumer", "label": "consumer", "required": false, "type": "object", "javaType": "org.apache.camel.component.aws2.kinesis.consumer.KinesisResumeStrategy", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "KinesisUserConfigurationResumeStrategy", "configurationClass": "org.apache.camel.component.aws2.kinesis.Kinesis2Configuration", "configurationField": "configuration", "descr [...]
"sendEmptyMessageWhenIdle": { "kind": "parameter", "displayName": "Send Empty Message When Idle", "group": "consumer", "label": "consumer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "If the polling consumer did not poll any files, you can enable this option to send an empty message (no body) instead." },
"sequenceNumber": { "kind": "parameter", "displayName": "Sequence Number", "group": "consumer", "label": "consumer", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.aws2.kinesis.Kinesis2Configuration", "configurationField": "configuration", "description": "The sequence number to start polling from. Required if iteratorType is set to AFTER_SEQUENCE_NUMBER or [...]
"shardClosed": { "kind": "parameter", "displayName": "Shard Closed", "group": "consumer", "label": "consumer", "required": false, "type": "object", "javaType": "org.apache.camel.component.aws2.kinesis.Kinesis2ShardClosedStrategyEnum", "enum": [ "ignore", "fail", "silent" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "ignore", "configurationClass": "org.apache.camel.component.aws2.kinesis.Kinesis2Configuration", "configurationField": "configuration", "de [...]
diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/couchdb.json b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/couchdb.json
index 69fdb92..9f4a1e5 100644
--- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/couchdb.json
+++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/couchdb.json
@@ -35,7 +35,6 @@
"bridgeErrorHandler": { "kind": "parameter", "displayName": "Bridge Error Handler", "group": "consumer", "label": "consumer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a m [...]
"deletes": { "kind": "parameter", "displayName": "Deletes", "group": "consumer", "label": "consumer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Document deletes are published as events" },
"heartbeat": { "kind": "parameter", "displayName": "Heartbeat", "group": "consumer", "label": "consumer", "required": false, "type": "duration", "javaType": "long", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "30000", "description": "How often to send an empty message to keep socket alive in millis" },
- "resumeStrategy": { "kind": "parameter", "displayName": "Resume Strategy", "group": "consumer", "label": "consumer", "required": false, "type": "object", "javaType": "org.apache.camel.component.couchdb.consumer.CouchDbResumeStrategy", "deprecated": false, "autowired": false, "secret": false, "description": "Sets a custom resume strategy for tracking changes from CouchDB. It allows tracking from a specific point (i.e.: since the given update sequence, the latest sequence, etc)." },
"style": { "kind": "parameter", "displayName": "Style", "group": "consumer", "label": "consumer", "required": false, "type": "string", "javaType": "java.lang.String", "enum": [ "all_docs", "main_only" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "main_only", "description": "Specifies how many revisions are returned in the changes array. The default, main_only, will only return the current winning revision; all_docs will return all leaf revisions (inclu [...]
"updates": { "kind": "parameter", "displayName": "Updates", "group": "consumer", "label": "consumer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Document inserts\/updates are published as events" },
"exceptionHandler": { "kind": "parameter", "displayName": "Exception Handler", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "object", "javaType": "org.apache.camel.spi.ExceptionHandler", "optionalPrefix": "consumer.", "deprecated": false, "autowired": false, "secret": false, "description": "To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By default the con [...]
diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/file.json b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/file.json
index 721f7a4..f6e6025 100644
--- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/file.json
+++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/file.json
@@ -49,7 +49,6 @@
"pollStrategy": { "kind": "parameter", "displayName": "Poll Strategy", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "object", "javaType": "org.apache.camel.spi.PollingConsumerPollStrategy", "deprecated": false, "autowired": false, "secret": false, "description": "A pluggable org.apache.camel.PollingConsumerPollingStrategy allowing you to provide your custom implementation to control error handling usually occurred during the poll operation [...]
"probeContentType": { "kind": "parameter", "displayName": "Probe Content Type", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether to enable probing of the content type. If enable then the consumer uses Files#probeContentType(java.nio.file.Path) to determine the content-type of the file, and store that as a he [...]
"processStrategy": { "kind": "parameter", "displayName": "Process Strategy", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "object", "javaType": "org.apache.camel.component.file.GenericFileProcessStrategy<java.io.File>", "deprecated": false, "autowired": false, "secret": false, "description": "A pluggable org.apache.camel.component.file.GenericFileProcessStrategy allowing you to implement your own readLock option or similar. Can also be used [...]
- "resumeStrategy": { "kind": "parameter", "displayName": "Resume Strategy", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "object", "javaType": "org.apache.camel.component.file.consumer.FileConsumerResumeStrategy", "deprecated": false, "autowired": false, "secret": false, "description": "Set a resume strategy for files. This makes it possible to define a strategy for resuming reading files after the last point before stopping the application. [...]
"startingDirectoryMustExist": { "kind": "parameter", "displayName": "Starting Directory Must Exist", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether the starting directory must exist. Mind that the autoCreate option is default enabled, which means the starting directory is normally auto created if it doesn' [...]
"startingDirectoryMustHaveAccess": { "kind": "parameter", "displayName": "Starting Directory Must Have Access", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether the starting directory has access permissions. Mind that the startingDirectoryMustExist parameter must be set to true in order to verify that the di [...]
"appendChars": { "kind": "parameter", "displayName": "Append Chars", "group": "producer", "label": "producer", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Used to append characters (text) after writing files. This can for example be used to add new lines or other separators when writing and appending new files or existing files. To specify new-line (slash-n or slash-r) or tab (slash-t) [...]
diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/kafka.json b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/kafka.json
index 4758ba8..5007791 100644
--- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/kafka.json
+++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/kafka.json
@@ -55,7 +55,6 @@
"partitionAssignor": { "kind": "property", "displayName": "Partition Assignor", "group": "consumer", "label": "consumer", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "org.apache.kafka.clients.consumer.RangeAssignor", "configurationClass": "org.apache.camel.component.kafka.KafkaConfiguration", "configurationField": "configuration", "description": "The class name of the partition assignme [...]
"pollOnError": { "kind": "property", "displayName": "Poll On Error", "group": "consumer", "label": "consumer", "required": false, "type": "object", "javaType": "org.apache.camel.component.kafka.PollOnError", "enum": [ "DISCARD", "ERROR_HANDLER", "RECONNECT", "RETRY", "STOP" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "ERROR_HANDLER", "configurationClass": "org.apache.camel.component.kafka.KafkaConfiguration", "configurationField": "configuration", "de [...]
"pollTimeoutMs": { "kind": "property", "displayName": "Poll Timeout Ms", "group": "consumer", "label": "consumer", "required": false, "type": "duration", "javaType": "java.lang.Long", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "5000", "configurationClass": "org.apache.camel.component.kafka.KafkaConfiguration", "configurationField": "configuration", "description": "The timeout used when polling the KafkaConsumer." },
- "resumeStrategy": { "kind": "property", "displayName": "Resume Strategy", "group": "consumer", "label": "consumer", "required": false, "type": "object", "javaType": "org.apache.camel.component.kafka.consumer.support.KafkaConsumerResumeStrategy", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.kafka.KafkaConfiguration", "configurationField": "configuration", "description": "This option allows the user to set a custom resume s [...]
"seekTo": { "kind": "property", "displayName": "Seek To", "group": "consumer", "label": "consumer", "required": false, "type": "string", "javaType": "java.lang.String", "enum": [ "beginning", "end" ], "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.kafka.KafkaConfiguration", "configurationField": "configuration", "description": "Set if KafkaConsumer will read from beginning or end on startup: beginning : read from beginning [...]
"sessionTimeoutMs": { "kind": "property", "displayName": "Session Timeout Ms", "group": "consumer", "label": "consumer", "required": false, "type": "integer", "javaType": "java.lang.Integer", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "10000", "configurationClass": "org.apache.camel.component.kafka.KafkaConfiguration", "configurationField": "configuration", "description": "The timeout used to detect failures when using Kafka's group management facilities." },
"specificAvroReader": { "kind": "property", "displayName": "Specific Avro Reader", "group": "consumer", "label": "confluent,consumer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.kafka.KafkaConfiguration", "configurationField": "configuration", "description": "This enables the use of a specific Avro reader for use with the Confluent Platf [...]
@@ -161,7 +160,6 @@
"partitionAssignor": { "kind": "parameter", "displayName": "Partition Assignor", "group": "consumer", "label": "consumer", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "org.apache.kafka.clients.consumer.RangeAssignor", "configurationClass": "org.apache.camel.component.kafka.KafkaConfiguration", "configurationField": "configuration", "description": "The class name of the partition assignm [...]
"pollOnError": { "kind": "parameter", "displayName": "Poll On Error", "group": "consumer", "label": "consumer", "required": false, "type": "object", "javaType": "org.apache.camel.component.kafka.PollOnError", "enum": [ "DISCARD", "ERROR_HANDLER", "RECONNECT", "RETRY", "STOP" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "ERROR_HANDLER", "configurationClass": "org.apache.camel.component.kafka.KafkaConfiguration", "configurationField": "configuration", "d [...]
"pollTimeoutMs": { "kind": "parameter", "displayName": "Poll Timeout Ms", "group": "consumer", "label": "consumer", "required": false, "type": "duration", "javaType": "java.lang.Long", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "5000", "configurationClass": "org.apache.camel.component.kafka.KafkaConfiguration", "configurationField": "configuration", "description": "The timeout used when polling the KafkaConsumer." },
- "resumeStrategy": { "kind": "parameter", "displayName": "Resume Strategy", "group": "consumer", "label": "consumer", "required": false, "type": "object", "javaType": "org.apache.camel.component.kafka.consumer.support.KafkaConsumerResumeStrategy", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.kafka.KafkaConfiguration", "configurationField": "configuration", "description": "This option allows the user to set a custom resume [...]
"seekTo": { "kind": "parameter", "displayName": "Seek To", "group": "consumer", "label": "consumer", "required": false, "type": "string", "javaType": "java.lang.String", "enum": [ "beginning", "end" ], "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.kafka.KafkaConfiguration", "configurationField": "configuration", "description": "Set if KafkaConsumer will read from beginning or end on startup: beginning : read from beginning [...]
"sessionTimeoutMs": { "kind": "parameter", "displayName": "Session Timeout Ms", "group": "consumer", "label": "consumer", "required": false, "type": "integer", "javaType": "java.lang.Integer", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "10000", "configurationClass": "org.apache.camel.component.kafka.KafkaConfiguration", "configurationField": "configuration", "description": "The timeout used to detect failures when using Kafka's group management facilities." },
"specificAvroReader": { "kind": "parameter", "displayName": "Specific Avro Reader", "group": "consumer", "label": "confluent,consumer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.kafka.KafkaConfiguration", "configurationField": "configuration", "description": "This enables the use of a specific Avro reader for use with the Confluent Plat [...]
diff --git a/components/camel-aws/camel-aws2-kinesis/src/generated/java/org/apache/camel/component/aws2/kinesis/Kinesis2ComponentConfigurer.java b/components/camel-aws/camel-aws2-kinesis/src/generated/java/org/apache/camel/component/aws2/kinesis/Kinesis2ComponentConfigurer.java
index 97bb77a..1a15fdc 100644
--- a/components/camel-aws/camel-aws2-kinesis/src/generated/java/org/apache/camel/component/aws2/kinesis/Kinesis2ComponentConfigurer.java
+++ b/components/camel-aws/camel-aws2-kinesis/src/generated/java/org/apache/camel/component/aws2/kinesis/Kinesis2ComponentConfigurer.java
@@ -54,8 +54,6 @@ public class Kinesis2ComponentConfigurer extends PropertyConfigurerSupport imple
case "proxyprotocol":
case "proxyProtocol": getOrCreateConfiguration(target).setProxyProtocol(property(camelContext, software.amazon.awssdk.core.Protocol.class, value)); return true;
case "region": getOrCreateConfiguration(target).setRegion(property(camelContext, java.lang.String.class, value)); return true;
- case "resumestrategy":
- case "resumeStrategy": getOrCreateConfiguration(target).setResumeStrategy(property(camelContext, org.apache.camel.component.aws2.kinesis.consumer.KinesisResumeStrategy.class, value)); return true;
case "secretkey":
case "secretKey": getOrCreateConfiguration(target).setSecretKey(property(camelContext, java.lang.String.class, value)); return true;
case "sequencenumber":
@@ -108,8 +106,6 @@ public class Kinesis2ComponentConfigurer extends PropertyConfigurerSupport imple
case "proxyprotocol":
case "proxyProtocol": return software.amazon.awssdk.core.Protocol.class;
case "region": return java.lang.String.class;
- case "resumestrategy":
- case "resumeStrategy": return org.apache.camel.component.aws2.kinesis.consumer.KinesisResumeStrategy.class;
case "secretkey":
case "secretKey": return java.lang.String.class;
case "sequencenumber":
@@ -158,8 +154,6 @@ public class Kinesis2ComponentConfigurer extends PropertyConfigurerSupport imple
case "proxyprotocol":
case "proxyProtocol": return getOrCreateConfiguration(target).getProxyProtocol();
case "region": return getOrCreateConfiguration(target).getRegion();
- case "resumestrategy":
- case "resumeStrategy": return getOrCreateConfiguration(target).getResumeStrategy();
case "secretkey":
case "secretKey": return getOrCreateConfiguration(target).getSecretKey();
case "sequencenumber":
diff --git a/components/camel-aws/camel-aws2-kinesis/src/generated/java/org/apache/camel/component/aws2/kinesis/Kinesis2EndpointConfigurer.java b/components/camel-aws/camel-aws2-kinesis/src/generated/java/org/apache/camel/component/aws2/kinesis/Kinesis2EndpointConfigurer.java
index 00e68d0..b165e71 100644
--- a/components/camel-aws/camel-aws2-kinesis/src/generated/java/org/apache/camel/component/aws2/kinesis/Kinesis2EndpointConfigurer.java
+++ b/components/camel-aws/camel-aws2-kinesis/src/generated/java/org/apache/camel/component/aws2/kinesis/Kinesis2EndpointConfigurer.java
@@ -62,8 +62,6 @@ public class Kinesis2EndpointConfigurer extends PropertyConfigurerSupport implem
case "region": target.getConfiguration().setRegion(property(camelContext, java.lang.String.class, value)); return true;
case "repeatcount":
case "repeatCount": target.setRepeatCount(property(camelContext, long.class, value)); return true;
- case "resumestrategy":
- case "resumeStrategy": target.getConfiguration().setResumeStrategy(property(camelContext, org.apache.camel.component.aws2.kinesis.consumer.KinesisResumeStrategy.class, value)); return true;
case "runlogginglevel":
case "runLoggingLevel": target.setRunLoggingLevel(property(camelContext, org.apache.camel.LoggingLevel.class, value)); return true;
case "scheduledexecutorservice":
@@ -146,8 +144,6 @@ public class Kinesis2EndpointConfigurer extends PropertyConfigurerSupport implem
case "region": return java.lang.String.class;
case "repeatcount":
case "repeatCount": return long.class;
- case "resumestrategy":
- case "resumeStrategy": return org.apache.camel.component.aws2.kinesis.consumer.KinesisResumeStrategy.class;
case "runlogginglevel":
case "runLoggingLevel": return org.apache.camel.LoggingLevel.class;
case "scheduledexecutorservice":
@@ -226,8 +222,6 @@ public class Kinesis2EndpointConfigurer extends PropertyConfigurerSupport implem
case "region": return target.getConfiguration().getRegion();
case "repeatcount":
case "repeatCount": return target.getRepeatCount();
- case "resumestrategy":
- case "resumeStrategy": return target.getConfiguration().getResumeStrategy();
case "runlogginglevel":
case "runLoggingLevel": return target.getRunLoggingLevel();
case "scheduledexecutorservice":
diff --git a/components/camel-aws/camel-aws2-kinesis/src/generated/java/org/apache/camel/component/aws2/kinesis/Kinesis2EndpointUriFactory.java b/components/camel-aws/camel-aws2-kinesis/src/generated/java/org/apache/camel/component/aws2/kinesis/Kinesis2EndpointUriFactory.java
index c04c83b..5627b87 100644
--- a/components/camel-aws/camel-aws2-kinesis/src/generated/java/org/apache/camel/component/aws2/kinesis/Kinesis2EndpointUriFactory.java
+++ b/components/camel-aws/camel-aws2-kinesis/src/generated/java/org/apache/camel/component/aws2/kinesis/Kinesis2EndpointUriFactory.java
@@ -21,7 +21,7 @@ public class Kinesis2EndpointUriFactory extends org.apache.camel.support.compone
private static final Set<String> SECRET_PROPERTY_NAMES;
private static final Set<String> MULTI_VALUE_PREFIXES;
static {
- Set<String> props = new HashSet<>(39);
+ Set<String> props = new HashSet<>(38);
props.add("backoffMultiplier");
props.add("initialDelay");
props.add("scheduler");
@@ -57,7 +57,6 @@ public class Kinesis2EndpointUriFactory extends org.apache.camel.support.compone
props.add("startScheduler");
props.add("accessKey");
props.add("overrideEndpoint");
- props.add("resumeStrategy");
props.add("maxResultsPerRequest");
props.add("region");
props.add("exceptionHandler");
diff --git a/components/camel-aws/camel-aws2-kinesis/src/generated/resources/org/apache/camel/component/aws2/kinesis/aws2-kinesis.json b/components/camel-aws/camel-aws2-kinesis/src/generated/resources/org/apache/camel/component/aws2/kinesis/aws2-kinesis.json
index a498481..6902ece 100644
--- a/components/camel-aws/camel-aws2-kinesis/src/generated/resources/org/apache/camel/component/aws2/kinesis/aws2-kinesis.json
+++ b/components/camel-aws/camel-aws2-kinesis/src/generated/resources/org/apache/camel/component/aws2/kinesis/aws2-kinesis.json
@@ -36,7 +36,6 @@
"bridgeErrorHandler": { "kind": "property", "displayName": "Bridge Error Handler", "group": "consumer", "label": "consumer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a me [...]
"iteratorType": { "kind": "property", "displayName": "Iterator Type", "group": "consumer", "label": "consumer", "required": false, "type": "object", "javaType": "software.amazon.awssdk.services.kinesis.model.ShardIteratorType", "enum": [ "AT_SEQUENCE_NUMBER", "AFTER_SEQUENCE_NUMBER", "TRIM_HORIZON", "LATEST", "AT_TIMESTAMP", "null" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "TRIM_HORIZON", "configurationClass": "org.apache.camel.component.aws2.kinesi [...]
"maxResultsPerRequest": { "kind": "property", "displayName": "Max Results Per Request", "group": "consumer", "label": "consumer", "required": false, "type": "integer", "javaType": "int", "deprecated": false, "autowired": false, "secret": false, "defaultValue": 1, "configurationClass": "org.apache.camel.component.aws2.kinesis.Kinesis2Configuration", "configurationField": "configuration", "description": "Maximum number of records that will be fetched in each poll" },
- "resumeStrategy": { "kind": "property", "displayName": "Resume Strategy", "group": "consumer", "label": "consumer", "required": false, "type": "object", "javaType": "org.apache.camel.component.aws2.kinesis.consumer.KinesisResumeStrategy", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "KinesisUserConfigurationResumeStrategy", "configurationClass": "org.apache.camel.component.aws2.kinesis.Kinesis2Configuration", "configurationField": "configuration", "descri [...]
"sequenceNumber": { "kind": "property", "displayName": "Sequence Number", "group": "consumer", "label": "consumer", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.aws2.kinesis.Kinesis2Configuration", "configurationField": "configuration", "description": "The sequence number to start polling from. Required if iteratorType is set to AFTER_SEQUENCE_NUMBER or [...]
"shardClosed": { "kind": "property", "displayName": "Shard Closed", "group": "consumer", "label": "consumer", "required": false, "type": "object", "javaType": "org.apache.camel.component.aws2.kinesis.Kinesis2ShardClosedStrategyEnum", "enum": [ "ignore", "fail", "silent" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "ignore", "configurationClass": "org.apache.camel.component.aws2.kinesis.Kinesis2Configuration", "configurationField": "configuration", "des [...]
"shardId": { "kind": "property", "displayName": "Shard Id", "group": "consumer", "label": "consumer", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.aws2.kinesis.Kinesis2Configuration", "configurationField": "configuration", "description": "Defines which shardId in the Kinesis stream to get records from" },
@@ -60,7 +59,6 @@
"bridgeErrorHandler": { "kind": "parameter", "displayName": "Bridge Error Handler", "group": "consumer", "label": "consumer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a m [...]
"iteratorType": { "kind": "parameter", "displayName": "Iterator Type", "group": "consumer", "label": "consumer", "required": false, "type": "object", "javaType": "software.amazon.awssdk.services.kinesis.model.ShardIteratorType", "enum": [ "AT_SEQUENCE_NUMBER", "AFTER_SEQUENCE_NUMBER", "TRIM_HORIZON", "LATEST", "AT_TIMESTAMP", "null" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "TRIM_HORIZON", "configurationClass": "org.apache.camel.component.aws2.kines [...]
"maxResultsPerRequest": { "kind": "parameter", "displayName": "Max Results Per Request", "group": "consumer", "label": "consumer", "required": false, "type": "integer", "javaType": "int", "deprecated": false, "autowired": false, "secret": false, "defaultValue": 1, "configurationClass": "org.apache.camel.component.aws2.kinesis.Kinesis2Configuration", "configurationField": "configuration", "description": "Maximum number of records that will be fetched in each poll" },
- "resumeStrategy": { "kind": "parameter", "displayName": "Resume Strategy", "group": "consumer", "label": "consumer", "required": false, "type": "object", "javaType": "org.apache.camel.component.aws2.kinesis.consumer.KinesisResumeStrategy", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "KinesisUserConfigurationResumeStrategy", "configurationClass": "org.apache.camel.component.aws2.kinesis.Kinesis2Configuration", "configurationField": "configuration", "descr [...]
"sendEmptyMessageWhenIdle": { "kind": "parameter", "displayName": "Send Empty Message When Idle", "group": "consumer", "label": "consumer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "If the polling consumer did not poll any files, you can enable this option to send an empty message (no body) instead." },
"sequenceNumber": { "kind": "parameter", "displayName": "Sequence Number", "group": "consumer", "label": "consumer", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.aws2.kinesis.Kinesis2Configuration", "configurationField": "configuration", "description": "The sequence number to start polling from. Required if iteratorType is set to AFTER_SEQUENCE_NUMBER or [...]
"shardClosed": { "kind": "parameter", "displayName": "Shard Closed", "group": "consumer", "label": "consumer", "required": false, "type": "object", "javaType": "org.apache.camel.component.aws2.kinesis.Kinesis2ShardClosedStrategyEnum", "enum": [ "ignore", "fail", "silent" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "ignore", "configurationClass": "org.apache.camel.component.aws2.kinesis.Kinesis2Configuration", "configurationField": "configuration", "de [...]
diff --git a/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/kinesis/Kinesis2Configuration.java b/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/kinesis/Kinesis2Configuration.java
index 0ded74b..db57da4 100644
--- a/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/kinesis/Kinesis2Configuration.java
+++ b/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/kinesis/Kinesis2Configuration.java
@@ -17,7 +17,6 @@
package org.apache.camel.component.aws2.kinesis;
import org.apache.camel.RuntimeCamelException;
-import org.apache.camel.component.aws2.kinesis.consumer.KinesisResumeStrategy;
import org.apache.camel.spi.Metadata;
import org.apache.camel.spi.UriParam;
import org.apache.camel.spi.UriParams;
@@ -84,11 +83,6 @@ public class Kinesis2Configuration implements Cloneable {
"static credentials to be passed in.")
private boolean useDefaultCredentialsProvider;
- @UriParam(label = "consumer",
- description = "Defines a resume strategy for AWS Kinesis. The default strategy reads the sequenceNumber if provided",
- defaultValue = "KinesisUserConfigurationResumeStrategy")
- private KinesisResumeStrategy resumeStrategy;
-
public KinesisClient getAmazonKinesisClient() {
return amazonKinesisClient;
}
@@ -233,14 +227,6 @@ public class Kinesis2Configuration implements Cloneable {
this.useDefaultCredentialsProvider = useDefaultCredentialsProvider;
}
- public KinesisResumeStrategy getResumeStrategy() {
- return resumeStrategy;
- }
-
- public void setResumeStrategy(KinesisResumeStrategy resumeStrategy) {
- this.resumeStrategy = resumeStrategy;
- }
-
// *************************************************
//
// *************************************************
diff --git a/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/kinesis/Kinesis2Consumer.java b/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/kinesis/Kinesis2Consumer.java
index 8ad6181..f8bee4c 100644
--- a/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/kinesis/Kinesis2Consumer.java
+++ b/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/kinesis/Kinesis2Consumer.java
@@ -171,11 +171,10 @@ public class Kinesis2Consumer extends ScheduledBatchPollingConsumer {
}
private void resume(GetShardIteratorRequest.Builder req) {
- KinesisResumeStrategy resumeStrategy;
- if (getEndpoint().getConfiguration().getResumeStrategy() == null) {
+ KinesisResumeStrategy resumeStrategy = getEndpoint().getCamelContext().hasService(KinesisResumeStrategy.class);
+
+ if (resumeStrategy == null) {
resumeStrategy = new KinesisUserConfigurationResumeStrategy(getEndpoint().getConfiguration());
- } else {
- resumeStrategy = getEndpoint().getConfiguration().getResumeStrategy();
}
resumeStrategy.setRequestBuilder(req);
diff --git a/components/camel-couchdb/src/generated/java/org/apache/camel/component/couchdb/CouchDbEndpointConfigurer.java b/components/camel-couchdb/src/generated/java/org/apache/camel/component/couchdb/CouchDbEndpointConfigurer.java
index 5452c62..6629f7f 100644
--- a/components/camel-couchdb/src/generated/java/org/apache/camel/component/couchdb/CouchDbEndpointConfigurer.java
+++ b/components/camel-couchdb/src/generated/java/org/apache/camel/component/couchdb/CouchDbEndpointConfigurer.java
@@ -34,8 +34,6 @@ public class CouchDbEndpointConfigurer extends PropertyConfigurerSupport impleme
case "lazystartproducer":
case "lazyStartProducer": target.setLazyStartProducer(property(camelContext, boolean.class, value)); return true;
case "password": target.setPassword(property(camelContext, java.lang.String.class, value)); return true;
- case "resumestrategy":
- case "resumeStrategy": target.setResumeStrategy(property(camelContext, org.apache.camel.component.couchdb.consumer.CouchDbResumeStrategy.class, value)); return true;
case "style": target.setStyle(property(camelContext, java.lang.String.class, value)); return true;
case "updates": target.setUpdates(property(camelContext, boolean.class, value)); return true;
case "username": target.setUsername(property(camelContext, java.lang.String.class, value)); return true;
@@ -59,8 +57,6 @@ public class CouchDbEndpointConfigurer extends PropertyConfigurerSupport impleme
case "lazystartproducer":
case "lazyStartProducer": return boolean.class;
case "password": return java.lang.String.class;
- case "resumestrategy":
- case "resumeStrategy": return org.apache.camel.component.couchdb.consumer.CouchDbResumeStrategy.class;
case "style": return java.lang.String.class;
case "updates": return boolean.class;
case "username": return java.lang.String.class;
@@ -85,8 +81,6 @@ public class CouchDbEndpointConfigurer extends PropertyConfigurerSupport impleme
case "lazystartproducer":
case "lazyStartProducer": return target.isLazyStartProducer();
case "password": return target.getPassword();
- case "resumestrategy":
- case "resumeStrategy": return target.getResumeStrategy();
case "style": return target.getStyle();
case "updates": return target.isUpdates();
case "username": return target.getUsername();
diff --git a/components/camel-couchdb/src/generated/java/org/apache/camel/component/couchdb/CouchDbEndpointUriFactory.java b/components/camel-couchdb/src/generated/java/org/apache/camel/component/couchdb/CouchDbEndpointUriFactory.java
index 92d9d31..92f01c8 100644
--- a/components/camel-couchdb/src/generated/java/org/apache/camel/component/couchdb/CouchDbEndpointUriFactory.java
+++ b/components/camel-couchdb/src/generated/java/org/apache/camel/component/couchdb/CouchDbEndpointUriFactory.java
@@ -21,7 +21,7 @@ public class CouchDbEndpointUriFactory extends org.apache.camel.support.componen
private static final Set<String> SECRET_PROPERTY_NAMES;
private static final Set<String> MULTI_VALUE_PREFIXES;
static {
- Set<String> props = new HashSet<>(16);
+ Set<String> props = new HashSet<>(15);
props.add("deletes");
props.add("heartbeat");
props.add("exchangePattern");
@@ -34,7 +34,6 @@ public class CouchDbEndpointUriFactory extends org.apache.camel.support.componen
props.add("password");
props.add("bridgeErrorHandler");
props.add("port");
- props.add("resumeStrategy");
props.add("style");
props.add("exceptionHandler");
props.add("username");
diff --git a/components/camel-couchdb/src/generated/resources/org/apache/camel/component/couchdb/couchdb.json b/components/camel-couchdb/src/generated/resources/org/apache/camel/component/couchdb/couchdb.json
index 69fdb92..9f4a1e5 100644
--- a/components/camel-couchdb/src/generated/resources/org/apache/camel/component/couchdb/couchdb.json
+++ b/components/camel-couchdb/src/generated/resources/org/apache/camel/component/couchdb/couchdb.json
@@ -35,7 +35,6 @@
"bridgeErrorHandler": { "kind": "parameter", "displayName": "Bridge Error Handler", "group": "consumer", "label": "consumer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a m [...]
"deletes": { "kind": "parameter", "displayName": "Deletes", "group": "consumer", "label": "consumer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Document deletes are published as events" },
"heartbeat": { "kind": "parameter", "displayName": "Heartbeat", "group": "consumer", "label": "consumer", "required": false, "type": "duration", "javaType": "long", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "30000", "description": "How often to send an empty message to keep socket alive in millis" },
- "resumeStrategy": { "kind": "parameter", "displayName": "Resume Strategy", "group": "consumer", "label": "consumer", "required": false, "type": "object", "javaType": "org.apache.camel.component.couchdb.consumer.CouchDbResumeStrategy", "deprecated": false, "autowired": false, "secret": false, "description": "Sets a custom resume strategy for tracking changes from CouchDB. It allows tracking from a specific point (i.e.: since the given update sequence, the latest sequence, etc)." },
"style": { "kind": "parameter", "displayName": "Style", "group": "consumer", "label": "consumer", "required": false, "type": "string", "javaType": "java.lang.String", "enum": [ "all_docs", "main_only" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "main_only", "description": "Specifies how many revisions are returned in the changes array. The default, main_only, will only return the current winning revision; all_docs will return all leaf revisions (inclu [...]
"updates": { "kind": "parameter", "displayName": "Updates", "group": "consumer", "label": "consumer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Document inserts\/updates are published as events" },
"exceptionHandler": { "kind": "parameter", "displayName": "Exception Handler", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "object", "javaType": "org.apache.camel.spi.ExceptionHandler", "optionalPrefix": "consumer.", "deprecated": false, "autowired": false, "secret": false, "description": "To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By default the con [...]
diff --git a/components/camel-couchdb/src/main/java/org/apache/camel/component/couchdb/CouchDbChangesetTracker.java b/components/camel-couchdb/src/main/java/org/apache/camel/component/couchdb/CouchDbChangesetTracker.java
index 9e305ad..58a9a70 100644
--- a/components/camel-couchdb/src/main/java/org/apache/camel/component/couchdb/CouchDbChangesetTracker.java
+++ b/components/camel-couchdb/src/main/java/org/apache/camel/component/couchdb/CouchDbChangesetTracker.java
@@ -22,7 +22,7 @@ import com.google.gson.JsonObject;
import org.apache.camel.Exchange;
import org.apache.camel.component.couchdb.consumer.CouchDbResumable;
import org.apache.camel.component.couchdb.consumer.CouchDbResumeStrategy;
-import org.apache.camel.component.couchdb.consumer.CouchDdResumeStrategyFactory;
+import org.apache.camel.component.couchdb.consumer.CouchDbResumeStrategyFactory;
import org.apache.camel.support.task.BlockingTask;
import org.apache.camel.support.task.Tasks;
import org.apache.camel.support.task.budget.Budgets;
@@ -53,7 +53,7 @@ public class CouchDbChangesetTracker implements Runnable {
CouchDbResumable resumable = new CouchDbResumable(couchClient, sequence);
if (sequence == null) {
- CouchDbResumeStrategy resumeStrategy = CouchDdResumeStrategyFactory.newResumeStrategy(this.endpoint);
+ CouchDbResumeStrategy resumeStrategy = CouchDbResumeStrategyFactory.newResumeStrategy(this.consumer);
resumeStrategy.setResumable(resumable);
resumeStrategy.resume();
diff --git a/components/camel-couchdb/src/main/java/org/apache/camel/component/couchdb/CouchDbConsumer.java b/components/camel-couchdb/src/main/java/org/apache/camel/component/couchdb/CouchDbConsumer.java
index 3a8e478..1a22bf3 100644
--- a/components/camel-couchdb/src/main/java/org/apache/camel/component/couchdb/CouchDbConsumer.java
+++ b/components/camel-couchdb/src/main/java/org/apache/camel/component/couchdb/CouchDbConsumer.java
@@ -21,14 +21,17 @@ import java.util.concurrent.ExecutorService;
import com.google.gson.JsonObject;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
+import org.apache.camel.ResumeAware;
+import org.apache.camel.component.couchdb.consumer.CouchDbResumeStrategy;
import org.apache.camel.support.DefaultConsumer;
-public class CouchDbConsumer extends DefaultConsumer {
+public class CouchDbConsumer extends DefaultConsumer implements ResumeAware<CouchDbResumeStrategy> {
private final CouchDbClientWrapper couchClient;
private final CouchDbEndpoint endpoint;
private ExecutorService executor;
private CouchDbChangesetTracker task;
+ private CouchDbResumeStrategy resumeStrategy;
public CouchDbConsumer(CouchDbEndpoint endpoint, CouchDbClientWrapper couchClient, Processor processor) {
super(endpoint, processor);
@@ -36,6 +39,15 @@ public class CouchDbConsumer extends DefaultConsumer {
this.endpoint = endpoint;
}
+ @Override
+ public void setResumeStrategy(CouchDbResumeStrategy resumeStrategy) {
+ this.resumeStrategy = resumeStrategy;
+ }
+
+ public CouchDbResumeStrategy getResumeStrategy() {
+ return resumeStrategy;
+ }
+
public Exchange createExchange(String seq, String id, JsonObject obj, boolean deleted) {
Exchange exchange = createExchange(false);
exchange.getIn().setHeader(CouchDbConstants.HEADER_DATABASE, endpoint.getDatabase());
diff --git a/components/camel-couchdb/src/main/java/org/apache/camel/component/couchdb/CouchDbEndpoint.java b/components/camel-couchdb/src/main/java/org/apache/camel/component/couchdb/CouchDbEndpoint.java
index b2db700..a45d0c3 100644
--- a/components/camel-couchdb/src/main/java/org/apache/camel/component/couchdb/CouchDbEndpoint.java
+++ b/components/camel-couchdb/src/main/java/org/apache/camel/component/couchdb/CouchDbEndpoint.java
@@ -22,7 +22,6 @@ import org.apache.camel.Category;
import org.apache.camel.Consumer;
import org.apache.camel.Processor;
import org.apache.camel.Producer;
-import org.apache.camel.component.couchdb.consumer.CouchDbResumeStrategy;
import org.apache.camel.spi.Metadata;
import org.apache.camel.spi.UriEndpoint;
import org.apache.camel.spi.UriParam;
@@ -70,8 +69,6 @@ public class CouchDbEndpoint extends DefaultEndpoint {
private boolean deletes = true;
@UriParam(label = "consumer", defaultValue = "true")
private boolean updates = true;
- @UriParam(label = "consumer")
- private CouchDbResumeStrategy resumeStrategy;
public CouchDbEndpoint() {
}
@@ -238,16 +235,4 @@ public class CouchDbEndpoint extends DefaultEndpoint {
public void setUpdates(boolean updates) {
this.updates = updates;
}
-
- public CouchDbResumeStrategy getResumeStrategy() {
- return resumeStrategy;
- }
-
- /**
- * Sets a custom resume strategy for tracking changes from CouchDB. It allows tracking from a specific point (i.e.:
- * since the given update sequence, the latest sequence, etc).
- */
- public void setResumeStrategy(CouchDbResumeStrategy resumeStrategy) {
- this.resumeStrategy = resumeStrategy;
- }
}
diff --git a/components/camel-couchdb/src/main/java/org/apache/camel/component/couchdb/consumer/CouchDdResumeStrategyFactory.java b/components/camel-couchdb/src/main/java/org/apache/camel/component/couchdb/consumer/CouchDbResumeStrategyFactory.java
similarity index 82%
rename from components/camel-couchdb/src/main/java/org/apache/camel/component/couchdb/consumer/CouchDdResumeStrategyFactory.java
rename to components/camel-couchdb/src/main/java/org/apache/camel/component/couchdb/consumer/CouchDbResumeStrategyFactory.java
index 15d4543..ce0196f 100644
--- a/components/camel-couchdb/src/main/java/org/apache/camel/component/couchdb/consumer/CouchDdResumeStrategyFactory.java
+++ b/components/camel-couchdb/src/main/java/org/apache/camel/component/couchdb/consumer/CouchDbResumeStrategyFactory.java
@@ -17,14 +17,14 @@
package org.apache.camel.component.couchdb.consumer;
-import org.apache.camel.component.couchdb.CouchDbEndpoint;
+import org.apache.camel.component.couchdb.CouchDbConsumer;
-public final class CouchDdResumeStrategyFactory {
- private CouchDdResumeStrategyFactory() {
+public final class CouchDbResumeStrategyFactory {
+ private CouchDbResumeStrategyFactory() {
}
- public static CouchDbResumeStrategy newResumeStrategy(CouchDbEndpoint endpoint) {
- CouchDbResumeStrategy resumeStrategy = endpoint.getResumeStrategy();
+ public static CouchDbResumeStrategy newResumeStrategy(CouchDbConsumer consumer) {
+ CouchDbResumeStrategy resumeStrategy = consumer.getResumeStrategy();
if (resumeStrategy == null) {
resumeStrategy = new LatestUpdateSequenceResumeStrategy();
diff --git a/components/camel-file/src/generated/java/org/apache/camel/component/file/FileEndpointConfigurer.java b/components/camel-file/src/generated/java/org/apache/camel/component/file/FileEndpointConfigurer.java
index f291e0b..1e914ba 100644
--- a/components/camel-file/src/generated/java/org/apache/camel/component/file/FileEndpointConfigurer.java
+++ b/components/camel-file/src/generated/java/org/apache/camel/component/file/FileEndpointConfigurer.java
@@ -162,8 +162,6 @@ public class FileEndpointConfigurer extends PropertyConfigurerSupport implements
case "renameUsingCopy": target.setRenameUsingCopy(property(camelContext, boolean.class, value)); return true;
case "repeatcount":
case "repeatCount": target.setRepeatCount(property(camelContext, long.class, value)); return true;
- case "resumestrategy":
- case "resumeStrategy": target.setResumeStrategy(property(camelContext, org.apache.camel.component.file.consumer.FileConsumerResumeStrategy.class, value)); return true;
case "runlogginglevel":
case "runLoggingLevel": target.setRunLoggingLevel(property(camelContext, org.apache.camel.LoggingLevel.class, value)); return true;
case "scheduledexecutorservice":
@@ -340,8 +338,6 @@ public class FileEndpointConfigurer extends PropertyConfigurerSupport implements
case "renameUsingCopy": return boolean.class;
case "repeatcount":
case "repeatCount": return long.class;
- case "resumestrategy":
- case "resumeStrategy": return org.apache.camel.component.file.consumer.FileConsumerResumeStrategy.class;
case "runlogginglevel":
case "runLoggingLevel": return org.apache.camel.LoggingLevel.class;
case "scheduledexecutorservice":
@@ -519,8 +515,6 @@ public class FileEndpointConfigurer extends PropertyConfigurerSupport implements
case "renameUsingCopy": return target.isRenameUsingCopy();
case "repeatcount":
case "repeatCount": return target.getRepeatCount();
- case "resumestrategy":
- case "resumeStrategy": return target.getResumeStrategy();
case "runlogginglevel":
case "runLoggingLevel": return target.getRunLoggingLevel();
case "scheduledexecutorservice":
diff --git a/components/camel-file/src/generated/java/org/apache/camel/component/file/FileEndpointUriFactory.java b/components/camel-file/src/generated/java/org/apache/camel/component/file/FileEndpointUriFactory.java
index d08e6c1d..1910468 100644
--- a/components/camel-file/src/generated/java/org/apache/camel/component/file/FileEndpointUriFactory.java
+++ b/components/camel-file/src/generated/java/org/apache/camel/component/file/FileEndpointUriFactory.java
@@ -21,7 +21,7 @@ public class FileEndpointUriFactory extends org.apache.camel.support.component.E
private static final Set<String> SECRET_PROPERTY_NAMES;
private static final Set<String> MULTI_VALUE_PREFIXES;
static {
- Set<String> props = new HashSet<>(95);
+ Set<String> props = new HashSet<>(94);
props.add("renameUsingCopy");
props.add("moveExistingFileStrategy");
props.add("fileName");
@@ -58,7 +58,6 @@ public class FileEndpointUriFactory extends org.apache.camel.support.component.E
props.add("lazyStartProducer");
props.add("delay");
props.add("startScheduler");
- props.add("resumeStrategy");
props.add("readLockMarkerFile");
props.add("readLockTimeout");
props.add("exceptionHandler");
diff --git a/components/camel-file/src/generated/resources/org/apache/camel/component/file/file.json b/components/camel-file/src/generated/resources/org/apache/camel/component/file/file.json
index 721f7a4..f6e6025 100644
--- a/components/camel-file/src/generated/resources/org/apache/camel/component/file/file.json
+++ b/components/camel-file/src/generated/resources/org/apache/camel/component/file/file.json
@@ -49,7 +49,6 @@
"pollStrategy": { "kind": "parameter", "displayName": "Poll Strategy", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "object", "javaType": "org.apache.camel.spi.PollingConsumerPollStrategy", "deprecated": false, "autowired": false, "secret": false, "description": "A pluggable org.apache.camel.PollingConsumerPollingStrategy allowing you to provide your custom implementation to control error handling usually occurred during the poll operation [...]
"probeContentType": { "kind": "parameter", "displayName": "Probe Content Type", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether to enable probing of the content type. If enable then the consumer uses Files#probeContentType(java.nio.file.Path) to determine the content-type of the file, and store that as a he [...]
"processStrategy": { "kind": "parameter", "displayName": "Process Strategy", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "object", "javaType": "org.apache.camel.component.file.GenericFileProcessStrategy<java.io.File>", "deprecated": false, "autowired": false, "secret": false, "description": "A pluggable org.apache.camel.component.file.GenericFileProcessStrategy allowing you to implement your own readLock option or similar. Can also be used [...]
- "resumeStrategy": { "kind": "parameter", "displayName": "Resume Strategy", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "object", "javaType": "org.apache.camel.component.file.consumer.FileConsumerResumeStrategy", "deprecated": false, "autowired": false, "secret": false, "description": "Set a resume strategy for files. This makes it possible to define a strategy for resuming reading files after the last point before stopping the application. [...]
"startingDirectoryMustExist": { "kind": "parameter", "displayName": "Starting Directory Must Exist", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether the starting directory must exist. Mind that the autoCreate option is default enabled, which means the starting directory is normally auto created if it doesn' [...]
"startingDirectoryMustHaveAccess": { "kind": "parameter", "displayName": "Starting Directory Must Have Access", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether the starting directory has access permissions. Mind that the startingDirectoryMustExist parameter must be set to true in order to verify that the di [...]
"appendChars": { "kind": "parameter", "displayName": "Append Chars", "group": "producer", "label": "producer", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Used to append characters (text) after writing files. This can for example be used to add new lines or other separators when writing and appending new files or existing files. To specify new-line (slash-n or slash-r) or tab (slash-t) [...]
diff --git a/components/camel-file/src/main/java/org/apache/camel/component/file/FileConsumer.java b/components/camel-file/src/main/java/org/apache/camel/component/file/FileConsumer.java
index e9cca6b..1b3ae3b 100644
--- a/components/camel-file/src/main/java/org/apache/camel/component/file/FileConsumer.java
+++ b/components/camel-file/src/main/java/org/apache/camel/component/file/FileConsumer.java
@@ -31,6 +31,7 @@ import java.util.Set;
import org.apache.camel.Exchange;
import org.apache.camel.Message;
import org.apache.camel.Processor;
+import org.apache.camel.ResumeAware;
import org.apache.camel.component.file.consumer.FileConsumerResumeStrategy;
import org.apache.camel.component.file.consumer.FileResumeSet;
import org.apache.camel.component.file.consumer.FileSetResumeStrategy;
@@ -43,10 +44,10 @@ import org.slf4j.LoggerFactory;
/**
* File consumer.
*/
-public class FileConsumer extends GenericFileConsumer<File> {
+public class FileConsumer extends GenericFileConsumer<File> implements ResumeAware<FileConsumerResumeStrategy> {
private static final Logger LOG = LoggerFactory.getLogger(FileConsumer.class);
- private final FileConsumerResumeStrategy resumeStrategy;
+ private FileConsumerResumeStrategy resumeStrategy;
private String endpointPath;
private Set<String> extendedAttributes;
@@ -59,8 +60,6 @@ public class FileConsumer extends GenericFileConsumer<File> {
List<String> attributes = Arrays.asList(endpoint.getExtendedAttributes().split(","));
this.extendedAttributes = new HashSet<>(attributes);
}
-
- resumeStrategy = endpoint.getResumeStrategy();
}
@Override
@@ -104,8 +103,8 @@ public class FileConsumer extends GenericFileConsumer<File> {
GenericFile<File> gf
= asGenericFile(endpointPath, file, getEndpoint().getCharset(), getEndpoint().isProbeContentType());
- if (resumeStrategy != null && resumeStrategy instanceof GenericFileResumeStrategy) {
- resumeStrategy.resume(gf);
+ if (resumeStrategy instanceof GenericFileResumeStrategy) {
+ ((GenericFileResumeStrategy<File>) resumeStrategy).resume(gf);
}
if (file.isDirectory()) {
@@ -172,7 +171,7 @@ public class FileConsumer extends GenericFileConsumer<File> {
}
}
- if (resumeStrategy != null && resumeStrategy instanceof FileSetResumeStrategy) {
+ if (resumeStrategy instanceof FileSetResumeStrategy) {
FileResumeSet resumeSet = new FileResumeSet(dirFiles);
resumeStrategy.resume(resumeSet);
@@ -306,4 +305,9 @@ public class FileConsumer extends GenericFileConsumer<File> {
// underlying file is not
return !file.getFile().getAbsolutePath().equals(file.getAbsoluteFilePath());
}
+
+ @Override
+ public void setResumeStrategy(FileConsumerResumeStrategy resumeStrategy) {
+ this.resumeStrategy = resumeStrategy;
+ }
}
diff --git a/components/camel-file/src/main/java/org/apache/camel/component/file/FileEndpoint.java b/components/camel-file/src/main/java/org/apache/camel/component/file/FileEndpoint.java
index c57f0f3..dc51742 100644
--- a/components/camel-file/src/main/java/org/apache/camel/component/file/FileEndpoint.java
+++ b/components/camel-file/src/main/java/org/apache/camel/component/file/FileEndpoint.java
@@ -31,7 +31,6 @@ import org.apache.camel.Exchange;
import org.apache.camel.Message;
import org.apache.camel.PollingConsumer;
import org.apache.camel.Processor;
-import org.apache.camel.component.file.consumer.FileConsumerResumeStrategy;
import org.apache.camel.component.file.strategy.FileMoveExistingStrategy;
import org.apache.camel.component.file.strategy.FileProcessStrategyFactory;
import org.apache.camel.spi.Metadata;
@@ -83,9 +82,6 @@ public class FileEndpoint extends GenericFileEndpoint<File> {
@UriParam(label = "producer,advanced")
private String chmodDirectory;
- @UriParam(label = "consumer,advanced")
- private FileConsumerResumeStrategy resumeStrategy;
-
public FileEndpoint() {
}
@@ -364,22 +360,6 @@ public class FileEndpoint extends GenericFileEndpoint<File> {
this.extendedAttributes = extendedAttributes;
}
- public FileConsumerResumeStrategy getResumeStrategy() {
- return resumeStrategy;
- }
-
- /**
- * Set a resume strategy for files. This makes it possible to define a strategy for resuming reading files after the
- * last point before stopping the application.
- *
- * See the {@link FileConsumerResumeStrategy} for implementation details
- *
- * @param resumeStrategy an instance of the resume strategy to be used
- */
- public void setResumeStrategy(FileConsumerResumeStrategy resumeStrategy) {
- this.resumeStrategy = resumeStrategy;
- }
-
/**
* Chmod value must be between 000 and 777; If there is a leading digit like in 0755 we will ignore it.
*/
diff --git a/components/camel-kafka/src/generated/java/org/apache/camel/component/kafka/KafkaComponentConfigurer.java b/components/camel-kafka/src/generated/java/org/apache/camel/component/kafka/KafkaComponentConfigurer.java
index 0d5a1c2..e2fa43e 100644
--- a/components/camel-kafka/src/generated/java/org/apache/camel/component/kafka/KafkaComponentConfigurer.java
+++ b/components/camel-kafka/src/generated/java/org/apache/camel/component/kafka/KafkaComponentConfigurer.java
@@ -160,8 +160,6 @@ public class KafkaComponentConfigurer extends PropertyConfigurerSupport implemen
case "requestRequiredAcks": getOrCreateConfiguration(target).setRequestRequiredAcks(property(camelContext, java.lang.String.class, value)); return true;
case "requesttimeoutms":
case "requestTimeoutMs": getOrCreateConfiguration(target).setRequestTimeoutMs(property(camelContext, java.lang.Integer.class, value)); return true;
- case "resumestrategy":
- case "resumeStrategy": getOrCreateConfiguration(target).setResumeStrategy(property(camelContext, org.apache.camel.component.kafka.consumer.support.KafkaConsumerResumeStrategy.class, value)); return true;
case "retries": getOrCreateConfiguration(target).setRetries(property(camelContext, java.lang.Integer.class, value)); return true;
case "retrybackoffms":
case "retryBackoffMs": getOrCreateConfiguration(target).setRetryBackoffMs(property(camelContext, java.lang.Integer.class, value)); return true;
@@ -374,8 +372,6 @@ public class KafkaComponentConfigurer extends PropertyConfigurerSupport implemen
case "requestRequiredAcks": return java.lang.String.class;
case "requesttimeoutms":
case "requestTimeoutMs": return java.lang.Integer.class;
- case "resumestrategy":
- case "resumeStrategy": return org.apache.camel.component.kafka.consumer.support.KafkaConsumerResumeStrategy.class;
case "retries": return java.lang.Integer.class;
case "retrybackoffms":
case "retryBackoffMs": return java.lang.Integer.class;
@@ -584,8 +580,6 @@ public class KafkaComponentConfigurer extends PropertyConfigurerSupport implemen
case "requestRequiredAcks": return getOrCreateConfiguration(target).getRequestRequiredAcks();
case "requesttimeoutms":
case "requestTimeoutMs": return getOrCreateConfiguration(target).getRequestTimeoutMs();
- case "resumestrategy":
- case "resumeStrategy": return getOrCreateConfiguration(target).getResumeStrategy();
case "retries": return getOrCreateConfiguration(target).getRetries();
case "retrybackoffms":
case "retryBackoffMs": return getOrCreateConfiguration(target).getRetryBackoffMs();
diff --git a/components/camel-kafka/src/generated/java/org/apache/camel/component/kafka/KafkaEndpointConfigurer.java b/components/camel-kafka/src/generated/java/org/apache/camel/component/kafka/KafkaEndpointConfigurer.java
index 270e758..2ee0b05 100644
--- a/components/camel-kafka/src/generated/java/org/apache/camel/component/kafka/KafkaEndpointConfigurer.java
+++ b/components/camel-kafka/src/generated/java/org/apache/camel/component/kafka/KafkaEndpointConfigurer.java
@@ -152,8 +152,6 @@ public class KafkaEndpointConfigurer extends PropertyConfigurerSupport implement
case "requestRequiredAcks": target.getConfiguration().setRequestRequiredAcks(property(camelContext, java.lang.String.class, value)); return true;
case "requesttimeoutms":
case "requestTimeoutMs": target.getConfiguration().setRequestTimeoutMs(property(camelContext, java.lang.Integer.class, value)); return true;
- case "resumestrategy":
- case "resumeStrategy": target.getConfiguration().setResumeStrategy(property(camelContext, org.apache.camel.component.kafka.consumer.support.KafkaConsumerResumeStrategy.class, value)); return true;
case "retries": target.getConfiguration().setRetries(property(camelContext, java.lang.Integer.class, value)); return true;
case "retrybackoffms":
case "retryBackoffMs": target.getConfiguration().setRetryBackoffMs(property(camelContext, java.lang.Integer.class, value)); return true;
@@ -358,8 +356,6 @@ public class KafkaEndpointConfigurer extends PropertyConfigurerSupport implement
case "requestRequiredAcks": return java.lang.String.class;
case "requesttimeoutms":
case "requestTimeoutMs": return java.lang.Integer.class;
- case "resumestrategy":
- case "resumeStrategy": return org.apache.camel.component.kafka.consumer.support.KafkaConsumerResumeStrategy.class;
case "retries": return java.lang.Integer.class;
case "retrybackoffms":
case "retryBackoffMs": return java.lang.Integer.class;
@@ -565,8 +561,6 @@ public class KafkaEndpointConfigurer extends PropertyConfigurerSupport implement
case "requestRequiredAcks": return target.getConfiguration().getRequestRequiredAcks();
case "requesttimeoutms":
case "requestTimeoutMs": return target.getConfiguration().getRequestTimeoutMs();
- case "resumestrategy":
- case "resumeStrategy": return target.getConfiguration().getResumeStrategy();
case "retries": return target.getConfiguration().getRetries();
case "retrybackoffms":
case "retryBackoffMs": return target.getConfiguration().getRetryBackoffMs();
diff --git a/components/camel-kafka/src/generated/java/org/apache/camel/component/kafka/KafkaEndpointUriFactory.java b/components/camel-kafka/src/generated/java/org/apache/camel/component/kafka/KafkaEndpointUriFactory.java
index 7ace7fd..250221a 100644
--- a/components/camel-kafka/src/generated/java/org/apache/camel/component/kafka/KafkaEndpointUriFactory.java
+++ b/components/camel-kafka/src/generated/java/org/apache/camel/component/kafka/KafkaEndpointUriFactory.java
@@ -21,7 +21,7 @@ public class KafkaEndpointUriFactory extends org.apache.camel.support.component.
private static final Set<String> SECRET_PROPERTY_NAMES;
private static final Set<String> MULTI_VALUE_PREFIXES;
static {
- Set<String> props = new HashSet<>(103);
+ Set<String> props = new HashSet<>(102);
props.add("synchronous");
props.add("queueBufferingMaxMessages");
props.add("allowManualCommit");
@@ -88,7 +88,6 @@ public class KafkaEndpointUriFactory extends org.apache.camel.support.component.
props.add("sslKeystorePassword");
props.add("kafkaManualCommitFactory");
props.add("sslEndpointAlgorithm");
- props.add("resumeStrategy");
props.add("topic");
props.add("sslProtocol");
props.add("sslKeymanagerAlgorithm");
diff --git a/components/camel-kafka/src/generated/resources/org/apache/camel/component/kafka/kafka.json b/components/camel-kafka/src/generated/resources/org/apache/camel/component/kafka/kafka.json
index 4758ba8..5007791 100644
--- a/components/camel-kafka/src/generated/resources/org/apache/camel/component/kafka/kafka.json
+++ b/components/camel-kafka/src/generated/resources/org/apache/camel/component/kafka/kafka.json
@@ -55,7 +55,6 @@
"partitionAssignor": { "kind": "property", "displayName": "Partition Assignor", "group": "consumer", "label": "consumer", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "org.apache.kafka.clients.consumer.RangeAssignor", "configurationClass": "org.apache.camel.component.kafka.KafkaConfiguration", "configurationField": "configuration", "description": "The class name of the partition assignme [...]
"pollOnError": { "kind": "property", "displayName": "Poll On Error", "group": "consumer", "label": "consumer", "required": false, "type": "object", "javaType": "org.apache.camel.component.kafka.PollOnError", "enum": [ "DISCARD", "ERROR_HANDLER", "RECONNECT", "RETRY", "STOP" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "ERROR_HANDLER", "configurationClass": "org.apache.camel.component.kafka.KafkaConfiguration", "configurationField": "configuration", "de [...]
"pollTimeoutMs": { "kind": "property", "displayName": "Poll Timeout Ms", "group": "consumer", "label": "consumer", "required": false, "type": "duration", "javaType": "java.lang.Long", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "5000", "configurationClass": "org.apache.camel.component.kafka.KafkaConfiguration", "configurationField": "configuration", "description": "The timeout used when polling the KafkaConsumer." },
- "resumeStrategy": { "kind": "property", "displayName": "Resume Strategy", "group": "consumer", "label": "consumer", "required": false, "type": "object", "javaType": "org.apache.camel.component.kafka.consumer.support.KafkaConsumerResumeStrategy", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.kafka.KafkaConfiguration", "configurationField": "configuration", "description": "This option allows the user to set a custom resume s [...]
"seekTo": { "kind": "property", "displayName": "Seek To", "group": "consumer", "label": "consumer", "required": false, "type": "string", "javaType": "java.lang.String", "enum": [ "beginning", "end" ], "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.kafka.KafkaConfiguration", "configurationField": "configuration", "description": "Set if KafkaConsumer will read from beginning or end on startup: beginning : read from beginning [...]
"sessionTimeoutMs": { "kind": "property", "displayName": "Session Timeout Ms", "group": "consumer", "label": "consumer", "required": false, "type": "integer", "javaType": "java.lang.Integer", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "10000", "configurationClass": "org.apache.camel.component.kafka.KafkaConfiguration", "configurationField": "configuration", "description": "The timeout used to detect failures when using Kafka's group management facilities." },
"specificAvroReader": { "kind": "property", "displayName": "Specific Avro Reader", "group": "consumer", "label": "confluent,consumer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.kafka.KafkaConfiguration", "configurationField": "configuration", "description": "This enables the use of a specific Avro reader for use with the Confluent Platf [...]
@@ -161,7 +160,6 @@
"partitionAssignor": { "kind": "parameter", "displayName": "Partition Assignor", "group": "consumer", "label": "consumer", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "org.apache.kafka.clients.consumer.RangeAssignor", "configurationClass": "org.apache.camel.component.kafka.KafkaConfiguration", "configurationField": "configuration", "description": "The class name of the partition assignm [...]
"pollOnError": { "kind": "parameter", "displayName": "Poll On Error", "group": "consumer", "label": "consumer", "required": false, "type": "object", "javaType": "org.apache.camel.component.kafka.PollOnError", "enum": [ "DISCARD", "ERROR_HANDLER", "RECONNECT", "RETRY", "STOP" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "ERROR_HANDLER", "configurationClass": "org.apache.camel.component.kafka.KafkaConfiguration", "configurationField": "configuration", "d [...]
"pollTimeoutMs": { "kind": "parameter", "displayName": "Poll Timeout Ms", "group": "consumer", "label": "consumer", "required": false, "type": "duration", "javaType": "java.lang.Long", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "5000", "configurationClass": "org.apache.camel.component.kafka.KafkaConfiguration", "configurationField": "configuration", "description": "The timeout used when polling the KafkaConsumer." },
- "resumeStrategy": { "kind": "parameter", "displayName": "Resume Strategy", "group": "consumer", "label": "consumer", "required": false, "type": "object", "javaType": "org.apache.camel.component.kafka.consumer.support.KafkaConsumerResumeStrategy", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.kafka.KafkaConfiguration", "configurationField": "configuration", "description": "This option allows the user to set a custom resume [...]
"seekTo": { "kind": "parameter", "displayName": "Seek To", "group": "consumer", "label": "consumer", "required": false, "type": "string", "javaType": "java.lang.String", "enum": [ "beginning", "end" ], "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.kafka.KafkaConfiguration", "configurationField": "configuration", "description": "Set if KafkaConsumer will read from beginning or end on startup: beginning : read from beginning [...]
"sessionTimeoutMs": { "kind": "parameter", "displayName": "Session Timeout Ms", "group": "consumer", "label": "consumer", "required": false, "type": "integer", "javaType": "java.lang.Integer", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "10000", "configurationClass": "org.apache.camel.component.kafka.KafkaConfiguration", "configurationField": "configuration", "description": "The timeout used to detect failures when using Kafka's group management facilities." },
"specificAvroReader": { "kind": "parameter", "displayName": "Specific Avro Reader", "group": "consumer", "label": "confluent,consumer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.kafka.KafkaConfiguration", "configurationField": "configuration", "description": "This enables the use of a specific Avro reader for use with the Confluent Plat [...]
diff --git a/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/KafkaConfiguration.java b/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/KafkaConfiguration.java
index 74a1cb1..7c75e44 100644
--- a/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/KafkaConfiguration.java
+++ b/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/KafkaConfiguration.java
@@ -27,7 +27,6 @@ import java.util.stream.Collectors;
import org.apache.camel.Exchange;
import org.apache.camel.RuntimeCamelException;
import org.apache.camel.component.kafka.consumer.KafkaManualCommit;
-import org.apache.camel.component.kafka.consumer.support.KafkaConsumerResumeStrategy;
import org.apache.camel.component.kafka.serde.DefaultKafkaHeaderDeserializer;
import org.apache.camel.component.kafka.serde.DefaultKafkaHeaderSerializer;
import org.apache.camel.component.kafka.serde.KafkaHeaderDeserializer;
@@ -149,9 +148,6 @@ public class KafkaConfiguration implements Cloneable, HeaderFilterStrategyAware
@UriParam(label = "consumer", defaultValue = "5000", javaType = "java.time.Duration")
private Long commitTimeoutMs = 5000L;
- @UriParam(label = "consumer")
- private KafkaConsumerResumeStrategy resumeStrategy;
-
// Producer configuration properties
@UriParam(label = "producer", defaultValue = KafkaConstants.KAFKA_DEFAULT_PARTITIONER)
private String partitioner = KafkaConstants.KAFKA_DEFAULT_PARTITIONER;
@@ -802,26 +798,6 @@ public class KafkaConfiguration implements Cloneable, HeaderFilterStrategyAware
this.breakOnFirstError = breakOnFirstError;
}
- public KafkaConsumerResumeStrategy getResumeStrategy() {
- return resumeStrategy;
- }
-
- /**
- * This option allows the user to set a custom resume strategy. The resume strategy is executed when partitions are
- * assigned (i.e.: when connecting or reconnecting). It allows implementations to customize how to resume operations
- * and serve as more flexible alternative to the seekTo and the offsetRepository mechanisms.
- *
- * See the {@link KafkaConsumerResumeStrategy} for implementation details.
- *
- * This option does not affect the auto commit setting. It is likely that implementations using this setting will
- * also want to evaluate using the manual commit option along with this.
- *
- * @param resumeStrategy An instance of the resume strategy
- */
- public void setResumeStrategy(KafkaConsumerResumeStrategy resumeStrategy) {
- this.resumeStrategy = resumeStrategy;
- }
-
public String getBrokers() {
return brokers;
}
diff --git a/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/consumer/support/ResumeStrategyFactory.java b/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/consumer/support/ResumeStrategyFactory.java
index c2648ce..2db61f1 100644
--- a/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/consumer/support/ResumeStrategyFactory.java
+++ b/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/consumer/support/ResumeStrategyFactory.java
@@ -65,11 +65,6 @@ public final class ResumeStrategyFactory {
KafkaConfiguration configuration = kafkaConsumer.getEndpoint().getConfiguration();
- if (configuration.getResumeStrategy() != null) {
- LOG.info("Using user-provided strategy");
- return configuration.getResumeStrategy();
- }
-
return builtinResumeStrategies(configuration);
}
diff --git a/components/camel-kafka/src/test/java/org/apache/camel/component/kafka/integration/KafkaConsumerWithResumeStrategyIT.java b/components/camel-kafka/src/test/java/org/apache/camel/component/kafka/integration/KafkaConsumerWithResumeStrategyIT.java
deleted file mode 100644
index fb8bae5..0000000
--- a/components/camel-kafka/src/test/java/org/apache/camel/component/kafka/integration/KafkaConsumerWithResumeStrategyIT.java
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.camel.component.kafka.integration;
-
-import java.util.Collections;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
-
-import org.apache.camel.BindToRegistry;
-import org.apache.camel.EndpointInject;
-import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.kafka.consumer.support.KafkaConsumerResumeStrategy;
-import org.apache.camel.component.kafka.consumer.support.KafkaResumable;
-import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.kafka.clients.consumer.Consumer;
-import org.junit.jupiter.api.AfterEach;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.Timeout;
-
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-public class KafkaConsumerWithResumeStrategyIT extends BaseEmbeddedKafkaTestSupport {
- private static final String TOPIC = "custom-resume";
-
- @EndpointInject("mock:result")
- private MockEndpoint result;
-
- @BindToRegistry("resumeStrategy")
- private TestKafkaConsumerResumeStrategy resumeStrategy;
- private CountDownLatch messagesLatch;
-
- private static class TestKafkaConsumerResumeStrategy implements KafkaConsumerResumeStrategy {
- private final CountDownLatch messagesLatch;
- private boolean resumeCalled;
- private boolean consumerIsNull = true;
-
- public TestKafkaConsumerResumeStrategy(CountDownLatch messagesLatch) {
- this.messagesLatch = messagesLatch;
- }
-
- @Override
- public void setConsumer(Consumer<?, ?> consumer) {
- if (consumer != null) {
- consumerIsNull = false;
- }
- }
-
- @Override
- public void resume(KafkaResumable resumable) {
- resumeCalled = true;
- messagesLatch.countDown();
- }
-
- @Override
- public void resume() {
-
- }
-
- public boolean isResumeCalled() {
- return resumeCalled;
- }
-
- public boolean isConsumerIsNull() {
- return consumerIsNull;
- }
-
- @Override
- public void start() throws Exception {
-
- }
- }
-
- @Override
- protected void doPreSetup() {
- messagesLatch = new CountDownLatch(1);
- resumeStrategy = new TestKafkaConsumerResumeStrategy(messagesLatch);
- }
-
- @Test
- @Timeout(value = 30)
- public void offsetGetStateMustHaveBeenCalledTwice() throws InterruptedException {
- assertTrue(messagesLatch.await(4, TimeUnit.SECONDS), "The resume was not called");
-
- assertTrue(resumeStrategy.isResumeCalled(),
- "The resume strategy should have been called when the partition was assigned");
- assertFalse(resumeStrategy.isConsumerIsNull(),
- "The consumer passed to the strategy should not be null");
- }
-
- @AfterEach
- public void after() {
- kafkaAdminClient.deleteTopics(Collections.singletonList(TOPIC));
- }
-
- @Override
- protected RouteBuilder createRouteBuilder() throws Exception {
- return new RouteBuilder() {
- @Override
- public void configure() throws Exception {
- from("kafka:" + TOPIC + "?groupId=" + TOPIC + "_GROUP&autoCommitIntervalMs=1000"
- + "&autoOffsetReset=latest" + "&consumersCount=1"
- + "&resumeStrategy=#resumeStrategy")
- .routeId("resume-strategy-route")
- .to("mock:result");
- }
- };
- }
-}
diff --git a/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerResumeFromOffsetStrategyTest.java b/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerResumeFromOffsetStrategyTest.java
index f12941d..2ef283c 100644
--- a/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerResumeFromOffsetStrategyTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerResumeFromOffsetStrategyTest.java
@@ -17,6 +17,8 @@
package org.apache.camel.component.file;
import java.io.File;
+import java.util.HashMap;
+import java.util.Map;
import org.apache.camel.ContextTestSupport;
import org.apache.camel.Exchange;
@@ -25,6 +27,7 @@ import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.file.consumer.GenericFileResumable;
import org.apache.camel.component.file.consumer.GenericFileResumeStrategy;
import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.resume.Resumables;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
@@ -42,6 +45,7 @@ public class FileConsumerResumeFromOffsetStrategyTest extends ContextTestSupport
@Override
public void resume() {
+ throw new UnsupportedOperationException("Unsupported operation");
// NO-OP
}
@@ -57,7 +61,11 @@ public class FileConsumerResumeFromOffsetStrategyTest extends ContextTestSupport
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedBodiesReceivedInAnyOrder("34567890");
- template.sendBodyAndHeader(fileUri("resumeOff"), "01234567890", Exchange.FILE_NAME, "resume-from-offset.txt");
+ Map<String, Object> headers = new HashMap<>();
+ headers.put(Exchange.FILE_NAME, "resume-from-offset.txt");
+ headers.put("CamelOffset", Resumables.of("resume-from-offset.txt", 3L));
+
+ template.sendBodyAndHeaders(fileUri("resumeOff"), "01234567890", headers);
// only expect 4 of the 6 sent
assertMockEndpointsSatisfied();
@@ -79,11 +87,13 @@ public class FileConsumerResumeFromOffsetStrategyTest extends ContextTestSupport
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
- public void configure() throws Exception {
+ public void configure() {
- bindToRegistry("testResumeStrategy", new TestResumeStrategy());
+ bindToRegistry("resumeStrategy", new TestResumeStrategy());
- from(fileUri("resumeOff?noop=true&recursive=true&resumeStrategy=#testResumeStrategy"))
+ from(fileUri("resumeOff?noop=true&recursive=true"))
+ .resumable().header("CamelOffset").resumableStrategyRef("resumeStrategy")
+ .log("${body}")
.convertBodyTo(String.class).to("mock:result");
from(fileUri("resumeNone?noop=true&recursive=true"))
diff --git a/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerResumeStrategyTest.java b/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerResumeStrategyTest.java
index d70134e..e867cf2 100644
--- a/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerResumeStrategyTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerResumeStrategyTest.java
@@ -18,6 +18,7 @@ package org.apache.camel.component.file;
import java.util.Arrays;
import java.util.List;
+import java.util.Map;
import java.util.Objects;
import org.apache.camel.ContextTestSupport;
@@ -26,6 +27,7 @@ import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.file.consumer.FileResumeSet;
import org.apache.camel.component.file.consumer.FileSetResumeStrategy;
import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.resume.Resumables;
import org.junit.jupiter.api.Test;
public class FileConsumerResumeStrategyTest extends ContextTestSupport {
@@ -54,18 +56,25 @@ public class FileConsumerResumeStrategyTest extends ContextTestSupport {
}
}
+ private static Map<String, Object> headerFor(int num) {
+ String name = num + ".txt";
+
+ return Map.of(Exchange.FILE_NAME, name, "id", Resumables.of(name, num));
+ }
+
@Test
public void testResume() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedBodiesReceivedInAnyOrder("3", "4", "5", "6");
- template.sendBodyAndHeader(fileUri("resume"), "0", Exchange.FILE_NAME, "0.txt");
- template.sendBodyAndHeader(fileUri("resume"), "1", Exchange.FILE_NAME, "1.txt");
- template.sendBodyAndHeader(fileUri("resume"), "2", Exchange.FILE_NAME, "2.txt");
- template.sendBodyAndHeader(fileUri("resume"), "3", Exchange.FILE_NAME, "3.txt");
- template.sendBodyAndHeader(fileUri("resume"), "4", Exchange.FILE_NAME, "4.txt");
- template.sendBodyAndHeader(fileUri("resume"), "5", Exchange.FILE_NAME, "5.txt");
- template.sendBodyAndHeader(fileUri("resume"), "6", Exchange.FILE_NAME, "6.txt");
+
+ template.sendBodyAndHeaders(fileUri("resume"), "0", headerFor(0));
+ template.sendBodyAndHeaders(fileUri("resume"), "1", headerFor(1));
+ template.sendBodyAndHeaders(fileUri("resume"), "2", headerFor(2));
+ template.sendBodyAndHeaders(fileUri("resume"), "3", headerFor(3));
+ template.sendBodyAndHeaders(fileUri("resume"), "4", headerFor(4));
+ template.sendBodyAndHeaders(fileUri("resume"), "5", headerFor(5));
+ template.sendBodyAndHeaders(fileUri("resume"), "6", headerFor(6));
// only expect 4 of the 6 sent
assertMockEndpointsSatisfied();
@@ -79,7 +88,8 @@ public class FileConsumerResumeStrategyTest extends ContextTestSupport {
bindToRegistry("testResumeStrategy", new TestResumeStrategy());
- from(fileUri("resume?noop=true&recursive=true&resumeStrategy=#testResumeStrategy"))
+ from(fileUri("resume?noop=true&recursive=true"))
+ .resumable().header("id").resumableStrategyRef("testResumeStrategy")
.convertBodyTo(String.class)
.to("mock:result");
}
diff --git a/dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/Aws2KinesisComponentBuilderFactory.java b/dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/Aws2KinesisComponentBuilderFactory.java
index 061c1c0..c6ac5e1 100644
--- a/dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/Aws2KinesisComponentBuilderFactory.java
+++ b/dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/Aws2KinesisComponentBuilderFactory.java
@@ -286,24 +286,6 @@ public interface Aws2KinesisComponentBuilderFactory {
return this;
}
/**
- * Defines a resume strategy for AWS Kinesis. The default strategy reads
- * the sequenceNumber if provided.
- *
- * The option is a:
- * <code>org.apache.camel.component.aws2.kinesis.consumer.KinesisResumeStrategy</code> type.
- *
- * Default: KinesisUserConfigurationResumeStrategy
- * Group: consumer
- *
- * @param resumeStrategy the value to set
- * @return the dsl builder
- */
- default Aws2KinesisComponentBuilder resumeStrategy(
- org.apache.camel.component.aws2.kinesis.consumer.KinesisResumeStrategy resumeStrategy) {
- doSetProperty("resumeStrategy", resumeStrategy);
- return this;
- }
- /**
* The sequence number to start polling from. Required if iteratorType
* is set to AFTER_SEQUENCE_NUMBER or AT_SEQUENCE_NUMBER.
*
@@ -466,7 +448,6 @@ public interface Aws2KinesisComponentBuilderFactory {
case "bridgeErrorHandler": ((Kinesis2Component) component).setBridgeErrorHandler((boolean) value); return true;
case "iteratorType": getOrCreateConfiguration((Kinesis2Component) component).setIteratorType((software.amazon.awssdk.services.kinesis.model.ShardIteratorType) value); return true;
case "maxResultsPerRequest": getOrCreateConfiguration((Kinesis2Component) component).setMaxResultsPerRequest((int) value); return true;
- case "resumeStrategy": getOrCreateConfiguration((Kinesis2Component) component).setResumeStrategy((org.apache.camel.component.aws2.kinesis.consumer.KinesisResumeStrategy) value); return true;
case "sequenceNumber": getOrCreateConfiguration((Kinesis2Component) component).setSequenceNumber((java.lang.String) value); return true;
case "shardClosed": getOrCreateConfiguration((Kinesis2Component) component).setShardClosed((org.apache.camel.component.aws2.kinesis.Kinesis2ShardClosedStrategyEnum) value); return true;
case "shardId": getOrCreateConfiguration((Kinesis2Component) component).setShardId((java.lang.String) value); return true;
diff --git a/dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/KafkaComponentBuilderFactory.java b/dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/KafkaComponentBuilderFactory.java
index 7e81195..64703ab 100644
--- a/dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/KafkaComponentBuilderFactory.java
+++ b/dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/KafkaComponentBuilderFactory.java
@@ -673,30 +673,6 @@ public interface KafkaComponentBuilderFactory {
return this;
}
/**
- * This option allows the user to set a custom resume strategy. The
- * resume strategy is executed when partitions are assigned (i.e.: when
- * connecting or reconnecting). It allows implementations to customize
- * how to resume operations and serve as more flexible alternative to
- * the seekTo and the offsetRepository mechanisms. See the
- * KafkaConsumerResumeStrategy for implementation details. This option
- * does not affect the auto commit setting. It is likely that
- * implementations using this setting will also want to evaluate using
- * the manual commit option along with this.
- *
- * The option is a:
- * <code>org.apache.camel.component.kafka.consumer.support.KafkaConsumerResumeStrategy</code> type.
- *
- * Group: consumer
- *
- * @param resumeStrategy the value to set
- * @return the dsl builder
- */
- default KafkaComponentBuilder resumeStrategy(
- org.apache.camel.component.kafka.consumer.support.KafkaConsumerResumeStrategy resumeStrategy) {
- doSetProperty("resumeStrategy", resumeStrategy);
- return this;
- }
- /**
* Set if KafkaConsumer will read from beginning or end on startup:
* beginning : read from beginning end : read from end This is replacing
* the earlier property seekToBeginning.
@@ -2040,7 +2016,6 @@ public interface KafkaComponentBuilderFactory {
case "partitionAssignor": getOrCreateConfiguration((KafkaComponent) component).setPartitionAssignor((java.lang.String) value); return true;
case "pollOnError": getOrCreateConfiguration((KafkaComponent) component).setPollOnError((org.apache.camel.component.kafka.PollOnError) value); return true;
case "pollTimeoutMs": getOrCreateConfiguration((KafkaComponent) component).setPollTimeoutMs((java.lang.Long) value); return true;
- case "resumeStrategy": getOrCreateConfiguration((KafkaComponent) component).setResumeStrategy((org.apache.camel.component.kafka.consumer.support.KafkaConsumerResumeStrategy) value); return true;
case "seekTo": getOrCreateConfiguration((KafkaComponent) component).setSeekTo((java.lang.String) value); return true;
case "sessionTimeoutMs": getOrCreateConfiguration((KafkaComponent) component).setSessionTimeoutMs((java.lang.Integer) value); return true;
case "specificAvroReader": getOrCreateConfiguration((KafkaComponent) component).setSpecificAvroReader((boolean) value); return true;
diff --git a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/CouchDbEndpointBuilderFactory.java b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/CouchDbEndpointBuilderFactory.java
index 5016928..493d4d9 100644
--- a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/CouchDbEndpointBuilderFactory.java
+++ b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/CouchDbEndpointBuilderFactory.java
@@ -184,42 +184,6 @@ public interface CouchDbEndpointBuilderFactory {
return this;
}
/**
- * Sets a custom resume strategy for tracking changes from CouchDB. It
- * allows tracking from a specific point (i.e.: since the given update
- * sequence, the latest sequence, etc).
- *
- * The option is a:
- * <code>org.apache.camel.component.couchdb.consumer.CouchDbResumeStrategy</code> type.
- *
- * Group: consumer
- *
- * @param resumeStrategy the value to set
- * @return the dsl builder
- */
- default CouchDbEndpointConsumerBuilder resumeStrategy(
- org.apache.camel.component.couchdb.consumer.CouchDbResumeStrategy resumeStrategy) {
- doSetProperty("resumeStrategy", resumeStrategy);
- return this;
- }
- /**
- * Sets a custom resume strategy for tracking changes from CouchDB. It
- * allows tracking from a specific point (i.e.: since the given update
- * sequence, the latest sequence, etc).
- *
- * The option will be converted to a
- * <code>org.apache.camel.component.couchdb.consumer.CouchDbResumeStrategy</code> type.
- *
- * Group: consumer
- *
- * @param resumeStrategy the value to set
- * @return the dsl builder
- */
- default CouchDbEndpointConsumerBuilder resumeStrategy(
- String resumeStrategy) {
- doSetProperty("resumeStrategy", resumeStrategy);
- return this;
- }
- /**
* Specifies how many revisions are returned in the changes array. The
* default, main_only, will only return the current winning revision;
* all_docs will return all leaf revisions (including conflicts and
diff --git a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/FileEndpointBuilderFactory.java b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/FileEndpointBuilderFactory.java
index 85ee35a..ed3c98f 100644
--- a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/FileEndpointBuilderFactory.java
+++ b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/FileEndpointBuilderFactory.java
@@ -2393,44 +2393,6 @@ public interface FileEndpointBuilderFactory {
return this;
}
/**
- * Set a resume strategy for files. This makes it possible to define a
- * strategy for resuming reading files after the last point before
- * stopping the application. See the FileConsumerResumeStrategy for
- * implementation details.
- *
- * The option is a:
- * <code>org.apache.camel.component.file.consumer.FileConsumerResumeStrategy</code> type.
- *
- * Group: consumer (advanced)
- *
- * @param resumeStrategy the value to set
- * @return the dsl builder
- */
- default AdvancedFileEndpointConsumerBuilder resumeStrategy(
- org.apache.camel.component.file.consumer.FileConsumerResumeStrategy resumeStrategy) {
- doSetProperty("resumeStrategy", resumeStrategy);
- return this;
- }
- /**
- * Set a resume strategy for files. This makes it possible to define a
- * strategy for resuming reading files after the last point before
- * stopping the application. See the FileConsumerResumeStrategy for
- * implementation details.
- *
- * The option will be converted to a
- * <code>org.apache.camel.component.file.consumer.FileConsumerResumeStrategy</code> type.
- *
- * Group: consumer (advanced)
- *
- * @param resumeStrategy the value to set
- * @return the dsl builder
- */
- default AdvancedFileEndpointConsumerBuilder resumeStrategy(
- String resumeStrategy) {
- doSetProperty("resumeStrategy", resumeStrategy);
- return this;
- }
- /**
* Whether the starting directory must exist. Mind that the autoCreate
* option is default enabled, which means the starting directory is
* normally auto created if it doesn't exist. You can disable autoCreate
diff --git a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/KafkaEndpointBuilderFactory.java b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/KafkaEndpointBuilderFactory.java
index 41a9e2d..5d3cab9 100644
--- a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/KafkaEndpointBuilderFactory.java
+++ b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/KafkaEndpointBuilderFactory.java
@@ -1137,54 +1137,6 @@ public interface KafkaEndpointBuilderFactory {
return this;
}
/**
- * This option allows the user to set a custom resume strategy. The
- * resume strategy is executed when partitions are assigned (i.e.: when
- * connecting or reconnecting). It allows implementations to customize
- * how to resume operations and serve as more flexible alternative to
- * the seekTo and the offsetRepository mechanisms. See the
- * KafkaConsumerResumeStrategy for implementation details. This option
- * does not affect the auto commit setting. It is likely that
- * implementations using this setting will also want to evaluate using
- * the manual commit option along with this.
- *
- * The option is a:
- * <code>org.apache.camel.component.kafka.consumer.support.KafkaConsumerResumeStrategy</code> type.
- *
- * Group: consumer
- *
- * @param resumeStrategy the value to set
- * @return the dsl builder
- */
- default KafkaEndpointConsumerBuilder resumeStrategy(
- org.apache.camel.component.kafka.consumer.support.KafkaConsumerResumeStrategy resumeStrategy) {
- doSetProperty("resumeStrategy", resumeStrategy);
- return this;
- }
- /**
- * This option allows the user to set a custom resume strategy. The
- * resume strategy is executed when partitions are assigned (i.e.: when
- * connecting or reconnecting). It allows implementations to customize
- * how to resume operations and serve as more flexible alternative to
- * the seekTo and the offsetRepository mechanisms. See the
- * KafkaConsumerResumeStrategy for implementation details. This option
- * does not affect the auto commit setting. It is likely that
- * implementations using this setting will also want to evaluate using
- * the manual commit option along with this.
- *
- * The option will be converted to a
- * <code>org.apache.camel.component.kafka.consumer.support.KafkaConsumerResumeStrategy</code> type.
- *
- * Group: consumer
- *
- * @param resumeStrategy the value to set
- * @return the dsl builder
- */
- default KafkaEndpointConsumerBuilder resumeStrategy(
- String resumeStrategy) {
- doSetProperty("resumeStrategy", resumeStrategy);
- return this;
- }
- /**
* Set if KafkaConsumer will read from beginning or end on startup:
* beginning : read from beginning end : read from end This is replacing
* the earlier property seekToBeginning.
diff --git a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/Kinesis2EndpointBuilderFactory.java b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/Kinesis2EndpointBuilderFactory.java
index 17b70b5..d47755f 100644
--- a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/Kinesis2EndpointBuilderFactory.java
+++ b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/Kinesis2EndpointBuilderFactory.java
@@ -436,42 +436,6 @@ public interface Kinesis2EndpointBuilderFactory {
return this;
}
/**
- * Defines a resume strategy for AWS Kinesis. The default strategy reads
- * the sequenceNumber if provided.
- *
- * The option is a:
- * <code>org.apache.camel.component.aws2.kinesis.consumer.KinesisResumeStrategy</code> type.
- *
- * Default: KinesisUserConfigurationResumeStrategy
- * Group: consumer
- *
- * @param resumeStrategy the value to set
- * @return the dsl builder
- */
- default Kinesis2EndpointConsumerBuilder resumeStrategy(
- org.apache.camel.component.aws2.kinesis.consumer.KinesisResumeStrategy resumeStrategy) {
- doSetProperty("resumeStrategy", resumeStrategy);
- return this;
- }
- /**
- * Defines a resume strategy for AWS Kinesis. The default strategy reads
- * the sequenceNumber if provided.
- *
- * The option will be converted to a
- * <code>org.apache.camel.component.aws2.kinesis.consumer.KinesisResumeStrategy</code> type.
- *
- * Default: KinesisUserConfigurationResumeStrategy
- * Group: consumer
- *
- * @param resumeStrategy the value to set
- * @return the dsl builder
- */
- default Kinesis2EndpointConsumerBuilder resumeStrategy(
- String resumeStrategy) {
- doSetProperty("resumeStrategy", resumeStrategy);
- return this;
- }
- /**
* If the polling consumer did not poll any files, you can enable this
* option to send an empty message (no body) instead.
*
[camel] 13/16: CAMEL-15562: use the service interface to avoid overlap in life cycle management
Posted by or...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 1e76dd62c01ee474e962c73db11c38a55c32154f
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Tue Mar 1 11:15:22 2022 +0100
CAMEL-15562: use the service interface to avoid overlap in life cycle management
---
.../component/aws2/kinesis/consumer/KinesisResumeStrategy.java | 10 ++++++++++
.../consumer/KinesisUserConfigurationResumeStrategy.java | 5 -----
.../component/couchdb/consumer/CouchDbResumeStrategy.java | 10 ++++++++++
.../couchdb/consumer/LatestUpdateSequenceResumeStrategy.java | 5 -----
.../kafka/consumer/support/KafkaConsumerResumeStrategy.java | 10 ++++++++++
.../consumer/support/OffsetKafkaConsumerResumeStrategy.java | 5 -----
.../kafka/consumer/support/ResumeStrategyFactory.java | 5 -----
.../support/SeekPolicyKafkaConsumerResumeStrategy.java | 5 -----
.../integration/KafkaConsumerWithResumeRouteStrategyIT.java | 6 ------
.../src/main/java/org/apache/camel/ResumeStrategy.java | 9 +--------
.../file/FileConsumerResumeFromOffsetStrategyTest.java | 7 ++++++-
.../camel/component/file/FileConsumerResumeStrategyTest.java | 7 ++++++-
12 files changed, 43 insertions(+), 41 deletions(-)
diff --git a/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/kinesis/consumer/KinesisResumeStrategy.java b/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/kinesis/consumer/KinesisResumeStrategy.java
index 6c3ae6f..0592bfb 100644
--- a/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/kinesis/consumer/KinesisResumeStrategy.java
+++ b/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/kinesis/consumer/KinesisResumeStrategy.java
@@ -23,4 +23,14 @@ import software.amazon.awssdk.services.kinesis.model.GetShardIteratorRequest;
public interface KinesisResumeStrategy extends ResumeStrategy {
void setRequestBuilder(GetShardIteratorRequest.Builder builder);
+
+ @Override
+ default void start() {
+
+ }
+
+ @Override
+ default void stop() {
+
+ }
}
diff --git a/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/kinesis/consumer/KinesisUserConfigurationResumeStrategy.java b/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/kinesis/consumer/KinesisUserConfigurationResumeStrategy.java
index e5c92fc..5633443 100644
--- a/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/kinesis/consumer/KinesisUserConfigurationResumeStrategy.java
+++ b/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/kinesis/consumer/KinesisUserConfigurationResumeStrategy.java
@@ -46,9 +46,4 @@ public class KinesisUserConfigurationResumeStrategy implements KinesisResumeStra
resumable.startingSequenceNumber(configuration.getSequenceNumber());
}
}
-
- @Override
- public void start() throws Exception {
-
- }
}
diff --git a/components/camel-couchdb/src/main/java/org/apache/camel/component/couchdb/consumer/CouchDbResumeStrategy.java b/components/camel-couchdb/src/main/java/org/apache/camel/component/couchdb/consumer/CouchDbResumeStrategy.java
index 14d87d4..3a92a04 100644
--- a/components/camel-couchdb/src/main/java/org/apache/camel/component/couchdb/consumer/CouchDbResumeStrategy.java
+++ b/components/camel-couchdb/src/main/java/org/apache/camel/component/couchdb/consumer/CouchDbResumeStrategy.java
@@ -24,4 +24,14 @@ import org.apache.camel.ResumeStrategy;
*/
public interface CouchDbResumeStrategy extends ResumeStrategy {
void setResumable(CouchDbResumable resumable);
+
+ @Override
+ default void start() {
+
+ }
+
+ @Override
+ default void stop() {
+
+ }
}
diff --git a/components/camel-couchdb/src/main/java/org/apache/camel/component/couchdb/consumer/LatestUpdateSequenceResumeStrategy.java b/components/camel-couchdb/src/main/java/org/apache/camel/component/couchdb/consumer/LatestUpdateSequenceResumeStrategy.java
index 04679d8..277d842 100644
--- a/components/camel-couchdb/src/main/java/org/apache/camel/component/couchdb/consumer/LatestUpdateSequenceResumeStrategy.java
+++ b/components/camel-couchdb/src/main/java/org/apache/camel/component/couchdb/consumer/LatestUpdateSequenceResumeStrategy.java
@@ -36,9 +36,4 @@ public final class LatestUpdateSequenceResumeStrategy implements CouchDbResumeSt
resumable.updateLastOffset(clientWrapper.getLatestUpdateSequence());
}
-
- @Override
- public void start() throws Exception {
-
- }
}
diff --git a/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/consumer/support/KafkaConsumerResumeStrategy.java b/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/consumer/support/KafkaConsumerResumeStrategy.java
index 35eb879..97f25e0 100644
--- a/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/consumer/support/KafkaConsumerResumeStrategy.java
+++ b/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/consumer/support/KafkaConsumerResumeStrategy.java
@@ -33,4 +33,14 @@ public interface KafkaConsumerResumeStrategy extends ResumeStrategy {
default void resume(KafkaResumable resumable) {
}
+
+ @Override
+ default void start() {
+
+ }
+
+ @Override
+ default void stop() {
+
+ }
}
diff --git a/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/consumer/support/OffsetKafkaConsumerResumeStrategy.java b/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/consumer/support/OffsetKafkaConsumerResumeStrategy.java
index 3875184..4502831 100644
--- a/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/consumer/support/OffsetKafkaConsumerResumeStrategy.java
+++ b/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/consumer/support/OffsetKafkaConsumerResumeStrategy.java
@@ -73,9 +73,4 @@ public class OffsetKafkaConsumerResumeStrategy implements KafkaConsumerResumeStr
public void resume(KafkaResumable resumable) {
resume();
}
-
- @Override
- public void start() throws Exception {
-
- }
}
diff --git a/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/consumer/support/ResumeStrategyFactory.java b/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/consumer/support/ResumeStrategyFactory.java
index d1656f86..c4fdb6d 100644
--- a/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/consumer/support/ResumeStrategyFactory.java
+++ b/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/consumer/support/ResumeStrategyFactory.java
@@ -41,11 +41,6 @@ public final class ResumeStrategyFactory {
public void resume() {
}
-
- @Override
- public void start() throws Exception {
-
- }
}
private static final NoOpKafkaConsumerResumeStrategy NO_OP_RESUME_STRATEGY = new NoOpKafkaConsumerResumeStrategy();
diff --git a/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/consumer/support/SeekPolicyKafkaConsumerResumeStrategy.java b/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/consumer/support/SeekPolicyKafkaConsumerResumeStrategy.java
index 46fd974..91db91b 100644
--- a/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/consumer/support/SeekPolicyKafkaConsumerResumeStrategy.java
+++ b/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/consumer/support/SeekPolicyKafkaConsumerResumeStrategy.java
@@ -58,9 +58,4 @@ public class SeekPolicyKafkaConsumerResumeStrategy implements KafkaConsumerResum
public void resume(KafkaResumable resumable) {
resume();
}
-
- @Override
- public void start() throws Exception {
-
- }
}
diff --git a/components/camel-kafka/src/test/java/org/apache/camel/component/kafka/integration/KafkaConsumerWithResumeRouteStrategyIT.java b/components/camel-kafka/src/test/java/org/apache/camel/component/kafka/integration/KafkaConsumerWithResumeRouteStrategyIT.java
index aeb5de3..c6a27ca 100644
--- a/components/camel-kafka/src/test/java/org/apache/camel/component/kafka/integration/KafkaConsumerWithResumeRouteStrategyIT.java
+++ b/components/camel-kafka/src/test/java/org/apache/camel/component/kafka/integration/KafkaConsumerWithResumeRouteStrategyIT.java
@@ -111,13 +111,7 @@ public class KafkaConsumerWithResumeRouteStrategyIT extends BaseEmbeddedKafkaTes
}
@Override
- public void stop() {
-
- }
-
- @Override
public void init() {
- Service.super.init();
LOG.warn("Init was called");
}
diff --git a/core/camel-api/src/main/java/org/apache/camel/ResumeStrategy.java b/core/camel-api/src/main/java/org/apache/camel/ResumeStrategy.java
index a271cd4..f23e762 100644
--- a/core/camel-api/src/main/java/org/apache/camel/ResumeStrategy.java
+++ b/core/camel-api/src/main/java/org/apache/camel/ResumeStrategy.java
@@ -21,7 +21,7 @@ package org.apache.camel;
* Defines a strategy for handling resume operations. Implementations can define different ways to handle how to resume
* processing records.
*/
-public interface ResumeStrategy {
+public interface ResumeStrategy extends Service {
/**
* A consumer, iterator or value class that can be used to set the index position from which to resume from. The
@@ -29,11 +29,4 @@ public interface ResumeStrategy {
*
*/
void resume();
-
- /**
- * Starts the resume strategy
- *
- * @throws Exception
- */
- void start() throws Exception;
}
diff --git a/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerResumeFromOffsetStrategyTest.java b/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerResumeFromOffsetStrategyTest.java
index fdf0315..2db4785 100644
--- a/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerResumeFromOffsetStrategyTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerResumeFromOffsetStrategyTest.java
@@ -50,7 +50,12 @@ public class FileConsumerResumeFromOffsetStrategyTest extends ContextTestSupport
}
@Override
- public void start() throws Exception {
+ public void start() {
+
+ }
+
+ @Override
+ public void stop() {
}
}
diff --git a/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerResumeStrategyTest.java b/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerResumeStrategyTest.java
index 5adb2dd..bf662ee 100644
--- a/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerResumeStrategyTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerResumeStrategyTest.java
@@ -51,7 +51,12 @@ public class FileConsumerResumeStrategyTest extends ContextTestSupport {
}
@Override
- public void start() throws Exception {
+ public void start() {
+
+ }
+
+ @Override
+ public void stop() {
}
}
[camel] 03/16: CAMEL-15562: cleanup the creation of the strategy factories
Posted by or...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 0992cbc2b28bb6bc385a7a4fe3d7eb16c6558fcc
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Fri Feb 4 09:18:48 2022 +0100
CAMEL-15562: cleanup the creation of the strategy factories
---
.../apache/camel/component/kafka/KafkaFetchRecords.java | 10 ++++++----
.../consumer/support/PartitionAssignmentListener.java | 14 +++-----------
.../kafka/consumer/support/ResumeStrategyFactory.java | 15 ++++++++++++++-
3 files changed, 23 insertions(+), 16 deletions(-)
diff --git a/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/KafkaFetchRecords.java b/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/KafkaFetchRecords.java
index deeef3c..91728e3 100644
--- a/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/KafkaFetchRecords.java
+++ b/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/KafkaFetchRecords.java
@@ -32,6 +32,7 @@ import org.apache.camel.component.kafka.consumer.support.KafkaConsumerResumeStra
import org.apache.camel.component.kafka.consumer.support.KafkaRecordProcessorFacade;
import org.apache.camel.component.kafka.consumer.support.PartitionAssignmentListener;
import org.apache.camel.component.kafka.consumer.support.ProcessingResult;
+import org.apache.camel.component.kafka.consumer.support.ResumeStrategyFactory;
import org.apache.camel.support.BridgeExceptionHandlerToErrorHandler;
import org.apache.camel.util.IOHelper;
import org.apache.kafka.clients.consumer.ConsumerRecords;
@@ -137,12 +138,13 @@ class KafkaFetchRecords implements Runnable {
}
private void subscribe() {
- KafkaConsumerResumeStrategy userProvidedStrategy
- = kafkaConsumer.getEndpoint().getCamelContext().hasService(KafkaConsumerResumeStrategy.class);
+
+ KafkaConsumerResumeStrategy resumeStrategy = ResumeStrategyFactory.newResumeStrategy(kafkaConsumer);
+ resumeStrategy.setConsumer(consumer);
PartitionAssignmentListener listener = new PartitionAssignmentListener(
- threadId, kafkaConsumer.getEndpoint().getConfiguration(), consumer, lastProcessedOffset,
- this::isRunnable, commitManager, userProvidedStrategy);
+ threadId, kafkaConsumer.getEndpoint().getConfiguration(), lastProcessedOffset,
+ this::isRunnable, commitManager, resumeStrategy);
if (LOG.isInfoEnabled()) {
LOG.info("Subscribing {} to {}", threadId, getPrintableTopic());
diff --git a/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/consumer/support/PartitionAssignmentListener.java b/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/consumer/support/PartitionAssignmentListener.java
index fe19147..482f804 100644
--- a/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/consumer/support/PartitionAssignmentListener.java
+++ b/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/consumer/support/PartitionAssignmentListener.java
@@ -25,7 +25,6 @@ import java.util.stream.Collectors;
import org.apache.camel.component.kafka.KafkaConfiguration;
import org.apache.camel.component.kafka.consumer.CommitManager;
-import org.apache.kafka.clients.consumer.Consumer;
import org.apache.kafka.clients.consumer.ConsumerRebalanceListener;
import org.apache.kafka.common.TopicPartition;
import org.slf4j.Logger;
@@ -41,10 +40,10 @@ public class PartitionAssignmentListener implements ConsumerRebalanceListener {
private final Map<String, Long> lastProcessedOffset;
private final KafkaConsumerResumeStrategy resumeStrategy;
private final CommitManager commitManager;
- private Supplier<Boolean> stopStateSupplier;
+ private final Supplier<Boolean> stopStateSupplier;
public PartitionAssignmentListener(String threadId, KafkaConfiguration configuration,
- Consumer consumer, Map<String, Long> lastProcessedOffset,
+ Map<String, Long> lastProcessedOffset,
Supplier<Boolean> stopStateSupplier, CommitManager commitManager,
KafkaConsumerResumeStrategy resumeStrategy) {
this.threadId = threadId;
@@ -52,15 +51,8 @@ public class PartitionAssignmentListener implements ConsumerRebalanceListener {
this.lastProcessedOffset = lastProcessedOffset;
this.commitManager = commitManager;
this.stopStateSupplier = stopStateSupplier;
+ this.resumeStrategy = resumeStrategy;
- if (resumeStrategy == null) {
- LOG.info("No resume strategy was provided ... checking for builtins ...");
- this.resumeStrategy = ResumeStrategyFactory.newResumeStrategy(configuration);
- } else {
- LOG.info("Using user-provided strategy");
- this.resumeStrategy = resumeStrategy;
- }
- resumeStrategy.setConsumer(consumer);
}
@Override
diff --git a/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/consumer/support/ResumeStrategyFactory.java b/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/consumer/support/ResumeStrategyFactory.java
index 67707de..c2648ce 100644
--- a/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/consumer/support/ResumeStrategyFactory.java
+++ b/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/consumer/support/ResumeStrategyFactory.java
@@ -17,6 +17,7 @@
package org.apache.camel.component.kafka.consumer.support;
import org.apache.camel.component.kafka.KafkaConfiguration;
+import org.apache.camel.component.kafka.KafkaConsumer;
import org.apache.camel.spi.StateRepository;
import org.apache.kafka.clients.consumer.Consumer;
import org.slf4j.Logger;
@@ -53,8 +54,19 @@ public final class ResumeStrategyFactory {
private ResumeStrategyFactory() {
}
- public static KafkaConsumerResumeStrategy newResumeStrategy(KafkaConfiguration configuration) {
+ public static KafkaConsumerResumeStrategy newResumeStrategy(KafkaConsumer kafkaConsumer) {
+ // When using resumable routes, which register the strategy via service, it takes priority over everything else
+ KafkaConsumerResumeStrategy resumableRouteStrategy
+ = kafkaConsumer.getEndpoint().getCamelContext().hasService(KafkaConsumerResumeStrategy.class);
+
+ if (resumableRouteStrategy != null) {
+ return resumableRouteStrategy;
+ }
+
+ KafkaConfiguration configuration = kafkaConsumer.getEndpoint().getConfiguration();
+
if (configuration.getResumeStrategy() != null) {
+ LOG.info("Using user-provided strategy");
return configuration.getResumeStrategy();
}
@@ -62,6 +74,7 @@ public final class ResumeStrategyFactory {
}
private static KafkaConsumerResumeStrategy builtinResumeStrategies(KafkaConfiguration configuration) {
+ LOG.debug("No resume strategy was provided ... checking for built-ins ...");
StateRepository<String, String> offsetRepository = configuration.getOffsetRepository();
String seekTo = configuration.getSeekTo();
[camel] 15/16: CAMEL-15562: minor adjustments to the resume API log messages
Posted by or...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 519f6ab86649b671a9c719b7d826ead9f5b4d00a
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Tue Mar 1 12:59:13 2022 +0100
CAMEL-15562: minor adjustments to the resume API log messages
---
.../org/apache/camel/processor/resume/ResumableCompletion.java | 2 +-
.../java/org/apache/camel/processor/resume/ResumableProcessor.java | 7 ++++++-
2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/core/camel-core-processor/src/main/java/org/apache/camel/processor/resume/ResumableCompletion.java b/core/camel-core-processor/src/main/java/org/apache/camel/processor/resume/ResumableCompletion.java
index 62dba42..c7e712f 100644
--- a/core/camel-core-processor/src/main/java/org/apache/camel/processor/resume/ResumableCompletion.java
+++ b/core/camel-core-processor/src/main/java/org/apache/camel/processor/resume/ResumableCompletion.java
@@ -49,7 +49,7 @@ public class ResumableCompletion implements Synchronization {
LOG.error("Unable to update the offset: {}", e.getMessage(), e);
}
} else {
- LOG.warn("Cannot perform an offset update because the strategy is not updatable");
+ LOG.debug("Cannot perform an offset update because the strategy is not updatable");
}
}
}
diff --git a/core/camel-core-processor/src/main/java/org/apache/camel/processor/resume/ResumableProcessor.java b/core/camel-core-processor/src/main/java/org/apache/camel/processor/resume/ResumableProcessor.java
index 4c64a1c..ebc4d78 100644
--- a/core/camel-core-processor/src/main/java/org/apache/camel/processor/resume/ResumableProcessor.java
+++ b/core/camel-core-processor/src/main/java/org/apache/camel/processor/resume/ResumableProcessor.java
@@ -76,8 +76,13 @@ public class ResumableProcessor extends AsyncProcessorSupport
public ResumableProcessor(ResumeStrategy resumeStrategy, Processor processor) {
this.resumeStrategy = Objects.requireNonNull(resumeStrategy);
this.processor = AsyncProcessorConverterHelper.convert(processor);
+ }
+
+ @Override
+ protected void doStart() throws Exception {
+ LOG.debug("Enabling the resumable strategy of type: {}", resumeStrategy.getClass().getSimpleName());
- LOG.info("Enabling the resumable strategy of type: {}", resumeStrategy.getClass().getSimpleName());
+ super.doStart();
}
@Override