Commit Graph

10204 Commits

Author SHA1 Message Date
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
Ilayaperumal Gopinathan
e64d2ac0c8 Add StringDecoder for kafka messages
- Add StringDecoder for decoding kafka key/value messages

Refactor StringDecoder
2020-06-25 11:28:31 -04:00
Ilayaperumal Gopinathan
896d2c43f4 INTEXT-111: Allow PP for Kafka producer context
JIRA: https://jira.spring.io/browse/INTEXT-111

 - Remove hard coded names for bean names at the producer context parser
 - Fix and update tests
 - Remove the use of `BeanFactory` to get the producerConfigurations in
KakfaProducerContext and use setter to set the producerConfigurations
 - Add logic to send the message from producer configuration when there
is no header specified for the topic and single producer configuration
is used.

Add tests to verify placeholder values

Fix code review comment and formatting

Polishing code style.

Add `KafkaProducerContext#theProducerConfiguration` for single `producerConfigurations` entry to avoid iterators
2020-06-25 11:28:31 -04:00
Ilayaperumal Gopinathan
94585fe03b Kafka: PP for consumer context bean
JIRA: https://jira.spring.io/browse/INTEXT-112
https://jira.spring.io/browse/INTEXT-111

 - Avoid using hardcoded bean names for consumer context
 - Remove Integer value topic streams count, instead use string value
   - This will allow placeholder values to be used for `streams` attribute
 - Set `group-id` as a bean name for consumer configuration bean only if
   the group id is specified explicitly. This will allow placeholder values
   not being used as a bean name.
 - Add test cases to verify multiple consumer configurations within the
   same consumer context.

Set consumerConfigurations as propertyValue

Better handling of consumerConfigurations

 - Add getConsumerConfiguration(String groupId) in KafkaConsumerContext
   - Fix tests
 - Add additional test case to check multi consumer contexts

Fix getConsumerConfiguration(groupId)

Polishing
2020-06-25 11:28:30 -04:00
Ilayaperumal Gopinathan
1829bd879f Make ConsumerContext disposable
- This will allow shutting down the consumer connector for the consumer
configuration when the associated context no longer exists.
2020-06-25 11:28:30 -04:00
Artem Bilan
bacf8d2ceb Kafka-GH-92: Allow PP for the <topic-filter>
Fixes https://github.com/spring-projects/spring-integration-extensions/issues/92
2020-06-25 11:28:30 -04:00
Soby Chacko
999878f048 INTEXT-104: Kafka: order for o-channel-adapter
JIRA: https://jira.spring.io/browse/INTEXT-104

`order` attribute now honored if kafka outbound adapter is connected to a subscribable channel
unit tests and samples are updated

Polishing: use `<xsd:attributeGroup ref="integration:channelAdapterAttributes"/>` for adapter tags to cover `SmartLifecycle` options.
2020-06-25 11:28:30 -04:00
Soby Chacko
e22a90ea1f INTEXT-110: Update Kafka version to 0.8.1.1
JIRA: https://jira.spring.io/browse/INTEXT-110

Perform the necessary API Changes (Partioner interface in Kafka is now non-genericized for Keys - concrete Object is the new type for Key)
Unit test updates for an internal Kafka class (MessageMetadata)
Updates for the samples Kafka project to use the new M2 snapshot, Spring 4.0 Messaging changes, other build related minor changes, etc.
2020-06-25 11:28:30 -04:00
Artem Bilan
58ff34d83b Kafka: KCCtx: return null if consumedData.isEmpty
Fixes: https://github.com/spring-projects/spring-integration-extensions/issues/68
2020-06-25 11:28:29 -04:00
Jonathan Pearlin
fb40e521c7 INTEXT-106: Update to spring-integration 4.0
JIRA: https://jira.spring.io/browse/INTEXT-106

* Upgrade to SI 4.0 and other libs
* Upgrade to Gradle 1.12
* Polisihng for `build.gradle`
* Fix compile warnings
2020-06-25 11:28:29 -04:00
Rajasekar Elango
c52be66a1c INTEXT-92 Kafka: Add support for specifying any producer/consumer property
* Update README.md for producer and consumer properties usage
2020-06-25 11:28:29 -04:00
Rajasekar Elango
d226b7c3c5 INTEXT-77 Add Kafka topic filter support for producer + consumer
* Add tests
* Add samples
* Update readme

Jira: https://jira.springsource.org/browse/INTEXT-77
2020-06-25 11:28:29 -04:00
Soby Chacko
94734e4ca3 INTEXT-84 Kafka: Enhance Avro serialization support 2020-06-25 11:28:29 -04:00
Gunnar Hillert
af9440315c INTEXT-81 Add unit tests 2020-06-25 11:28:28 -04:00
Kevin Eustice
6993b73041 INTEXT-81 Fixing bug in decoding message streams
* adding a null check on the key decoder

