Commit Graph

10245 Commits

Author SHA1 Message Date
Chris Lemper
d8a1115f1f Kafka native offset implementation
Fixes #79 (https://github.com/spring-projects/spring-integration-kafka/pull/79)

Adds an implementation for offset management based on Kafka's own offset management support

Update copyright and use fill name in author tag.

Refactoring the native offset manager

Remove unused imports

Polishing
2020-06-25 11:28:42 -04:00
Artem Bilan
b6be2a33e7 Move XSD to the proper directory 2020-06-25 11:28:41 -04:00
Marius Bogoevici
b67fa489cb Adding a deprecated setter for KafkaProducerMessageHandler.setPartitionExpression() for backwards compatibility 2020-06-25 11:28:41 -04:00
Abhijith Prabhakar
32715799d9 Issue#67: fixing custom paritioner issue 2020-06-25 11:28:41 -04:00
Marius Bogoevici
fd93f91a78 Ignore broker bounce tests 2020-06-25 11:28:41 -04:00
Marius Bogoevici
3a5c2ffd77 Add test for producer key and payload cast 2020-06-25 11:28:40 -04:00
Gamal
21600a275d convertPayloadIfNecessary change to use Value Class Type
convertPayloadIfNecessary is using getProducerMetadata().getKeyClassType() when it should use getProducerMetadata().getValueClassType()
2020-06-25 11:28:40 -04:00
Marius Bogoevici
9b49e9a673 Deprecated Connection#getLeaders() - simplify DefaultConnectionFactory tests 2020-06-25 11:28:40 -04:00
Marius Bogoevici
9ddc4e6d12 Check if leader election is complete during tests 2020-06-25 11:28:40 -04:00
Marius Bogoevici
108197cffd Temporarily ignore bounce tests due to strain on CI environment 2020-06-25 11:28:40 -04:00
Martin Dam
bdb46760ad Support for sending messages synchronously to the Kafka broker.
Adds two fields to the producer-configuration that allows to set the send mode (async or sync) and an optional timeout in sync mode. Default behavior is async.
This allows for an upstream application to verify that the message have been handed off to Kafka following the delivery options specified, and not just residing in memory at the producer.
2020-06-25 11:28:39 -04:00
Artem Bilan
0065950830 GH-60: Get rid of HashCodeBuilder usage
Fixes #60 (https://github.com/spring-projects/spring-integration-kafka/issues/60)

* Upgrade to Gradle 2.5 and other dependencies
2020-06-25 11:28:39 -04:00
Artem Bilan
c1e1166895 Fix OutboundTests for required BeanFactory 2020-06-25 11:28:39 -04:00
Gary Russell
31439da037 Add High Level Consumer Integration Test
http://stackoverflow.com/questions/31668330/how-to-extract-the-data-from-a-kafka-inbound-message-with-spring/31681294#31681294

Polishing
2020-06-25 11:28:39 -04:00
Marius Bogoevici
c7f009f544 INTEXT-180: Fix ListenerContainer fetch pool size
JIRI: https://jira.spring.io/browse/INTEXT-180
2020-06-25 11:28:39 -04:00
Justin Walsh
19a27d7759 Fixed schema documentation for zookeeper-connect element 2020-06-25 11:28:38 -04:00
Artem Bilan
7695964e64 INTEXT-175: Fix IEC population
JIRA: https://jira.spring.io/browse/INTEXT-175

Since `IntegrationEvaluationContextAware` infrastructure had had wrong design and has been deprecated in the SI-4.2, change its usage to the proper way according to the SI-core recipes.

Tested against Spring IO-2.0.
2020-06-25 11:28:38 -04:00
Marius Bogoevici
b77f621c51 INTEXT-175 Replace onInit() check for IntegrationEvaluationContext
- replace the `onInit()` check for an `IntegrationEvaluationContext` with a getter
2020-06-25 11:28:38 -04:00
Marius Bogoevici
0956c0ad5a INTEXT-172 Make potentially long-running tasks SchedulingAwareRunnable 2020-06-25 11:28:38 -04:00
Marius Bogoevici
3cb57e96eb INTEXT-170 Use a custom MessageHeaders class
- revert to using a custom KafkaMessageHeaders class directly;
- avoid the use of MutableMessageHeaders and the subsequent assignment of ids and timestamps within a GenericMessageTemplate
2020-06-25 11:28:38 -04:00
Marius Bogoevici
35be1cb4fb QueueingMessageListenerInvoker fixes
- create latch before initiating shutdown;
- do not set latch to null inside onComplete();
- synchronize start and stop;
2020-06-25 11:28:37 -04:00
Marius Bogoevici
d0c0adc5bb Check that the queueSize is a positive integer 2020-06-25 11:28:37 -04:00
Gary Russell
1b28a7b863 INTEXT-169: Ensure queueSize is a Power of 2
JIRA: https://jira.spring.io/browse/INTEXT-169

