) {
29 |
30 | fun send(toSend: String, key: Int) {
31 | template.send("topic1", key, toSend)
32 | }
33 |
34 | }
35 | // end::startedNoBootSender[]
36 |
--------------------------------------------------------------------------------
/spring-kafka-docs/src/main/resources/logback.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
6 |
7 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/spring-kafka-test/src/main/java/org/springframework/kafka/test/assertj/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Provides a class for assertj conditions.
3 | */
4 | @org.jspecify.annotations.NullMarked
5 | package org.springframework.kafka.test.assertj;
6 |
--------------------------------------------------------------------------------
/spring-kafka-test/src/main/java/org/springframework/kafka/test/condition/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Provides classes for JUnit5 conditions.
3 | */
4 | @org.jspecify.annotations.NullMarked
5 | package org.springframework.kafka.test.condition;
6 |
--------------------------------------------------------------------------------
/spring-kafka-test/src/main/java/org/springframework/kafka/test/context/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Provides classes for EmbeddedKafka context customization.
3 | */
4 | @org.jspecify.annotations.NullMarked
5 | package org.springframework.kafka.test.context;
6 |
--------------------------------------------------------------------------------
/spring-kafka-test/src/main/java/org/springframework/kafka/test/core/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * core package for spring-kafka-test module.
3 | */
4 | @org.jspecify.annotations.NullMarked
5 | package org.springframework.kafka.test.core;
6 |
--------------------------------------------------------------------------------
/spring-kafka-test/src/main/java/org/springframework/kafka/test/hamcrest/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Provides hamcrest matchers.
3 | */
4 | @org.jspecify.annotations.NullMarked
5 | package org.springframework.kafka.test.hamcrest;
6 |
--------------------------------------------------------------------------------
/spring-kafka-test/src/main/java/org/springframework/kafka/test/junit/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Provides JUnit specific extensions in spring-kafka-test.
3 | */
4 | @org.jspecify.annotations.NullMarked
5 | package org.springframework.kafka.test.junit;
6 |
--------------------------------------------------------------------------------
/spring-kafka-test/src/main/java/org/springframework/kafka/test/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Provides top-level API for EmbeddedKafka.
3 | */
4 | @org.jspecify.annotations.NullMarked
5 | package org.springframework.kafka.test;
6 |
--------------------------------------------------------------------------------
/spring-kafka-test/src/main/java/org/springframework/kafka/test/rule/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Provides JUnit rules.
3 | */
4 | @org.jspecify.annotations.NullMarked
5 | package org.springframework.kafka.test.rule;
6 |
--------------------------------------------------------------------------------
/spring-kafka-test/src/main/java/org/springframework/kafka/test/utils/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Utils package.
3 | */
4 | @org.jspecify.annotations.NullMarked
5 | package org.springframework.kafka.test.utils;
6 |
--------------------------------------------------------------------------------
/spring-kafka-test/src/main/resources/META-INF/services/org.junit.platform.launcher.TestExecutionListener:
--------------------------------------------------------------------------------
1 | org.springframework.kafka.test.junit.GlobalEmbeddedKafkaTestExecutionListener
2 |
--------------------------------------------------------------------------------
/spring-kafka-test/src/main/resources/META-INF/spring.factories:
--------------------------------------------------------------------------------
1 | # Spring Test ContextCustomizerFactories
2 | org.springframework.test.context.ContextCustomizerFactory=\
3 | org.springframework.kafka.test.context.EmbeddedKafkaContextCustomizerFactory
4 |
--------------------------------------------------------------------------------
/spring-kafka-test/src/test/java/org/springframework/kafka/test/condition/WithSpringTestContextTests.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021-2024 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.kafka.test.condition;
18 |
19 | import org.junit.jupiter.api.Test;
20 |
21 | import org.springframework.beans.factory.annotation.Autowired;
22 | import org.springframework.context.annotation.Configuration;
23 | import org.springframework.kafka.test.EmbeddedKafkaBroker;
24 | import org.springframework.kafka.test.context.EmbeddedKafka;
25 | import org.springframework.test.annotation.DirtiesContext;
26 | import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
27 |
28 | import static org.assertj.core.api.Assertions.assertThat;
29 |
30 | /**
31 | * @author Gary Russell
32 | * @since 2.7.2
33 | *
34 | */
35 | @SpringJUnitConfig
36 | @EmbeddedKafka
37 | @DirtiesContext
38 | public class WithSpringTestContextTests {
39 |
40 | @Test
41 | void canAutowireBrokerInMethod(@Autowired EmbeddedKafkaBroker broker) {
42 | assertThat(broker).isNotNull();
43 | }
44 |
45 | @Configuration
46 | static class Config {
47 |
48 | }
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/spring-kafka-test/src/test/resources/junit-platform.properties:
--------------------------------------------------------------------------------
1 | spring.kafka.embedded.count=1
2 | spring.kafka.embedded.topics=topic1,topic2
3 |
--------------------------------------------------------------------------------
/spring-kafka-test/src/test/resources/log4j2-test.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/spring-kafka/src/main/java/org/springframework/kafka/annotation/DltHandler.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018-2025 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.kafka.annotation;
18 |
19 |
20 | import java.lang.annotation.Documented;
21 | import java.lang.annotation.ElementType;
22 | import java.lang.annotation.Retention;
23 | import java.lang.annotation.RetentionPolicy;
24 | import java.lang.annotation.Target;
25 |
26 | /**
27 | * Annotation to determine the method that should process the DLT topic message.
28 | * The method can have the same parameters as a {@link KafkaListener} method can have (Message, Acknowledgement, etc).
29 | *
30 | *
31 | * The annotated method must be in the same class as the corresponding {@link KafkaListener} annotation.
32 | *
33 | * @author Tomaz Fernandes
34 | * @since 2.7
35 | *
36 | */
37 | @Target(ElementType.METHOD)
38 | @Retention(RetentionPolicy.RUNTIME)
39 | @Documented
40 | public @interface DltHandler {
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/spring-kafka/src/main/java/org/springframework/kafka/annotation/KafkaListenerConfigurationSelector.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.kafka.annotation;
18 |
19 | import org.springframework.context.annotation.DeferredImportSelector;
20 | import org.springframework.core.annotation.Order;
21 | import org.springframework.core.type.AnnotationMetadata;
22 |
23 | /**
24 | * A {@link DeferredImportSelector} implementation with the lowest order to import a
25 | * {@link KafkaBootstrapConfiguration} as late as possible.
26 | *
27 | * @author Artem Bilan
28 | *
29 | * @since 2.3
30 | */
31 | @Order
32 | public class KafkaListenerConfigurationSelector implements DeferredImportSelector {
33 |
34 | @Override
35 | public String[] selectImports(AnnotationMetadata importingClassMetadata) {
36 | return new String[] { KafkaBootstrapConfiguration.class.getName() };
37 | }
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/spring-kafka/src/main/java/org/springframework/kafka/annotation/KafkaListeners.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016-2019 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.kafka.annotation;
18 |
19 | import java.lang.annotation.Documented;
20 | import java.lang.annotation.ElementType;
21 | import java.lang.annotation.Retention;
22 | import java.lang.annotation.RetentionPolicy;
23 | import java.lang.annotation.Target;
24 |
25 | /**
26 | * Container annotation that aggregates several {@link KafkaListener} annotations.
27 | *
28 | * Can be used natively, declaring several nested {@link KafkaListener} annotations.
29 | * Can also be used in conjunction with Java 8's support for repeatable annotations,
30 | * where {@link KafkaListener} can simply be declared several times on the same method
31 | * (or class), implicitly generating this container annotation.
32 | *
33 | * @author Gary Russell
34 | *
35 | * @see KafkaListener
36 | */
37 | @Target({ ElementType.TYPE, ElementType.METHOD, ElementType.ANNOTATION_TYPE })
38 | @Retention(RetentionPolicy.RUNTIME)
39 | @Documented
40 | public @interface KafkaListeners {
41 |
42 | KafkaListener[] value();
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/spring-kafka/src/main/java/org/springframework/kafka/annotation/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Package for kafka annotations
3 | */
4 | @org.jspecify.annotations.NullMarked
5 | package org.springframework.kafka.annotation;
6 |
--------------------------------------------------------------------------------
/spring-kafka/src/main/java/org/springframework/kafka/aot/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Provides classes to support Spring AOT.
3 | */
4 | @org.jspecify.annotations.NullMarked
5 | package org.springframework.kafka.aot;
6 |
--------------------------------------------------------------------------------
/spring-kafka/src/main/java/org/springframework/kafka/config/ContainerCustomizer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.kafka.config;
18 |
19 | import org.springframework.kafka.listener.AbstractMessageListenerContainer;
20 |
21 | /**
22 | * Called by the container factory after the container is created and configured.
23 | *
24 | * @param the key type.
25 | * @param the value type.
26 | * @param the container type.
27 | *
28 | * @author Gary Russell
29 | * @since 2.3.4
30 | *
31 | */
32 | @FunctionalInterface
33 | public interface ContainerCustomizer> {
34 |
35 | /**
36 | * Configure the container.
37 | * @param container the container.
38 | */
39 | void configure(C container);
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/spring-kafka/src/main/java/org/springframework/kafka/config/KafkaStreamsInfrastructureCustomizer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.kafka.config;
18 |
19 | import org.apache.kafka.streams.StreamsBuilder;
20 | import org.apache.kafka.streams.Topology;
21 |
22 | /**
23 | * A customizer for infrastructure components such as the {@code StreamsBuilder} and
24 | * {@code Topology}. It can be provided to the {@link StreamsBuilderFactoryBean} which
25 | * will apply the changes before creating the stream.
26 | *
27 | * @author Gary Russell
28 | * @since 2.4.1
29 | *
30 | */
31 | public interface KafkaStreamsInfrastructureCustomizer {
32 |
33 | /**
34 | * Configure the builder.
35 | * @param builder the builder.
36 | */
37 | default void configureBuilder(StreamsBuilder builder) {
38 | // no-op
39 | }
40 |
41 | /**
42 | * Configure the topology.
43 | * @param topology the topology
44 | */
45 | default void configureTopology(Topology topology) {
46 | // no-op
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/spring-kafka/src/main/java/org/springframework/kafka/config/StreamsBuilderFactoryBeanConfigurer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.kafka.config;
18 |
19 | import org.springframework.core.Ordered;
20 |
21 | /**
22 | * A configurer for {@link StreamsBuilderFactoryBean}. Applied, in order, to the single
23 | * {@link StreamsBuilderFactoryBean} configured by the framework. Invoked after the bean
24 | * is created and before it is started. Default order is 0.
25 | *
26 | * @author Gary Russell
27 | * @since 2.6.7
28 | *
29 | */
30 | @FunctionalInterface
31 | public interface StreamsBuilderFactoryBeanConfigurer extends Ordered {
32 |
33 | /**
34 | * Configure the factory bean.
35 | * @param factoryBean the factory bean.
36 | */
37 | void configure(StreamsBuilderFactoryBean factoryBean);
38 |
39 | @Override
40 | default int getOrder() {
41 | return 0;
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/spring-kafka/src/main/java/org/springframework/kafka/config/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Package for kafka configuration
3 | */
4 | @org.jspecify.annotations.NullMarked
5 | package org.springframework.kafka.config;
6 |
--------------------------------------------------------------------------------
/spring-kafka/src/main/java/org/springframework/kafka/core/CleanupConfig.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018-2019 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.kafka.core;
18 |
19 | /**
20 | * Specifies time of {@link org.apache.kafka.streams.KafkaStreams#cleanUp()} execution.
21 | *
22 | * @author Pawel Szymczyk
23 | */
24 | public class CleanupConfig {
25 |
26 | private final boolean onStart;
27 |
28 | private final boolean onStop;
29 |
30 | public CleanupConfig() {
31 | this(false, false);
32 | }
33 |
34 | public CleanupConfig(boolean onStart, boolean onStop) {
35 | this.onStart = onStart;
36 | this.onStop = onStop;
37 | }
38 |
39 | public boolean cleanupOnStart() {
40 | return this.onStart;
41 | }
42 |
43 | public boolean cleanupOnStop() {
44 | return this.onStop;
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/spring-kafka/src/main/java/org/springframework/kafka/core/ConsumerPostProcessor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.kafka.core;
18 |
19 | import java.util.function.Function;
20 |
21 | import org.apache.kafka.clients.consumer.Consumer;
22 |
23 | /**
24 | * Called by consumer factories to perform post processing on newly created consumers.
25 | *
26 | * @param the key type.
27 | * @param the value type
28 | *
29 | * @author Gary Russell
30 | * @since 2.5.3
31 | *
32 | */
33 | public interface ConsumerPostProcessor extends Function, Consumer> {
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/spring-kafka/src/main/java/org/springframework/kafka/core/ProducerPostProcessor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.kafka.core;
18 |
19 | import java.util.function.Function;
20 |
21 | import org.apache.kafka.clients.producer.Producer;
22 |
23 | /**
24 | * Called by producer factories to perform post processing on newly created producers.
25 | *
26 | * @param the key type.
27 | * @param the value type
28 | *
29 | * @author Gary Russell
30 | * @since 2.5.3
31 | *
32 | */
33 | public interface ProducerPostProcessor extends Function, Producer> {
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/spring-kafka/src/main/java/org/springframework/kafka/core/TransactionIdSuffixStrategy.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016-2025 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.kafka.core;
18 |
19 | import org.jspecify.annotations.Nullable;
20 |
21 | /**
22 | * The strategy for managing transactional producer suffixes.
23 | *
24 | * @author Ilya Starchenko
25 | *
26 | * @since 3.2
27 | */
28 | public interface TransactionIdSuffixStrategy {
29 |
30 | /**
31 | * Acquire the suffix for the transactional producer.
32 | * @param txIdPrefix the transaction id prefix.
33 | * @return the suffix.
34 | */
35 | String acquireSuffix(@Nullable String txIdPrefix);
36 |
37 | /**
38 | * Release the suffix for the transactional producer.
39 | * @param txIdPrefix the transaction id prefix.
40 | * @param suffix the suffix.
41 | */
42 | void releaseSuffix(@Nullable String txIdPrefix, @Nullable String suffix);
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/spring-kafka/src/main/java/org/springframework/kafka/core/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Package for kafka core components
3 | */
4 | @org.jspecify.annotations.NullMarked
5 | package org.springframework.kafka.core;
6 |
--------------------------------------------------------------------------------
/spring-kafka/src/main/java/org/springframework/kafka/core/reactive/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Reactive component for consumer and producer.
3 | */
4 | @org.jspecify.annotations.NullMarked
5 | package org.springframework.kafka.core.reactive;
6 |
--------------------------------------------------------------------------------
/spring-kafka/src/main/java/org/springframework/kafka/event/ConsumerFailedToStartEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018-2019 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.kafka.event;
18 |
19 | /**
20 | * An event published when a consumer fails to start.
21 | *
22 | * @author Gary Russell
23 | * @since 2.3
24 | *
25 | */
26 | public class ConsumerFailedToStartEvent extends KafkaEvent {
27 |
28 | private static final long serialVersionUID = 1L;
29 |
30 | /**
31 | * Construct an instance with the provided source and container.
32 | * @param source the container instance that generated the event.
33 | * @param container the container or the parent container if the container is a child.
34 | */
35 | public ConsumerFailedToStartEvent(Object source, Object container) {
36 | super(source, container);
37 | }
38 |
39 | @Override
40 | public String toString() {
41 | return "ConsumerFailedToStartEvent [source=" + getSource() + "]";
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/spring-kafka/src/main/java/org/springframework/kafka/event/ConsumerRetryAuthSuccessfulEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.kafka.event;
18 |
19 | /**
20 | * An event published when authentication or authorization has been retried successfully.
21 | *
22 | * @author Daniel Gentes
23 | * @since 3.0
24 | *
25 | */
26 | public class ConsumerRetryAuthSuccessfulEvent extends KafkaEvent {
27 |
28 | private static final long serialVersionUID = 1L;
29 |
30 | /**
31 | * Construct an instance with the provided source and container.
32 | * @param source the container instance that generated the event.
33 | * @param container the container or the parent container
34 | * if the container is a child.
35 | */
36 | public ConsumerRetryAuthSuccessfulEvent(Object source, Object container) {
37 | super(source, container);
38 | }
39 |
40 | @Override
41 | public String toString() {
42 | return "ConsumerRetryAuthSuccessfulEvent [source=" + getSource() + "]";
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/spring-kafka/src/main/java/org/springframework/kafka/event/ConsumerStartedEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018-2019 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.kafka.event;
18 |
19 | /**
20 | * An event published when a consumer has started.
21 | *
22 | * @author Gary Russell
23 | * @since 2.3
24 | *
25 | */
26 | public class ConsumerStartedEvent extends KafkaEvent {
27 |
28 | private static final long serialVersionUID = 1L;
29 |
30 | /**
31 | * Construct an instance with the provided source and container.
32 | * @param source the container instance that generated the event.
33 | * @param container the container or the parent container if the container is a child.
34 | */
35 | public ConsumerStartedEvent(Object source, Object container) {
36 | super(source, container);
37 | }
38 |
39 | @Override
40 | public String toString() {
41 | return "ConsumerStartedEvent [source=" + getSource() + "]";
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/spring-kafka/src/main/java/org/springframework/kafka/event/ConsumerStartingEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018-2019 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.kafka.event;
18 |
19 | /**
20 | * An event published when a consumer is initializing.
21 | *
22 | * @author Gary Russell
23 | * @since 2.3
24 | *
25 | */
26 | public class ConsumerStartingEvent extends KafkaEvent {
27 |
28 | private static final long serialVersionUID = 1L;
29 |
30 | /**
31 | * Construct an instance with the provided source and container.
32 | * @param source the container instance that generated the event.
33 | * @param container the container or the parent container if the container is a child.
34 | */
35 | public ConsumerStartingEvent(Object source, Object container) {
36 | super(source, container);
37 | }
38 |
39 | @Override
40 | public String toString() {
41 | return "ConsumerStartingEvent [source=" + getSource() + "]";
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/spring-kafka/src/main/java/org/springframework/kafka/event/ContainerStoppedEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018-2020 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.kafka.event;
18 |
19 | /**
20 | * An event published when a container is stopped.
21 | *
22 | * @author Gary Russell
23 | * @since 2.2
24 | *
25 | */
26 | public class ContainerStoppedEvent extends KafkaEvent {
27 |
28 | private static final long serialVersionUID = 1L;
29 |
30 | /**
31 | * Construct an instance with the provided source and container.
32 | * @param source the container instance that generated the event.
33 | * @param container the container or the parent container if the container is a child.
34 | * @since 2.2.1
35 | */
36 | public ContainerStoppedEvent(Object source, Object container) {
37 | super(source, container);
38 | }
39 |
40 | @Override
41 | public String toString() {
42 | return "ContainerStoppedEvent [source=" + getSource() + "]";
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/spring-kafka/src/main/java/org/springframework/kafka/event/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Application Events.
3 | */
4 | @org.jspecify.annotations.NullMarked
5 | package org.springframework.kafka.event;
6 |
--------------------------------------------------------------------------------
/spring-kafka/src/main/java/org/springframework/kafka/listener/ConsumerAwareRecordRecoverer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021-2025 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.kafka.listener;
18 |
19 | import org.apache.kafka.clients.consumer.Consumer;
20 | import org.apache.kafka.clients.consumer.ConsumerRecord;
21 | import org.jspecify.annotations.Nullable;
22 |
23 | /**
24 | * A {@link ConsumerRecordRecoverer} that supports getting a reference to the
25 | * {@link Consumer}.
26 | *
27 | * @author Gary Russell
28 | * @since 2.7
29 | *
30 | */
31 | @FunctionalInterface
32 | public interface ConsumerAwareRecordRecoverer extends ConsumerRecordRecoverer {
33 |
34 | @Override
35 | default void accept(ConsumerRecord, ?> record, Exception exception) {
36 | accept(record, null, exception);
37 | }
38 |
39 | /**
40 | * Recover the record.
41 | * @param record the record.
42 | * @param consumer the consumer.
43 | * @param exception the exception.
44 | * @since 2.7
45 | */
46 | void accept(ConsumerRecord, ?> record, @Nullable Consumer, ?> consumer, @Nullable Exception exception);
47 |
48 | }
49 |
--------------------------------------------------------------------------------
/spring-kafka/src/main/java/org/springframework/kafka/listener/ConsumerPauseResumeEventPublisher.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.kafka.listener;
18 |
19 | import java.util.Collection;
20 |
21 | import org.apache.kafka.common.TopicPartition;
22 |
23 | /**
24 | * Objects that can publish consumer pause/resume events.
25 | *
26 | * @author Gary Russell
27 | * @since 2.8.10
28 | *
29 | */
30 | public interface ConsumerPauseResumeEventPublisher {
31 |
32 | /**
33 | * Publish a consumer paused event.
34 | * @param partitions the paused partitions.
35 | * @param reason the reason.
36 | */
37 | void publishConsumerPausedEvent(Collection partitions, String reason);
38 |
39 | /**
40 | * Publish a consumer resumed event.
41 | * @param partitions the resumed partitions.
42 | */
43 | void publishConsumerResumedEvent(Collection partitions);
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/spring-kafka/src/main/java/org/springframework/kafka/listener/ConsumerRecordRecoverer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.kafka.listener;
18 |
19 | import java.util.function.BiConsumer;
20 |
21 | import org.apache.kafka.clients.consumer.ConsumerRecord;
22 |
23 | /**
24 | * A {@link BiConsumer} extension for recovering consumer records.
25 | *
26 | * @author Gary Russell
27 | * @since 2.3
28 | *
29 | */
30 | @FunctionalInterface
31 | public interface ConsumerRecordRecoverer extends BiConsumer, Exception> {
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/spring-kafka/src/main/java/org/springframework/kafka/listener/DefaultBackOffHandler.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022-2025 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.kafka.listener;
18 |
19 | import org.jspecify.annotations.Nullable;
20 |
21 | /**
22 | * Default {@link BackOffHandler}; suspends the thread for the back off. If a container is
23 | * provided, {@link ListenerUtils#stoppableSleep(MessageListenerContainer, long)} is used,
24 | * to terminate the suspension if the container is stopped.
25 | *
26 | * @author Jan Marincek
27 | * @author Gary Russell
28 | * @since 2.9
29 | */
30 | public class DefaultBackOffHandler implements BackOffHandler {
31 |
32 | @Override
33 | public void onNextBackOff(@Nullable MessageListenerContainer container, @Nullable Exception exception, long nextBackOff) {
34 | try {
35 | if (container == null) {
36 | Thread.sleep(nextBackOff);
37 | }
38 | else {
39 | ListenerUtils.stoppableSleep(container, nextBackOff);
40 | }
41 | }
42 | catch (InterruptedException e) {
43 | Thread.currentThread().interrupt();
44 | }
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/spring-kafka/src/main/java/org/springframework/kafka/listener/DefaultListenerMetadata.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017-2025 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.kafka.listener;
18 |
19 | import org.jspecify.annotations.Nullable;
20 |
21 | import org.springframework.util.Assert;
22 |
23 | /**
24 | * Default implementation for {@link ListenerMetadata}.
25 | * @author Francois Rosiere
26 | * @since 2.8.6
27 | */
28 | class DefaultListenerMetadata implements ListenerMetadata {
29 |
30 | private final MessageListenerContainer container;
31 |
32 | DefaultListenerMetadata(MessageListenerContainer container) {
33 | Assert.notNull(container, "'container' must not be null");
34 | this.container = container;
35 | }
36 |
37 | @Override
38 | @Nullable
39 | public String getListenerId() {
40 | return this.container.getListenerId();
41 | }
42 |
43 | @Override
44 | @Nullable
45 | public String getGroupId() {
46 | return this.container.getGroupId();
47 | }
48 |
49 | @Override
50 | @Nullable
51 | public byte[] getListenerInfo() {
52 | return this.container.getListenerInfo();
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/spring-kafka/src/main/java/org/springframework/kafka/listener/DelegatingMessageListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017-2019 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.kafka.listener;
18 |
19 | /**
20 | * Classes implementing this interface allow containers to determine the type of the
21 | * ultimate listener.
22 | *
23 | * @param the type received by the listener.
24 | *
25 | * @author Gary Russell
26 | * @since 2.0
27 | *
28 | */
29 | public interface DelegatingMessageListener {
30 |
31 | /**
32 | * Return the delegate.
33 | * @return the delegate.
34 | */
35 | T getDelegate();
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/spring-kafka/src/main/java/org/springframework/kafka/listener/DeliveryAttemptAware.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.kafka.listener;
18 |
19 | import org.springframework.kafka.support.TopicPartitionOffset;
20 |
21 | /**
22 | * A component implementing this interface can provide the next delivery attempt.
23 | *
24 | * @author Gary Russell
25 | * @since 2.5
26 | *
27 | */
28 | @FunctionalInterface
29 | public interface DeliveryAttemptAware {
30 |
31 | /**
32 | * Return the next delivery attempt for the topic/partition/offset.
33 | * @param topicPartitionOffset the topic/partition/offset.
34 | * @return the next delivery attempt.
35 | */
36 | int deliveryAttempt(TopicPartitionOffset topicPartitionOffset);
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/spring-kafka/src/main/java/org/springframework/kafka/listener/GenericMessageListenerContainer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018-2021 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.kafka.listener;
18 |
19 | /**
20 | * Generic message listener container; adds parameters.
21 | *
22 | * @param the key type.
23 | * @param the value type.
24 | *
25 | * @author Gary Russell
26 | * @since 2.1.3
27 | *
28 | */
29 | public interface GenericMessageListenerContainer extends MessageListenerContainer {
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/spring-kafka/src/main/java/org/springframework/kafka/listener/KafkaBackOffManagerFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018-2021 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.kafka.listener;
18 |
19 | /**
20 | *
21 | * Creates a {@link KafkaBackOffManagerFactory} instance.
22 | *
23 | * @author Tomaz Fernandes
24 | * @since 2.7
25 | * @see KafkaConsumerBackoffManager
26 | */
27 | public interface KafkaBackOffManagerFactory {
28 |
29 | KafkaConsumerBackoffManager create();
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/spring-kafka/src/main/java/org/springframework/kafka/listener/ListenerMetadata.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016-2025 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.kafka.listener;
18 |
19 | import org.jspecify.annotations.Nullable;
20 |
21 | /**
22 | * Metadata associated to a {@link org.springframework.kafka.annotation.KafkaListener}.
23 | *
24 | * @author Francois Rosiere
25 | * @author Gary Russell
26 | * @since 2.8.5
27 | * @see org.springframework.kafka.annotation.KafkaListener
28 | */
29 | public interface ListenerMetadata {
30 |
31 | /**
32 | * Return the listener id.
33 | * @return the listener id.
34 | */
35 | @Nullable
36 | String getListenerId();
37 |
38 | /**
39 | * Return the group id.
40 | * @return the group id.
41 | */
42 | @Nullable
43 | String getGroupId();
44 |
45 | /**
46 | * Return the listener info.
47 | * @return the listener info.
48 | */
49 | @Nullable
50 | byte[] getListenerInfo();
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/spring-kafka/src/main/java/org/springframework/kafka/listener/ListenerType.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017-2019 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.kafka.listener;
18 |
19 | /**
20 | * Defines the listener type.
21 | *
22 | * @author Gary Russell
23 | * @since 2.0
24 | *
25 | */
26 | public enum ListenerType {
27 |
28 | /**
29 | * Acknowledging and consumer aware.
30 | */
31 | ACKNOWLEDGING_CONSUMER_AWARE,
32 |
33 | /**
34 | * Consumer aware.
35 | */
36 | CONSUMER_AWARE,
37 |
38 | /**
39 | * Acknowledging.
40 | */
41 | ACKNOWLEDGING,
42 |
43 | /**
44 | * Simple.
45 | */
46 | SIMPLE
47 |
48 | }
49 |
--------------------------------------------------------------------------------
/spring-kafka/src/main/java/org/springframework/kafka/listener/ManualAckListenerErrorHandler.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022-2025 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.kafka.listener;
18 |
19 | import org.apache.kafka.clients.consumer.Consumer;
20 | import org.jspecify.annotations.Nullable;
21 |
22 | import org.springframework.kafka.support.Acknowledgment;
23 | import org.springframework.messaging.Message;
24 |
25 | /**
26 | * A {@link KafkaListenerErrorHandler} that supports manual acks.
27 | *
28 | * @author Gary Russell
29 | * @since 2.9
30 | *
31 | */
32 | @FunctionalInterface
33 | public interface ManualAckListenerErrorHandler extends KafkaListenerErrorHandler {
34 |
35 | @Override
36 | default Object handleError(Message> message, ListenerExecutionFailedException exception) {
37 | throw new UnsupportedOperationException("Adapter should never call this");
38 | }
39 |
40 | @Override
41 | Object handleError(Message> message, ListenerExecutionFailedException exception, @Nullable Consumer, ?> consumer,
42 | @Nullable Acknowledgment ack);
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/spring-kafka/src/main/java/org/springframework/kafka/listener/MessageListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015-2019 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.kafka.listener;
18 |
19 | import org.apache.kafka.clients.consumer.ConsumerRecord;
20 |
21 | /**
22 | * Listener for handling individual incoming Kafka messages.
23 | *
24 | * @param the key type.
25 | * @param the value type.
26 | *
27 | * @author Marius Bogoevici
28 | * @author Gary Russell
29 | */
30 | @FunctionalInterface
31 | public interface MessageListener extends GenericMessageListener> {
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/spring-kafka/src/main/java/org/springframework/kafka/listener/OffsetAndMetadataProvider.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016-2022 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.kafka.listener;
18 |
19 | import org.apache.kafka.clients.consumer.OffsetAndMetadata;
20 |
21 | /**
22 | * Provider for {@link OffsetAndMetadata}. The provider can be used to have more granularity when creating an
23 | * {@link OffsetAndMetadata}. The provider is used for both sync and async commits of the offsets.
24 | *
25 | * @author Francois Rosiere
26 | * @since 2.8.5
27 | * @see org.apache.kafka.clients.consumer.OffsetCommitCallback
28 | */
29 | public interface OffsetAndMetadataProvider {
30 |
31 | /**
32 | * Provide an offset and metadata object for the given listener metadata and offset.
33 | *
34 | * @param listenerMetadata metadata associated to a listener.
35 | * @param offset an offset.
36 | * @return an offset and metadata.
37 | */
38 | OffsetAndMetadata provide(ListenerMetadata listenerMetadata, long offset);
39 | }
40 |
--------------------------------------------------------------------------------
/spring-kafka/src/main/java/org/springframework/kafka/listener/RecordInRetryException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2024-2025 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.kafka.listener;
18 |
19 | import org.jspecify.annotations.Nullable;
20 |
21 | import org.springframework.core.NestedRuntimeException;
22 |
23 | /**
24 | * Internal {@link NestedRuntimeException} that is used as an exception thrown
25 | * when the record is in retry and not yet recovered during error handling.
26 | * This is to prevent the record from being prematurely committed in the middle of a retry.
27 | *
28 | * Intended only for framework use and thus the package-protected access.
29 | *
30 | * @author Soby Chacko
31 | * @since 3.3.0
32 | */
33 | @SuppressWarnings("serial")
34 | class RecordInRetryException extends NestedRuntimeException {
35 |
36 | /**
37 | * Package protected constructor to create an instance with the provided properties.
38 | *
39 | * @param message logging message
40 | * @param cause {@link Throwable}
41 | */
42 | RecordInRetryException(String message, @Nullable Throwable cause) {
43 | super(message, cause);
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/spring-kafka/src/main/java/org/springframework/kafka/listener/RecoveryStrategy.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021-2025 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.kafka.listener;
18 |
19 | import org.apache.kafka.clients.consumer.Consumer;
20 | import org.apache.kafka.clients.consumer.ConsumerRecord;
21 | import org.jspecify.annotations.Nullable;
22 |
23 | /**
24 | * Called to determine whether a record should be skipped.
25 | *
26 | * @author Gary Russell
27 | * @since 2.7
28 | */
29 | @FunctionalInterface
30 | public interface RecoveryStrategy {
31 |
32 | /**
33 | * Return true if the record should be skipped because it was successfully
34 | * recovered.
35 | * @param record the record.
36 | * @param ex the exception.
37 | * @param container the container (or parent if a child container).
38 | * @param consumer the consumer.
39 | * @return true to skip.
40 | * @throws InterruptedException if the thread is interrupted.
41 | */
42 | boolean recovered(ConsumerRecord, ?> record, @Nullable Exception ex, @Nullable MessageListenerContainer container,
43 | @Nullable Consumer, ?> consumer) throws InterruptedException;
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/spring-kafka/src/main/java/org/springframework/kafka/listener/ThreadStateProcessor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016-2021 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.kafka.listener;
18 |
19 | import org.apache.kafka.clients.consumer.Consumer;
20 |
21 | /**
22 | * A general interface for managing thread-bound resources when a {@link Consumer} is
23 | * available.
24 | *
25 | * @author Karol Dowbecki
26 | * @author Gary Russell
27 | * @since 2.8
28 | *
29 | */
30 | public interface ThreadStateProcessor {
31 |
32 | /**
33 | * Call to set up thread-bound resources which will be available for the
34 | * entire duration of enclosed operation involving a {@link Consumer}.
35 | *
36 | * @param consumer the consumer.
37 | */
38 | default void setupThreadState(Consumer, ?> consumer) {
39 | }
40 |
41 | /**
42 | * Call to clear thread-bound resources which were set up in
43 | * {@link #setupThreadState(Consumer)}.
44 | *
45 | * @param consumer the consumer.
46 | */
47 | default void clearThreadState(Consumer, ?> consumer) {
48 | }
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/spring-kafka/src/main/java/org/springframework/kafka/listener/adapter/AsyncRepliesAware.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023-2024 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.kafka.listener.adapter;
18 |
19 | /**
20 | * Message handler adapter implementing this interface can detect {@link HandlerAdapter} async return types.
21 | *
22 | * @author Wang zhiyang
23 | *
24 | * @since 3.2
25 | */
26 | public interface AsyncRepliesAware {
27 |
28 | /**
29 | * Return true if the {@link HandlerAdapter} return type is async.
30 | * @return true for async replies.
31 | * @since 3.2
32 | */
33 | default boolean isAsyncReplies() {
34 | return false;
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/spring-kafka/src/main/java/org/springframework/kafka/listener/adapter/InvocationResult.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018-2025 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.kafka.listener.adapter;
18 |
19 | import org.jspecify.annotations.Nullable;
20 |
21 | import org.springframework.expression.Expression;
22 |
23 | /**
24 | * The result of a method invocation.
25 | * @param result the result.
26 | * @param messageReturnType the message return type.
27 | * @param sendTo the expression about sends topic.
28 | *
29 | * @author Gary Russell
30 | * @since 2.2
31 | */
32 | public record InvocationResult(@Nullable Object result, @Nullable Expression sendTo, boolean messageReturnType) {
33 |
34 | @Override
35 | public String toString() {
36 | return "InvocationResult [result=" + this.result
37 | + ", sendTo=" + (this.sendTo == null ? "null" : this.sendTo.getExpressionString())
38 | + ", messageReturnType=" + this.messageReturnType + "]";
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/spring-kafka/src/main/java/org/springframework/kafka/listener/adapter/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Provides classes for adapting listeners.
3 | */
4 | @org.jspecify.annotations.NullMarked
5 | package org.springframework.kafka.listener.adapter;
6 |
--------------------------------------------------------------------------------
/spring-kafka/src/main/java/org/springframework/kafka/listener/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Package for kafka listeners
3 | */
4 | @org.jspecify.annotations.NullMarked
5 | package org.springframework.kafka.listener;
6 |
--------------------------------------------------------------------------------
/spring-kafka/src/main/java/org/springframework/kafka/mock/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Provides classes to support the use of MockConsumer and MockProducer.
3 | */
4 | @org.jspecify.annotations.NullMarked
5 | package org.springframework.kafka.mock;
6 |
--------------------------------------------------------------------------------
/spring-kafka/src/main/java/org/springframework/kafka/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Base package for kafka
3 | */
4 | @org.jspecify.annotations.NullMarked
5 | package org.springframework.kafka;
6 |
--------------------------------------------------------------------------------
/spring-kafka/src/main/java/org/springframework/kafka/requestreply/KafkaReplyTimeoutException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.kafka.requestreply;
18 |
19 | import org.springframework.kafka.KafkaException;
20 |
21 | /**
22 | * Exception when a reply is not received within a timeout.
23 | *
24 | * @author Gary Russell
25 | * @since 2.3
26 | *
27 | */
28 | public class KafkaReplyTimeoutException extends KafkaException {
29 |
30 | private static final long serialVersionUID = 1L;
31 |
32 | public KafkaReplyTimeoutException(String message) {
33 | super(message);
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/spring-kafka/src/main/java/org/springframework/kafka/requestreply/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Provides classes for request/reply semantics.
3 | */
4 | @org.jspecify.annotations.NullMarked
5 | package org.springframework.kafka.requestreply;
6 |
--------------------------------------------------------------------------------
/spring-kafka/src/main/java/org/springframework/kafka/retrytopic/DltStrategy.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018-2021 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.kafka.retrytopic;
18 |
19 | /**
20 | *
21 | * Strategies for handling DLT processing.
22 | *
23 | * @author Tomaz Fernandes
24 | * @since 2.7
25 | *
26 | */
27 | public enum DltStrategy {
28 |
29 | /**
30 | * Don't create a DLT.
31 | */
32 | NO_DLT,
33 |
34 | /**
35 | * Always send the message back to the DLT for reprocessing in case of failure in
36 | * DLT processing.
37 | */
38 | ALWAYS_RETRY_ON_ERROR,
39 |
40 | /**
41 | * Fail if DLT processing throws an error.
42 | */
43 | FAIL_ON_ERROR
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/spring-kafka/src/main/java/org/springframework/kafka/retrytopic/RetryTopicConstants.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018-2021 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.kafka.retrytopic;
18 |
19 | /**
20 | *
21 | * Constants for the RetryTopic functionality.
22 | *
23 | * @author Tomaz Fernandes
24 | * @since 2.7
25 | *
26 | */
27 | public abstract class RetryTopicConstants {
28 |
29 | /**
30 | * Default suffix for retry topics.
31 | */
32 | public static final String DEFAULT_RETRY_SUFFIX = "-retry";
33 |
34 | /**
35 | * Default suffix for dlt.
36 | */
37 | public static final String DEFAULT_DLT_SUFFIX = "-dlt";
38 |
39 | /**
40 | * Default number of times the message processing should be attempted,
41 | * including the first.
42 | */
43 | public static final int DEFAULT_MAX_ATTEMPTS = 3;
44 |
45 | /**
46 | * Constant to represent that the integer property is not set.
47 | */
48 | public static final int NOT_SET = -1;
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/spring-kafka/src/main/java/org/springframework/kafka/retrytopic/RetryTopicHeaders.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018-2021 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.kafka.retrytopic;
18 |
19 | /**
20 | *
21 | * Contains the headers that will be used in the forwarded messages.
22 | *
23 | * @author Tomaz Fernandes
24 | * @since 2.7
25 | *
26 | */
27 | public abstract class RetryTopicHeaders {
28 |
29 | /**
30 | * The default header for the backoff due timestamp.
31 | */
32 | public static final String DEFAULT_HEADER_BACKOFF_TIMESTAMP = "retry_topic-backoff-timestamp";
33 |
34 | /**
35 | * The default header for the attempts.
36 | */
37 | public static final String DEFAULT_HEADER_ATTEMPTS = "retry_topic-attempts";
38 |
39 | /**
40 | * The default header for the original message's timestamp.
41 | */
42 | public static final String DEFAULT_HEADER_ORIGINAL_TIMESTAMP = "retry_topic-original-timestamp";
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/spring-kafka/src/main/java/org/springframework/kafka/retrytopic/SameIntervalTopicReuseStrategy.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021-2023 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.kafka.retrytopic;
18 |
19 | /**
20 | *
21 | * Strategy for topic reuse when multiple, sequential retries have the same backoff
22 | * interval.
23 | *
24 | *
25 | * It can be used only when the retries that have the same interval are located
26 | * in the end of the retry chain (it cannot be used for retries with the same
27 | * interval in the middle of the retry chain).
28 | *
29 | * @author João Lima
30 | * @since 3.0.4
31 | *
32 | */
33 | public enum SameIntervalTopicReuseStrategy {
34 |
35 | /**
36 | * Uses a single retry topic for sequential attempts with the same interval.
37 | */
38 | SINGLE_TOPIC,
39 |
40 | /**
41 | * Uses one separate topic per retry attempt.
42 | */
43 | MULTIPLE_TOPICS
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/spring-kafka/src/main/java/org/springframework/kafka/retrytopic/TopicSuffixingStrategy.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018-2021 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.kafka.retrytopic;
18 |
19 | /**
20 | *
21 | * Constants for the RetryTopic functionality.
22 | *
23 | * @author Tomaz Fernandes
24 | * @since 2.7
25 | *
26 | */
27 | public enum TopicSuffixingStrategy {
28 |
29 | /**
30 | * Suffixes the topics with their index in the retry topics.
31 | * E.g. my-retry-topic-0, my-retry-topic-1, my-retry-topic-2.
32 | */
33 | SUFFIX_WITH_INDEX_VALUE,
34 |
35 | /**
36 | * Suffixes the topics the delay value for the topic.
37 | * E.g. my-retry-topic-1000, my-retry-topic-2000, my-retry-topic-4000.
38 | */
39 | SUFFIX_WITH_DELAY_VALUE
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/spring-kafka/src/main/java/org/springframework/kafka/retrytopic/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Package for retryable topic handling.
3 | */
4 | @org.jspecify.annotations.NullMarked
5 | package org.springframework.kafka.retrytopic;
6 |
--------------------------------------------------------------------------------
/spring-kafka/src/main/java/org/springframework/kafka/security/jaas/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Provides classes related to jaas.
3 | */
4 | @org.jspecify.annotations.NullMarked
5 | package org.springframework.kafka.security.jaas;
6 |
--------------------------------------------------------------------------------
/spring-kafka/src/main/java/org/springframework/kafka/streams/messaging/MessagingFunction.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.kafka.streams.messaging;
18 |
19 | import org.springframework.messaging.Message;
20 |
21 | /**
22 | * A function that receives a spring-messaging {@link Message} and returns
23 | * a {@link Message}.
24 | *
25 | * @author Gary Russell
26 | * @since 2.3
27 | *
28 | */
29 | @FunctionalInterface
30 | public interface MessagingFunction {
31 |
32 | Message> exchange(Message> message);
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/spring-kafka/src/main/java/org/springframework/kafka/streams/messaging/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Package for classes related to spring-messaging with Kafka Streams.
3 | */
4 | @org.jspecify.annotations.NullMarked
5 | package org.springframework.kafka.streams.messaging;
6 |
--------------------------------------------------------------------------------
/spring-kafka/src/main/java/org/springframework/kafka/streams/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Package for classes related to Kafka Streams.
3 | */
4 | @org.jspecify.annotations.NullMarked
5 | package org.springframework.kafka.streams;
6 |
--------------------------------------------------------------------------------
/spring-kafka/src/main/java/org/springframework/kafka/support/JacksonPresent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017-2025 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.kafka.support;
18 |
19 | import org.jspecify.annotations.Nullable;
20 |
21 | import org.springframework.util.ClassUtils;
22 |
23 | /**
24 | * The utility to check if Jackson JSON processor is present in the classpath.
25 | *
26 | * @author Artem Bilan
27 | * @author Gary Russell
28 | *
29 | * @since 1.3
30 | */
31 | public final class JacksonPresent {
32 |
33 | private static final @Nullable ClassLoader classLoader = ClassUtils.getDefaultClassLoader(); // NOSONAR
34 |
35 | private static final boolean jackson2Present = // NOSONAR
36 | ClassUtils.isPresent("com.fasterxml.jackson.databind.ObjectMapper", classLoader) &&
37 | ClassUtils.isPresent("com.fasterxml.jackson.core.JsonGenerator", classLoader);
38 |
39 | public static boolean isJackson2Present() {
40 | return jackson2Present;
41 | }
42 |
43 | private JacksonPresent() {
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/spring-kafka/src/main/java/org/springframework/kafka/support/KafkaHeaderMapper.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017-2022 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.kafka.support;
18 |
19 | import java.util.Map;
20 |
21 | import org.apache.kafka.common.header.Headers;
22 |
23 | import org.springframework.messaging.MessageHeaders;
24 |
25 | /**
26 | * Header mapper for Apache Kafka.
27 | *
28 | * @author Gary Russell
29 | * @since 1.3
30 | *
31 | */
32 | public interface KafkaHeaderMapper {
33 |
34 | /**
35 | * Map from the given {@link MessageHeaders} to the specified target headers.
36 | * @param headers the abstracted MessageHeaders.
37 | * @param target the native target headers.
38 | */
39 | void fromHeaders(MessageHeaders headers, Headers target);
40 |
41 | /**
42 | * Map from the given native headers to a map of headers for the eventual
43 | * {@link MessageHeaders}.
44 | * @param source the native headers.
45 | * @param target the target headers.
46 | */
47 | void toHeaders(Headers source, Map target);
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/spring-kafka/src/main/java/org/springframework/kafka/support/KafkaNull.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016-2019 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.kafka.support;
18 |
19 | /**
20 | * This class represents NULL Kafka payload.
21 | *
22 | * @author Dariusz Szablinski
23 | * @author Gary Russell
24 | * @since 1.0.3
25 | */
26 | public final class KafkaNull {
27 |
28 | /**
29 | * Instance of KafkaNull.
30 | */
31 | public static final KafkaNull INSTANCE = new KafkaNull();
32 |
33 | private KafkaNull() {
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/spring-kafka/src/main/java/org/springframework/kafka/support/TopicForRetryable.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.kafka.support;
18 |
19 | import org.apache.kafka.clients.admin.NewTopic;
20 |
21 | /**
22 | * Marker to indicate this {@link NewTopic} is for retryable topics; admin will ignore these if
23 | * a regular {@link NewTopic} exist.
24 | *
25 | * @author Gary Russell
26 | * @since 2.8.10
27 | *
28 | */
29 | public class TopicForRetryable extends NewTopic {
30 |
31 | /**
32 | * Create an instance with the provided properties.
33 | * @param topic the topic.
34 | * @param numPartitions the partitions.
35 | * @param replicationFactor the replication factor.
36 | */
37 | public TopicForRetryable(String topic, int numPartitions, short replicationFactor) {
38 | super(topic, numPartitions, replicationFactor);
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/spring-kafka/src/main/java/org/springframework/kafka/support/converter/KafkaMessageHeaders.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016-2019 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.kafka.support.converter;
18 |
19 | import java.util.Map;
20 |
21 | import org.springframework.messaging.MessageHeaders;
22 |
23 | /**
24 | * Overload of message headers configurable for adding id and timestamp headers.
25 | *
26 | * @author Marius Bogoevici
27 | * @author Gary Russell
28 | * @since 1.1
29 | *
30 | */
31 | @SuppressWarnings("serial")
32 | public class KafkaMessageHeaders extends MessageHeaders {
33 |
34 | /**
35 | * Construct headers with or without id and/or timestamp.
36 | * @param generateId true to add an ID header.
37 | * @param generateTimestamp true to add a timestamp header.
38 | */
39 | KafkaMessageHeaders(boolean generateId, boolean generateTimestamp) {
40 | super(null, generateId ? null : ID_VALUE_NONE, generateTimestamp ? null : -1L);
41 | }
42 |
43 | @Override
44 | public Map getRawHeaders() { //NOSONAR - not useless, widening to public
45 | return super.getRawHeaders();
46 | }
47 |
48 | }
49 |
--------------------------------------------------------------------------------
/spring-kafka/src/main/java/org/springframework/kafka/support/converter/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Package for kafka converters
3 | */
4 | @org.jspecify.annotations.NullMarked
5 | package org.springframework.kafka.support.converter;
6 |
--------------------------------------------------------------------------------
/spring-kafka/src/main/java/org/springframework/kafka/support/mapping/ClassMapper.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017-2025 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.kafka.support.mapping;
18 |
19 | import org.apache.kafka.common.header.Headers;
20 | import org.jspecify.annotations.Nullable;
21 |
22 | /**
23 | * Strategy for setting metadata on messages such that one can create the class
24 | * that needs to be instantiated when receiving a message.
25 | *
26 | * @author Mark Pollack
27 | * @author James Carr
28 | * @author Gary Russell
29 | *
30 | * @since 2.1
31 | */
32 | public interface ClassMapper {
33 |
34 | void fromClass(Class> clazz, Headers headers);
35 |
36 | @Nullable
37 | Class> toClass(Headers headers);
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/spring-kafka/src/main/java/org/springframework/kafka/support/mapping/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Provides classes related to type mapping.
3 | */
4 | @org.jspecify.annotations.NullMarked
5 | package org.springframework.kafka.support.mapping;
6 |
--------------------------------------------------------------------------------
/spring-kafka/src/main/java/org/springframework/kafka/support/micrometer/KafkaListenerObservationConvention.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.kafka.support.micrometer;
18 |
19 | import io.micrometer.observation.Observation.Context;
20 | import io.micrometer.observation.ObservationConvention;
21 |
22 | /**
23 | * {@link ObservationConvention} for Kafka listener key values.
24 | *
25 | * @author Gary Russell
26 | * @since 3.0
27 | *
28 | */
29 | public interface KafkaListenerObservationConvention extends ObservationConvention {
30 |
31 | @Override
32 | default boolean supportsContext(Context context) {
33 | return context instanceof KafkaRecordReceiverContext;
34 | }
35 |
36 | @Override
37 | default String getName() {
38 | return "spring.kafka.listener";
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/spring-kafka/src/main/java/org/springframework/kafka/support/micrometer/KafkaTemplateObservationConvention.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.kafka.support.micrometer;
18 |
19 | import io.micrometer.observation.Observation.Context;
20 | import io.micrometer.observation.ObservationConvention;
21 |
22 | /**
23 | * {@link ObservationConvention} for Kafka template key values.
24 | *
25 | * @author Gary Russell
26 | * @since 3.0
27 | *
28 | */
29 | public interface KafkaTemplateObservationConvention extends ObservationConvention {
30 |
31 | @Override
32 | default boolean supportsContext(Context context) {
33 | return context instanceof KafkaRecordSenderContext;
34 | }
35 |
36 | @Override
37 | default String getName() {
38 | return "spring.kafka.template";
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/spring-kafka/src/main/java/org/springframework/kafka/support/micrometer/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Provides classes to support Micrometer.
3 | */
4 | @org.jspecify.annotations.NullMarked
5 | package org.springframework.kafka.support.micrometer;
6 |
--------------------------------------------------------------------------------
/spring-kafka/src/main/java/org/springframework/kafka/support/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Package for kafka support
3 | */
4 | @org.jspecify.annotations.NullMarked
5 | package org.springframework.kafka.support;
6 |
--------------------------------------------------------------------------------
/spring-kafka/src/main/java/org/springframework/kafka/support/serializer/DeserializationExceptionHeader.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.kafka.support.serializer;
18 |
19 | import org.apache.kafka.common.header.internals.RecordHeader;
20 |
21 | /**
22 | * A package-protected header used to contain serialized
23 | * {@link DeserializationException}s. Only headers of this type will be examined for
24 | * deserialization.
25 | *
26 | * @author Gary Russell
27 | * @since 2.9.11
28 | */
29 | class DeserializationExceptionHeader extends RecordHeader {
30 |
31 | /**
32 | * Construct an instance with the provided properties.
33 | * @param key the key.
34 | * @param value the value;
35 | */
36 | DeserializationExceptionHeader(String key, byte[] value) {
37 | super(key, value);
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/spring-kafka/src/main/java/org/springframework/kafka/support/serializer/JsonTypeResolver.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020-2025 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.kafka.support.serializer;
18 |
19 | import com.fasterxml.jackson.databind.JavaType;
20 | import org.apache.kafka.common.header.Headers;
21 | import org.jspecify.annotations.Nullable;
22 |
23 | /**
24 | * Determine the {@link JavaType} from the topic/data/headers.
25 | *
26 | * @author Gary Russell
27 | * @since 2.5.3
28 | *
29 | */
30 | @FunctionalInterface
31 | public interface JsonTypeResolver {
32 |
33 | /**
34 | * Determine the type.
35 | * @param topic the topic.
36 | * @param data the serialized data.
37 | * @param headers the headers.
38 | * @return the type.
39 | */
40 | JavaType resolveType(String topic, byte[] data, @Nullable Headers headers);
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/spring-kafka/src/main/java/org/springframework/kafka/support/serializer/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Provides classes related to Kafka serialization.
3 | */
4 | @org.jspecify.annotations.NullMarked
5 | package org.springframework.kafka.support.serializer;
6 |
--------------------------------------------------------------------------------
/spring-kafka/src/main/java/org/springframework/kafka/transaction/KafkaAwareTransactionManager.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018-2021 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.kafka.transaction;
18 |
19 | import org.springframework.kafka.core.ProducerFactory;
20 | import org.springframework.transaction.PlatformTransactionManager;
21 |
22 | /**
23 | * A transaction manager that can provide a {@link ProducerFactory}.
24 | *
25 | * @param the key type.
26 | * @param the value type.
27 | *
28 | * @author Gary Russell
29 | * @since 2.1.3
30 | *
31 | */
32 | public interface KafkaAwareTransactionManager extends PlatformTransactionManager {
33 |
34 | /**
35 | * Get the producer factory.
36 | * @return the producerFactory
37 | */
38 | ProducerFactory getProducerFactory();
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/spring-kafka/src/main/java/org/springframework/kafka/transaction/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Provides classes related to transactions.
3 | */
4 | @org.jspecify.annotations.NullMarked
5 | package org.springframework.kafka.transaction;
6 |
--------------------------------------------------------------------------------
/spring-kafka/src/main/resources/META-INF/spring/aot.factories:
--------------------------------------------------------------------------------
1 | org.springframework.aot.hint.RuntimeHintsRegistrar=org.springframework.kafka.aot.KafkaRuntimeHints
2 | org.springframework.beans.factory.aot.BeanRegistrationAotProcessor=org.springframework.kafka.aot.KafkaAvroBeanRegistrationAotProcessor
3 |
--------------------------------------------------------------------------------
/spring-kafka/src/test/java/org/springframework/kafka/listener/ErrorHandlingCoverageTests.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017-2024 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.kafka.listener;
18 |
19 | import java.util.Map;
20 |
21 | import org.junit.jupiter.api.Test;
22 |
23 | import static org.assertj.core.api.Assertions.assertThat;
24 |
25 | /**
26 | * @author Gary Russell
27 | * @since 2.9.3
28 | *
29 | */
30 | public class ErrorHandlingCoverageTests {
31 |
32 | @Test
33 | void coverageDefault() {
34 | DefaultErrorHandler eh = new DefaultErrorHandler();
35 | eh.addNotRetryableExceptions(IllegalStateException.class);
36 | eh.setClassifications(Map.of(IllegalArgumentException.class, false), false);
37 | assertThat(eh.removeClassification(IllegalStateException.class)).isNull();
38 | assertThat(eh.removeClassification(IllegalArgumentException.class)).isFalse();
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/spring-kafka/src/test/java/org/springframework/kafka/listener/ManualImmediateNackBatchTests.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.kafka.listener;
18 |
19 | import org.springframework.kafka.listener.ContainerProperties.AckMode;
20 |
21 | /**
22 | * @author Gary Russell
23 | * @since 2.8
24 | *
25 | */
26 | public class ManualImmediateNackBatchTests extends ManualNackBatchTests {
27 |
28 | static {
29 | ackMode = AckMode.MANUAL_IMMEDIATE;
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/spring-kafka/src/test/java/org/springframework/kafka/requestreply/CorrelationKeyTests.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022-2024 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.kafka.requestreply;
18 |
19 | import org.junit.jupiter.api.Test;
20 |
21 | import static org.assertj.core.api.Assertions.assertThat;
22 |
23 | /**
24 | * @author Gary Russell
25 | * @since 2.8.10
26 | *
27 | */
28 | public class CorrelationKeyTests {
29 |
30 | @Test
31 | void asString() {
32 | CorrelationKey key = new CorrelationKey(new byte[16]);
33 | assertThat(key.toString()).isEqualTo("00000000-0000-0000-0000-000000000000");
34 | key = new CorrelationKey(new byte[10]);
35 | assertThat(key.toString()).isEqualTo("00000000000000000000");
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/spring-kafka/src/test/java/org/springframework/kafka/retrytopic/RetryTopicConstantsTests.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018-2024 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.kafka.retrytopic;
18 |
19 | import org.junit.jupiter.api.Test;
20 |
21 | import static org.assertj.core.api.Assertions.assertThat;
22 |
23 | /**
24 | * @author Tomaz Fernandes
25 | * @since 2.7
26 | */
27 | class RetryTopicConstantsTests {
28 |
29 | private static final String DEFAULT_RETRY_SUFFIX = "-retry";
30 |
31 | private static final String DEFAULT_DLT_SUFFIX = "-dlt";
32 |
33 | private static final int DEFAULT_MAX_ATTEMPTS = 3;
34 |
35 | private static final int NOT_SET = -1;
36 |
37 | @Test
38 | public void assertRetryTopicConstants() {
39 | new RetryTopicConstants() { }; // for coverage
40 | assertThat(RetryTopicConstants.DEFAULT_DLT_SUFFIX).isEqualTo(DEFAULT_DLT_SUFFIX);
41 | assertThat(RetryTopicConstants.DEFAULT_RETRY_SUFFIX).isEqualTo(DEFAULT_RETRY_SUFFIX);
42 | assertThat(RetryTopicConstants.DEFAULT_MAX_ATTEMPTS).isEqualTo(DEFAULT_MAX_ATTEMPTS);
43 | assertThat(RetryTopicConstants.NOT_SET).isEqualTo(NOT_SET);
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/spring-kafka/src/test/java/org/springframework/kafka/retrytopic/TestClockUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018-2021 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.kafka.retrytopic;
18 |
19 | import java.time.Clock;
20 | import java.time.Instant;
21 | import java.time.ZoneId;
22 |
23 | /**
24 | * @author tomazlemos
25 | * @since 14/02/21
26 | */
27 | public abstract class TestClockUtils {
28 |
29 | public static Clock CLOCK = Clock.fixed(Instant.ofEpochMilli(325587600000L), ZoneId.systemDefault());
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/spring-kafka/src/test/java/org/springframework/kafka/support/TopicPartitionOffsetTests.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020-2024 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.kafka.support;
18 |
19 | import java.util.Objects;
20 |
21 | import org.apache.kafka.common.TopicPartition;
22 | import org.junit.jupiter.api.Test;
23 |
24 | import org.springframework.kafka.support.TopicPartitionOffset.SeekPosition;
25 |
26 | import static org.assertj.core.api.Assertions.assertThat;
27 |
28 | /**
29 | * @author Gary Russell
30 | * @since 2.3.13
31 | *
32 | */
33 | public class TopicPartitionOffsetTests {
34 |
35 | @Test
36 | void hashCodeTest() {
37 | assertThat(new TopicPartitionOffset("foo", 1, SeekPosition.BEGINNING).hashCode())
38 | .isNotEqualTo(new TopicPartitionOffset("foo", 1, SeekPosition.END).hashCode());
39 | }
40 |
41 | @Test
42 | void hashCodeNPE() {
43 | assertThat(new TopicPartitionOffset("foo", 0).hashCode())
44 | .isEqualTo(Objects.hash(new TopicPartition("foo", 0), null));
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/spring-kafka/src/test/java/org/springframework/kafka/support/serializer/testentities/DummyEntity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016-2019 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.kafka.support.serializer.testentities;
18 |
19 | import java.util.List;
20 | import java.util.Map;
21 | import java.util.Objects;
22 |
23 | /**
24 | * @author Igor Stepanov
25 | */
26 | public class DummyEntity {
27 |
28 | public int intValue;
29 |
30 | public Long longValue;
31 |
32 | public String stringValue;
33 |
34 | public Map> complexStruct;
35 |
36 | @Override
37 | public boolean equals(Object o) {
38 | if (this == o) {
39 | return true;
40 | }
41 | if (o == null || getClass() != o.getClass()) {
42 | return false;
43 | }
44 | DummyEntity that = (DummyEntity) o;
45 | return intValue == that.intValue &&
46 | Objects.equals(longValue, that.longValue) &&
47 | Objects.equals(stringValue, that.stringValue) &&
48 | Objects.equals(complexStruct, that.complexStruct);
49 | }
50 |
51 | @Override
52 | public int hashCode() {
53 | return Objects.hash(intValue, longValue, stringValue, complexStruct);
54 | }
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/spring-kafka/src/test/resources/broker.properties:
--------------------------------------------------------------------------------
1 | delete.topic.enable = false
2 |
--------------------------------------------------------------------------------
/spring-kafka/src/test/resources/jaas-sample-kafka-only.conf:
--------------------------------------------------------------------------------
1 | KafkaClient {
2 | com.sun.security.auth.module.Krb5LoginModule required
3 | useKeyTab=true
4 | storeKey=true
5 | keyTab="/etc/security/keytabs/kafka_client.keytab"
6 | principal="kafka-client-1@EXAMPLE.COM";
7 | };
8 |
--------------------------------------------------------------------------------
/spring-kafka/src/test/resources/log4j2-test.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/src/api/overview.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | This document is the API specification for Spring for Apache Kafka project
4 |
5 |
6 |
7 | For further API reference and developer documentation, see the
8 | Spring
9 | for Apache Kafka reference documentation.
10 | That documentation contains more detailed, developer-targeted
11 | descriptions, with conceptual overviews, definitions of terms,
12 | workarounds, and working code examples.
13 |
14 |
15 |
16 | If you are interested in commercial consultancy, and
17 | support for Spring for Apache Kafka, please visit
18 | https://spring.io/
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/src/checkstyle/checkstyle-header.txt:
--------------------------------------------------------------------------------
1 | ^\Q/*\E$
2 | ^\Q * Copyright \E20\d\d(\-20\d\d)?\Q the original author or authors.\E$
3 | ^\Q *\E$
4 | ^\Q * Licensed under the Apache License, Version 2.0 (the "License");\E$
5 | ^\Q * you may not use this file except in compliance with the License.\E$
6 | ^\Q * You may obtain a copy of the License at\E$
7 | ^\Q *\E$
8 | ^\Q * https://www.apache.org/licenses/LICENSE-2.0\E$
9 | ^\Q *\E$
10 | ^\Q * Unless required by applicable law or agreed to in writing, software\E$
11 | ^\Q * distributed under the License is distributed on an "AS IS" BASIS,\E$
12 | ^\Q * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\E$
13 | ^\Q * See the License for the specific language governing permissions and\E$
14 | ^\Q * limitations under the License.\E$
15 | ^\Q */\E$
16 | ^$
17 | ^.*$
18 |
--------------------------------------------------------------------------------
/src/checkstyle/checkstyle-suppressions.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/src/dist/notice.txt:
--------------------------------------------------------------------------------
1 | Spring for Apache Kafka Framework ${version}
2 | Copyright (c) 2016-${copyright} Pivotal, Inc.
3 |
4 | This product is licensed to you under the Apache License, Version 2.0
5 | (the "License"). You may not use this product except in compliance with
6 | the License.
7 |
8 | This product may include a number of subcomponents with separate
9 | copyright notices and license terms. Your use of the source code for
10 | these subcomponents is subject to the terms and conditions of the
11 | subcomponent's license, as noted in the license.txt file.
12 |
--------------------------------------------------------------------------------