https://jira.springsource.org/browse/INTEXT-81
2020-06-25 11:28:28 -04:00
Gunnar Hillert
bea8c7cc86 Moved Kafka Test Context Files 2020-06-25 11:28:28 -04:00
Gunnar Hillert
0b20c8dfdb INTEXT-44 - Polishing
* Upgrade to Gradle 1.6
* Upgrade Sonar plugin to SonarRunner
* Upgrade a few dependencies (e.g. JUnit, Spring Integration)
* Remove deprecations (e.g. JUnit)
* Convert spaces to tabs
* Add author tags
* Add @since
2020-06-25 11:28:28 -04:00
Soby Chacko
9e626cb18b INTEXT-44 - Add Kafka Support
* Add Inbound adapter
* Add Outbound adapter
* Add serialization
* Initial Documentation
* Add unit tests
* Add async producer
* Support Kafka 0.8
* Add Kafka Sample

See: https://jira.springsource.org/browse/INTEXT-44
2020-06-25 11:28:27 -04:00
Artem Bilan
5d7f0d2d1c Fix RedisQueueMessageDrEndpointTests for Java 14 2020-06-24 12:43:12 -04:00
Artem Bilan
6a3bea5a64 Add keepAlive(true) to testing Redis CF 2020-06-24 11:58:09 -04:00
Artem Bilan
94956859a2 Fix RedisAvailableRule for the proper evaluate
* Fix `RedisQueueMessageDrivenEndpointTests` for missed options
and for proper stop when the polling from the test queue is over
2020-06-23 16:27:45 -04:00
Artem Bilan
9367d7f4de Fix MessagingGateway for reactive reply type
* Upgrade dependencies to be ready for release
2020-06-23 14:26:11 -04:00
Artem Bilan
3bb445e133 Fix deprecations from Reactor 2020-06-22 13:32:06 -04:00
Artem Bilan
498f42d480 Fix deprecations from SF
* Remove `whitelist` words
* Resolve Sonar smells
* Add `await()` for FTP file removal test: looks like this operation may fail under the stress build
2020-06-19 12:07:58 -04:00
Artem Bilan
3a9ae217b8 Fix UDP tests to rely on a random port
* Iterate over addresses in NI for a real one

* Use `0` for `ackPort`