Error from lmax is too far removed from configuration.
2020-06-25 11:28:37 -04:00
Marius Bogoevici
d475a79d83 Do not refresh metadata eagerly: 2020-06-25 11:28:37 -04:00
Marius Bogoevici
38856ee984 Add Reactor based ringbuffer
restart support

blocking stop

Test fixes

Ensure that an executor can be set externally

Polishing according PR comments
2020-06-25 11:28:36 -04:00
Marius Bogoevici
d8df11c2aa INTEXT-168 Upgrade to Kafka 0.8.2.1
JIRA: https://jira.spring.io/browse/INTEXT-168

- Replace producers with the new producer API
- Change KafkaProducerContext and ProducerConfiguration to match the new Producer's behaviour (i.e. providing partition as argument)
- support using the `partitionId` message header for targetting specific partitions;
- allow using a SpEL expression for partitioning;
- remove configurations that do not apply anymore, i.e. async (new producer is always async), batch size as message count, etc.
- add new configuration options wherever necessary;
- tweak schema - allow reuse of Encoders and Partitioners if available;

TODO: Add missing unit tests;

Fixes and polishing
2020-06-25 11:28:36 -04:00
Marius Bogoevici
fbe2975ed4 INTEXT-165 Recovery when cluster inaccessible
JIRA: https://jira.spring.io/browse/INTEXT-165

- retry fetching metadata until either successful or container stopped;
- do not stop the fetch task on connection errors, and handle it as a case when all partitions have moved;
- test broker stopped case + test enhancements for supporting broker restart;

Unused imports

Removed sysout calls from framework code

Reduced socket timeout, to improve timing on failover tests
2020-06-25 11:28:36 -04:00
Kevin Mooney
df652634a5 Fix expected type for listener-container attr 2020-06-25 11:28:36 -04:00
Marius Bogoevici
790d899953 INTEXT-159 DefaultConnectionFactory thread safety
- protect creation of connections with the lock as well, ensuring that it doesn't clash with refreshMetadata();
2020-06-25 11:28:36 -04:00
Marius Bogoevici
1e6e7b9bbf INTEXT 156-157
JIRA: https://jira.spring.io/browse/INTEXT-156
https://jira.spring.io/browse/INTEXT-157

- `KafkaMessageListenerContainer#stop()` returns only after the container has been effectively stopped, i.e. no more messages are dispatched to the listeners;
- add a configurable timeout property to prevent the previous operation from blocking indefinitely;
- create separate XSDs for 1.0 and 1.1 schemas;

Corrections after review

- removed 1.0 schema
- removed time-sensitive tests

Corrections after review

- removed 1.0 schema
- removed time-sensitive tests
- removed unused logger in QueueingMessageListenerInvoker

Clear messages after stopping

Clear partitionsByBrokersMap

Polishing imports and properties order
2020-06-25 11:28:35 -04:00
Marius Bogoevici
3e6a796e85 Improve performance of header generation
Using a regular HashMap instead of GS Collections' regular map improves performance, as the latter is more expensive to create.

Cleanup - put  references back
2020-06-25 11:28:35 -04:00
Gary Russell
52d218988b INTEXT-154: Namespace Support for New Features
JIRA: https://jira.spring.io/browse/INTEXT-154, https://jira.spring.io/browse/INTEXT-138
2020-06-25 11:28:35 -04:00
Marius Bogoevici
3ade92ba14 INTEXT-152 Improve message generation strategy
JIRA: https://jira.spring.io/browse/INTEXT-152

