Commit Graph

10251 Commits

Author SHA1 Message Date
Marius Bogoevici
4ff25fd894 Prevent Delay on Container Shutdown
Prevent the KafkaMessageListenerContainer from blocking during shutdown

If the RingBufferProcessor used by the KafkaMessageListenerContainer blocks during
processing, it may be prevented from handling the onConsume() notfication which is
the shutdown indicator. Thus, the stopping of the component may be effectively
delayed.

To solve this, the processing task of the RingBufferProcessor is wrapped in a
cancelable task that is managed by one of the container components, and canceled
on shutdown, allowing for the interruption of the processing thread. Subsequently,
all messages cached by the ringbuffer are discarded, without being processed or
acknowdledged.

Additionally, an option for acknowledging processed messages on success only is
added. This allows the component to run continuously and advance even in the case
of sporadic errors, but to resume from the last successfully processed message.

Polishing
2020-06-25 11:28:43 -04:00
Marius Bogoevici
d6f895977a Add header routing setting to KafkaOutboundChannelAdapter
Addressing PR comments

Simple polishing
2020-06-25 11:28:43 -04:00
Artem Bilan
ba96e7ce71 GH-84, GH-69 Improve Partitioner deprecation note
Fixes GH-84 (https://github.com/spring-projects/spring-integration-kafka/issues/84)
Fixes GH-69 (https://github.com/spring-projects/spring-integration-kafka/issues/69)

* The deprecation for the `partitioner` option hasn't mentioned the `partition-id` (`partition-id-expression`) option.
* Add built-in conversion for the `String <-> byte[]` to avoid serialization for Strings
* Expose `charset` option to configure `String <-> byte[]` conversion.
* Fix `deprecation` message for the `KafkaConsumerContextParser`

Extract `StringBytesConverter`
2020-06-25 11:28:42 -04:00
Artem Bilan
0f756cc1ec INTEXT-139: Deprecate High Level Consumer Adapter
JIRA: https://jira.spring.io/browse/INTEXT-139

Revert removal for test and deprecate them
2020-06-25 11:28:42 -04:00
Artem Bilan
28aca5332e INTEXT-206: Don't create extra consumers
JIRA: https://jira.spring.io/browse/INTEXT-206

The previous logic in the `ConcurrentMessageListenerDispatcher` create exactly `consumers`
number of `QueueingMessageListenerInvoker`, although we use only the `partitions.size()`.

Fix the logic to the `this.consumers = Math.min(partitions.size(), consumers);` to create maximum
consumers according to the partitions count.
2020-06-25 11:28:42 -04:00
Marius Bogoevici
464ca70aa6 Add Support for ProducerListener
Introduces the concept of ProducerListener, that can be injected in a ProducerContext and receive notifications when a message has been acknowledged or rejected.

While the Kafka API currently supports providing a Callback, it requires the creation of a distinct instance for receiving contextual information about the message that has been sent or rejected. This allows the use of the Callback mechanism with an injectable ProducerListener strategy.

Polishing and Callback Integration Test
2020-06-25 11:28:42 -04:00
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