* Use real `InetAddress` from the `NetworkInterface`
2020-06-18 16:30:59 -04:00
Filip Hrisafov
9ad348b75f Log attempting to receive email under debug level instead of info (#3312) 2020-06-18 12:06:00 -04:00
Artem Bilan
b4a82eb078 Resolve deprecations for MulticastSocket
* Use new `joinGroup(SocketAddress, NetworkInterface)` API
* Resolve `NetworkInterface` in UDP components as
`getByInetAddress(InetAddress.getByName(localAddress))`
* join group as `socket.joinGroup(new InetSocketAddress(this.group, 0), null);`
* Fix `SocketTestUtils.chooseANic()` to select a real `NetworkInterface`
bound to a real IP address
* Fix `MulticastRule` to populate a `multicast.local.address` against a
host name for the network interface not an interface logical name
2020-06-18 11:05:41 -04:00
Artem Bilan
3f5aba2cb9 Support Java 14 (#3310)
* Support Java 14

* Provide changes to avoid deprecated Java API
and have a compatibility back to Java 8
* Change affected test classes to JUnit 5 whenever it is possible
* Ignore/Disable some TCP/IP tests which don't pass on Java 14

* Fix (some) TCP tests on JRE 14

* Fix SSL Handshake test - client side handshake is successful with java 14

- change the badClient cert to a badServer cert to force an error on the client side

Co-authored-by: artembilan <raven666>
Co-authored-by: Gary Russell <grussell@pivotal.io>
2020-06-17 14:00:06 -04:00
astrubel
b0cd0156c7 GH-3307: Retry TransTimedEx in LockRepo.acquire
Fixes https://github.com/spring-projects/spring-integration/issues/3307

The `DefaultLockRepository.acquire()` is transactional method and
can fail with the `TransactionTimedOutException`.
When we call `JdbcLock.lock()`, we expect an attempt until we really obtain a lock.

* Treat a `TransactionTimedOutException` as a `TransientDataAccessException` and 
therefore retry a locking attempt logic

**Cherry-pick to 5.3.x, 5.2.x & 4.3.x**
2020-06-16 10:18:41 -04:00
DEEPAK GUNASEKARAN
7cefd53e10 GH-3092: Refactor (S)FTP outbound specs, handlers
Fixes https://github.com/spring-projects/spring-integration/issues/3092
2020-06-15 16:27:24 -04:00
Artem Bilan
2419c03b25 Replace whitelist with allowlist 2020-06-15 14:20:51 -04:00
Gary Russell
7ec1f5cc4b GH-3299: Fix client connectionId for TCP/NIO
Resolves https://github.com/spring-projects/spring-integration/issues/3299

Connect before creating the `TcpNioConnection` object and publishing the
`TcpConnectionOpenEvent`.

This was a regression caused by supporting connect timout; which moved
the connect to after the object was created and event published, causing
the `connectionId` to start with `unknown`.

**cherry-pick to 5.3.x, 5.2.x**
2020-06-10 09:42:51 -04:00
artembilan
3499cd615a Code clean up for JacksonJsonUtils
* Mention `trustedPackages` in the `redis.adoc`

**Cherry-pick to 5.3.x, 5.2.x, 5.1.x & 4.3.x**
2020-06-09 14:49:25 -04:00
astrubel
02f0c10c80 GH-3294: Retry JdbcLock.unlock for TransDataAccEx
Fixes https://github.com/spring-projects/spring-integration/issues/3294

A `DeadlockLoserDataAccessException` occurs at `JdbcLockRegistry$JdbcLock.unlock()` - 
better to retry like in the `lock()`

**Cherry-pick to 5.3.x, 5.2.x, 5.1.x & 4.3.x**
2020-06-09 13:27:32 -04:00
artembilan
b436cbecc5 Fix NPE for component name after FactoryBeans
SO: https://stackoverflow.com/questions/62190244/spring-integration-upgrade-from-5-2-x-to-5-3-problem

When the component is populated to the application context via `FactoryBean`,
all its `BeanFactory` callbacks should be propagated from that `FactoryBean` -
only lifecycle control for this component we have through its `FactoryBean`

**Cherry-pick to 5.3.x**
2020-06-09 11:05:17 -04:00
Gary Russell
6e78569c00 GH-2736: TCP Async GW - Fix async check
Checking for NIO cannot be done in `onInit()` because the factory is
not yet started.

**cherry-pick to 5.3.x**
2020-06-02 11:17:10 -04:00
Artem Bilan
ef939a09a4 GH-3283: HTTP Inbound handle SpEL errors (#3289)
* GH-3283: HTTP Inbound handle SpEL errors

Fixes https://github.com/spring-projects/spring-integration/issues/3283

* Process all the request message preparation exceptions
in the provided error channel to let target application
to make a decision about an appropriate HTTP status instead of
default 500 Server Error

* * Rephrase `ResponseStatusException` doc in the http.adoc

Co-authored-by: Gary Russell <grussell@vmware.com>

Co-authored-by: Gary Russell <grussell@vmware.com>
2020-05-28 11:47:15 -04:00
Artem Bilan
5bd6278fcb Fix new sonar smells 2020-05-28 09:56:39 -04:00
Artem Bilan
b8e2dfe4e1 GH-3280: NullChannel as reply for void gateways (#3292)
* GH-3280: NullChannel as reply for void gateways

Fixes https://github.com/spring-projects/spring-integration/issues/3280

To properly support a one-way gateway (`void` return type), it is
better to ignore any possible replies from downstream instead of
unexpected `no output-channel or replyChannel header available`
error

* Populate a `nullChannel` into a `replyChannel` header
for `void` gateway methods when `replyChannel` is not set explicitly
* Remove redundant `GatewayProxyFactoryBean.PARSER` in favor of
similar `EXPRESSION_PARSER` in the super class
* Test and document the feature

* * Fix language in the `whats-new.adoc`

Co-authored-by: Gary Russell <grussell@vmware.com>

* * Fix language in gateway.adoc

Co-authored-by: Gary Russell <grussell@vmware.com>

Co-authored-by: Gary Russell <grussell@vmware.com>
2020-05-27 16:10:05 -04:00
Artem Bilan
e98169146b GH-3288: Add Kotlin DSL transform(Transformer)
Fixes https://github.com/spring-projects/spring-integration/issues/3288

* For better end-user experience with Kotlin DSL and get a gain from
existing `Transformer` implementations add a `transform(Transformer)`
EI-method into the `KotlinIntegrationFlowDefinition`
* Also add `filter(MessageSelector)` for any out-of-the-box `MessageSelector`

**Cherry-pick to 5.3.x**
2020-05-27 13:39:54 -04:00
Artem Bilan
8d1dd0b68d Some docs clean up 2020-05-27 12:21:24 -04:00
Artem Bilan
8ba27f6e60 Move 5.3 changes to history 2020-05-26 16:54:15 -04:00