- upgrade to Spring Integration 4.1 and Spring 4.1 for MessageHeaders subclassing support;
- by default, the KafkaMessageDrivenChannelAdapter will create an optimized version of KafkaMessage;
- add settings for avoiding expensive ID and timestamp generation by default, with the option of turning them on;
- add a setting for reverting to superclass MessageBuilderFactory where that is necessary;

* JavaDocs polishing
2020-06-25 11:28:35 -04:00
Marius Bogoevici
0e0e8cebe3 INTEXT-153 Stop the KafkaMessageListenerContainer
JIRA: https://jira.spring.io/browse/INTEXT-153

- ensure that the fetch loop is exited immediately after the listener container is stopped;
- do not dispatch messages for processing once components are stopped;
2020-06-25 11:28:34 -04:00
Marius Bogoevici
5360aa3130 INTEXT-146 Fix NPE in KafkaMessageHandlerAdapter
JIRA: https://jira.spring.io/browse/INTEXT-146
2020-06-25 11:28:34 -04:00
Marius Bogoevici
da0f730298 INTEXT-145 Do not set the queue to fair 2020-06-25 11:28:34 -04:00
Marius Bogoevici
aef99fcd9d INTEXT-143 Add Support for Manual Acknowledgment
- Introduce an Acknowledgment object that message processors can invoke;
- Introduce an AcknowedgingMessageListener variation of the MessageListener that receives an Acknowledgment reference for the processed message;
- Add 'autoCommitOffset' settings to the KafkaMessageListenerContainer and KafkaMessageDrivenChannelAdapter, and the ability to inject a MessageListener or an AcknowledgingMessageListener in either (the allowed type depending on the offset management strategy)
- Prepopulate a message header for SI messages created by the KafkaMessageDrivenChannelAdapter if autoCommit is enabled or disabled;
- OffsetManager only sets values that are higher than the ones already set in a session (barring reset) - this is to prevent asynchrous acks to mistakenly revert checkpoints

Addressed PR comments

- removed autoOffsetCommit flag for the KafkaMessageListenerContainer, relying only on the messageListener type to detect one versus the other;
- added since tags
- added copyright

@since tags

Polishing
2020-06-25 11:28:34 -04:00
Marius Bogoevici
1d77012dae Increase timeout leniency for Kafka Offset Topic
Remove `Testing` "artefact"
2020-06-25 11:28:34 -04:00
Marius Bogoevici
ba647025b2 Log metadata fetch failures at INFO level.
We do not treat them as fatal.
2020-06-25 11:28:33 -04:00
Marius Bogoevici
ae2a1a08cd INTEXT-131-134: Add KafkaTopicOffsetManager
JIRA: https://jira.spring.io/browse/INTEXT-131, https://jira.spring.io/browse/INTEXT-134

Add deletion support to OffsetManagers

- Separate MetadataStore-related functionality and extract an AbstractOffsetManager to handle resetting/retrieving default offsets from Kafka
- Move connection parameters to the Configuration class
- Add deletion support to OffsetManagers
- Introduce KafkaOffsetManager

Renamed to TopicUtils

Use an embedded broker for outbound tests.

INTEXT-135 Dynamic producing to topics in the KafkaProducingMessageHandler

Rework how DefaultConnectionFactory manages cached metadata

-Renamed PartitionBrokerMap to a more apt MetadataCache
-Removed bidirectional mapping
-MetadataCache is still immutable but now allows to create new instances with new TopicMetadata
-As a result, DefaultConnectionFactory can load topic data as required, without requiring explicit resets
- DefaultConnectionFactory will refresh internally if data about a topic is not available, transparently retrieving data from the server

Corrections after PR comments:

- use a readLock for getLeaders as well
- renamed `refreshLeaders` to `refreshMetadata`
- various minor fixes

Double lock check
Make AbstractOffsetManager Disposable an close on that

Corrections, logs, etc.

INTEXT-131-134: Polishing

* Add `initialOffsets` "free" `AbstractOffsetManager`
* Get rid of `connectionFactory` ctor argument for the `KafkaTopicOffsetManager`
* `start/stop` checks to the `KafkaMessageDrivenChannelAdapterWithKafkaOffsetManagerTests`
* Add note to the `README.md` about `KafkaTopicOffsetManager`
2020-06-25 11:28:33 -04:00
Artem Bilan
d85677f61e INTEXT-129: Namespace support for KafkaMDCA
JIRA: https://jira.spring.io/browse/INTEXT-129

INTEXT-129: Polishing and Docs

Doc Polishing
2020-06-25 11:28:33 -04:00
Marius Bogoevici
2cae7420a3 Fixes a race condition in tests
https://build.spring.io/browse/INTEXT-KAFKA-JOB1-39
2020-06-25 11:28:33 -04:00
Artem Bilan
6a6d119c4e INTEXT-123-124-125: Ignore Snappy test 2020-06-25 11:28:33 -04:00
Artem Bilan
5989e618ed INTEXT-123-124-125: Increase maxWait for tests 2020-06-25 11:28:32 -04:00
Marius Bogoevici
6acf985cc1 INTEXT-123-124-125 Introducing SimpleConsumer API
JIRA: https://jira.spring.io/browse/INTEXT-123
https://jira.spring.io/browse/INTEXT-124
https://jira.spring.io/browse/INTEXT-125

The implementation has the following components:

- Configuration - allows retrieving a seed broker set either from a preconfigured list or from Zookeeper
- ConnectionFactory - manages and caches connections to a set of brokers
- Connection - handles low-level SimpleConsumer API calls and converts them to internal objects such as KafkaMessage and KafkaMessageBus
- KafkaTemplate - implements higher-level read operations on a Kafka broker
- OffsetManager - stores (potentially in a persistent fashion) offsets for a group of consumers, configures/resets initial offsets as necessary - can be configured to start at an arbitrary offset in a partition (e.g. replay since offset 100), or relative to a given timestamp (e.g. replay since Monday)
- KafkaMessageListenerContainer - retrieves messages from a given broker for an arbitrary set of partitions or topics (i.e. all partitions in the topics), invoking a MessageListener. Concurrency is adjustable, and allows processing multiple sets of partitions in parallel (while preserving ordering within a partition). Can poll multiple brokers (each on a parallel thread)
- KafkaInboundChannelAdapter - channel adapter using KMLC as underlying implementation
- AbstractDecodingMessageListener - utility base class for a MessageListener implementation that decodes the payload and key

Tests:
- Single and multi-broker configurations
- Partition subset retrieval
- Replicated sets
- Compression
- Starting offsets (with reset on wrong offset)
- Error handling (servers dropping and leader changes)

TO DO:
- namespace support

Remove warnings

Cleanup

Use ZookeeperConnect for configuring Zookeeper

Fixes, including:

- Extracted Connection and ConnectionFactory interfaces
- Made fields final where necessary
- Fixed Javadoc
- Added assertions
- Corrected headers

Updated copyright to 2015

Make connectivity parameters: timeouts, buffer size, minimum fetch size, fetch timeout configurable via ConnectionFactory. Remove sleep in KafkaMessageListenerContainer Add javadocs.

Addressing PR comments:

- renamed KafkaInboundChannelAdapter to KafkaMessageDrivenChannelAdapter
- removed unnecessary setters
- close ZkClient properly
- fix version

Must use TopicAndPartition as key

Log messages too via LoggingErrorHandler

Newline

- Make `MessageStoreOffsetManager` implement `Closeable` and `Flushable`
- Fix the configuration of `ErrorHandler`

We don't really need this initialization - it's premature optimization

Use ':' instead of ' ' as separator for the key

Fixes:

- Use 'getPhase' from superclass
- more cleanup

Defer to the superclass MessageBuilder factory and keep SI_FATAL_WHEN_NO_BEANFACTORY happy

Fix warnings in tests

Changes to support testing against external brokers
- refactored the rules so that an abstraction can be used
- topic name is configurable
- added (Ignored) TestSingleBrokerExternal that tests against an external broker
- refactored OutboundTest to use the new consumer

Properly catch TopicExistsException

Do not hold state for MetadataStoreOffsetManager
In KafkaMessageListenerContainer FetcherTasks will block if they have no partitions to listen to (to do - use separate monitors per task)
Updated test for offset reset to latest to wait until an actual refresh event takes place, thus preventing the test from not completing in case of a race condition

KafkaMessageDrivenChannelAdapter and KafkaMessageListenerContainer now throw new TopicNotFoundException if the topic does not exist on the broker
Renamed test classes to use the Test suffix.

Cleanup

Test if the component is still running when exiting the wait block

Serialization warnings

Addressing the last round of PR comments

Test configuration cleanup

The final polishing: code style, JavaDocs, renaming for test classes to the finish with `*Tests` suffix
2020-06-25 11:28:32 -04:00
Artem Bilan
46d06fd404 KAFKA-10: Fix for ConsumerConfiguration.executor
Fixes GH10 https://github.com/spring-projects/spring-integration-kafka/issues/10

Previously the `ConsumerConfiguration` used an internal `ExecutorService`.
In the management environment (App Server) it causes an issue with unmanaged Threads.

* Add `setExecutor` option and expose it to the Namespace to inject a managed `Executor`
* Stop an internal `ExecutorService` manually from the `ConsumerConfiguration.shutdown()`

Polishing
2020-06-25 11:28:32 -04:00
Artem Bilan
c3d696187c Remove SI-core XSD Version from Kafka XSD
JIRA: https://jira.spring.io/browse/INTEXT-122

Remove redundant SI-4.0.xsd

Remove redundant SI-4.0.xsd from `spring.schemas`
2020-06-25 11:28:32 -04:00
Artem Bilan
614308b482 IE-100: Kafka:o-c-a: topic and message-key attrs
JIRA: https://jira.spring.io/browse/INTEXT-100

Add `topic(-expression)` and `message-key(-expression)` attributes to avoid upstream configuration
to specify them in the `MessageHeaders`

Polishing for XSD

Conflicts:
	spring-integration-kafka/src/main/java/org/springframework/integration/kafka/support/KafkaProducerContext.java
	spring-integration-kafka/src/main/java/org/springframework/integration/kafka/support/ProducerConfiguration.java
	spring-integration-kafka/src/main/resources/org/springframework/integration/config/xml/spring-integration-kafka-1.0.xsd
	spring-integration-kafka/src/test/java/org/springframework/integration/kafka/config/xml/KafkaOutboundAdapterParserTests.java

INTEXT-100: Add `Assert.notNull(this.evaluationContext);`

INTEXT-100: Fix parser potential NPE

INTEXT-100: Add `KafkaHeaders`

Merge branch 'INTEXT-100-1' of ..\spring-integration-extensions into INTEXT-100

Conflicts:
	src/main/java/org/springframework/integration/kafka/outbound/KafkaProducerMessageHandler.java
	src/main/java/org/springframework/integration/kafka/support/KafkaProducerContext.java
	src/main/java/org/springframework/integration/kafka/support/ProducerConfiguration.java
	src/test/java/org/springframework/integration/kafka/config/xml/KafkaOutboundAdapterParserTests.java

* Polishing according the rebase to `master`
* Polishing for the `KafkaRunning` Rule to use `ZkClient` and its `getAllBrokersInCluster`
* Add a note to the `README.md`

Addressing PR comments

Polishing

- Minor doc polish + change tabs to spaces in code
- Enhance test to include expressions
2020-06-25 11:28:31 -04:00
Gary Russell
0e2808c014 INTEXT-121 Add SmartLifecycle to ProducerContext
JIRA: https://jira.spring.io/browse/INTEXT-121

When using `async` producers, the buffered messages need to be flushed.

Previously, when the context was stopped, such messages were lost.

- Implement `SmartLifecyle` in the producer context and propagate the `stop()` to the underlying producer(s).
- Remove unused attributes from the consumer parser.
- Add a test case to show the buffered message is received after closing the producer.
- Add KafkaRunning JUnit `@Rule`

Add KafkaRunning Rule to Parser Tests

Polishing
2020-06-25 11:28:31 -04:00
Gary Russell
503ce78395 INT-3570 Core 4.0 Schema Work Around
JIRA: https://jira.spring.io/browse/INT-3570

In 4.1 we removed the 'old' schemas to reduce clutter. However certain
extensions such as kafka import the 4.0 schema which is no longer on
the classpath when using Spring Integration 4.1 when there is no internet
connection.

INT-3570 states that we should restore the 4.0 core schema and mapping
to resolve this issue. In the meantime, this work around adds the schema
to the kafka jar.

It should be reverted when INT-3570 is released in Spring Integration 4.1.1.
2020-06-25 11:28:31 -04:00