consumer type
27 | * @param producer type
28 | * @author Marius Bogoevici
29 | */
30 | public interface ExtendedPropertiesBinder
31 | extends Binder, ExtendedProducerProperties>,
32 | ExtendedBindingProperties {
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/core/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/function/StreamFunctionConfigurationProperties.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023-present 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.cloud.stream.function;
18 |
19 | import java.util.HashMap;
20 | import java.util.Map;
21 |
22 | import org.springframework.boot.context.properties.ConfigurationProperties;
23 |
24 | /**
25 | * @author Oleg Zhurakousky
26 | * @author Soby Chacko
27 | * @since 4.0.2
28 | */
29 | @ConfigurationProperties("spring.cloud.stream.function")
30 | public class StreamFunctionConfigurationProperties {
31 | private Map bindings = new HashMap<>();
32 |
33 | public Map getBindings() {
34 | return this.bindings;
35 | }
36 |
37 | public void setBindings(Map bindings) {
38 | this.bindings = bindings;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/schema-registry/spring-cloud-stream-schema-registry-server/src/main/java/org/springframework/cloud/stream/schema/registry/server/SchemaRegistryServerApplication.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016-present 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.cloud.stream.schema.registry.server;
18 |
19 | import org.springframework.boot.SpringApplication;
20 | import org.springframework.boot.autoconfigure.SpringBootApplication;
21 | import org.springframework.cloud.stream.schema.registry.EnableSchemaRegistryServer;
22 |
23 | /**
24 | * @author Vinicius Carvalho
25 | */
26 | // @checkstyle:off
27 | @SpringBootApplication
28 | @EnableSchemaRegistryServer
29 | public class SchemaRegistryServerApplication {
30 |
31 | public static void main(String[] args) {
32 | SpringApplication.run(SchemaRegistryServerApplication.class, args);
33 | }
34 |
35 | }
36 | // @checkstyle:on
37 |
--------------------------------------------------------------------------------
/core/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/binder/DirectHandler.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016-present 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.cloud.stream.binder;
18 |
19 | import org.springframework.messaging.Message;
20 | import org.springframework.messaging.MessageChannel;
21 | import org.springframework.messaging.MessageHandler;
22 | import org.springframework.messaging.MessagingException;
23 |
24 | /**
25 | * @author Marius Bogoevici
26 | */
27 | public class DirectHandler implements MessageHandler {
28 |
29 | private final MessageChannel outputChannel;
30 |
31 | public DirectHandler(MessageChannel outputChannel) {
32 | this.outputChannel = outputChannel;
33 | }
34 |
35 | @Override
36 | public void handleMessage(Message> message) throws MessagingException {
37 | this.outputChannel.send(message);
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/binders/kafka-binder/spring-cloud-stream-binder-kafka/src/test/java/org/springframework/cloud/stream/binder/kafka/RawKafkaPartitionTestSupport.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-present 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.cloud.stream.binder.kafka;
18 |
19 | import org.springframework.cloud.stream.binder.PartitionKeyExtractorStrategy;
20 | import org.springframework.cloud.stream.binder.PartitionSelectorStrategy;
21 | import org.springframework.messaging.Message;
22 |
23 | /**
24 | * @author Marius Bogoevici
25 | */
26 | class RawKafkaPartitionTestSupport
27 | implements PartitionKeyExtractorStrategy, PartitionSelectorStrategy {
28 |
29 | @Override
30 | public int selectPartition(Object key, int divisor) {
31 | return ((byte[]) key)[0] % divisor;
32 | }
33 |
34 | @Override
35 | public Object extractKey(Message> message) {
36 | return message.getPayload();
37 | }
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/schema-registry/spring-cloud-stream-schema-registry-core/src/test/java/org/springframework/cloud/stream/schema/registry/entityScanning/domain/TestEntity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016-present 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.cloud.stream.schema.registry.entityScanning.domain;
18 |
19 | import jakarta.persistence.Column;
20 | import jakarta.persistence.Entity;
21 | import jakarta.persistence.Id;
22 |
23 | /**
24 | * @author Marius Bogoevici
25 | */
26 | @Entity
27 | public class TestEntity {
28 |
29 | @Id
30 | private long id;
31 |
32 | @Column(name = "name")
33 | private String name;
34 |
35 | public long getId() {
36 | return this.id;
37 | }
38 |
39 | public void setId(long id) {
40 | this.id = id;
41 | }
42 |
43 | public String getName() {
44 | return this.name;
45 | }
46 |
47 | public void setName(String name) {
48 | this.name = name;
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/schema-registry/spring-cloud-stream-schema-registry-core/src/main/java/org/springframework/cloud/stream/schema/registry/repository/SchemaRepository.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016-present 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.cloud.stream.schema.registry.repository;
18 |
19 | import java.util.List;
20 |
21 | import org.springframework.cloud.stream.schema.registry.model.Schema;
22 | import org.springframework.data.repository.CrudRepository;
23 | import org.springframework.transaction.annotation.Transactional;
24 |
25 | /**
26 | * @author Vinicius Carvalho
27 | */
28 | public interface SchemaRepository extends CrudRepository {
29 |
30 | @Transactional
31 | List findBySubjectAndFormatOrderByVersion(String subject, String format);
32 |
33 | @Transactional
34 | Schema findOneBySubjectAndFormatAndVersion(String subject, String format, Integer version);
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/core/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/binder/BinderFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015-present 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.cloud.stream.binder;
18 |
19 | /**
20 | * @author Marius Bogoevici
21 | */
22 | public interface BinderFactory {
23 |
24 | /**
25 | * Returns the binder instance associated with the given configuration name. Instance
26 | * caching is a requirement, and implementations must return the same instance on
27 | * subsequent invocations with the same arguments.
28 | * @param the primary binding type
29 | * @param configurationName the name of a binder configuration
30 | * @param bindableType binding target type
31 | * @return the binder instance
32 | */
33 | Binder getBinder(
34 | String configurationName, Class extends T> bindableType);
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/docs/modules/ROOT/pages/spring-cloud-stream/consumer-groups.adoc:
--------------------------------------------------------------------------------
1 | [[consumer-groups]]
2 | = Consumer Groups
3 | :page-section-summary-toc: 1
4 |
5 | While the publish-subscribe model makes it easy to connect applications through shared topics, the ability to scale up by creating multiple instances of a given application is equally important.
6 | When doing so, different instances of an application are placed in a competing consumer relationship, where only one of the instances is expected to handle a given message.
7 |
8 | Spring Cloud Stream models this behavior through the concept of a consumer group.
9 | (Spring Cloud Stream consumer groups are similar to and inspired by Kafka consumer groups.)
10 | Each consumer binding can use the `spring.cloud.stream.bindings..group` property to specify a group name.
11 | For the consumers shown in the following figure, this property would be set as `spring.cloud.stream.bindings..group=hdfsWrite` or `spring.cloud.stream.bindings..group=average`.
12 |
13 | .Spring Cloud Stream Consumer Groups
14 | image::SCSt-groups.png[width=800,scaledwidth="75%",align="center"]
15 |
16 | All groups that subscribe to a given destination receive a copy of published data, but only one member of each group receives a given message from that destination.
17 | By default, when a group is not specified, Spring Cloud Stream assigns the application to an anonymous and independent single-member consumer group that is in a publish-subscribe relationship with all other consumer groups.
18 |
19 |
--------------------------------------------------------------------------------
/core/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/binder/BindingCleaner.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015-present 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.cloud.stream.binder;
18 |
19 | import java.util.List;
20 | import java.util.Map;
21 |
22 | /**
23 | * Interface for implementations that perform cleanup for binders.
24 | *
25 | * @author Gary Russell
26 | * @since 1.2
27 | */
28 | public interface BindingCleaner {
29 |
30 | /**
31 | * Clean up all resources for the supplied stream/job.
32 | * @param entity the stream or job; may be terminated with a simple wild card '*', in
33 | * which case all streams with names starting with the characters before the '*' will
34 | * be cleaned.
35 | * @param isJob true if the entity is a job.
36 | * @return a map of lists of resources removed.
37 | */
38 | Map> clean(String entity, boolean isJob);
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/docs/modules/ROOT/pages/kafka/kafka-streams-binder/timestamp-extractor.adoc:
--------------------------------------------------------------------------------
1 | [[timestamp-extractor]]
2 | = Timestamp extractor
3 |
4 | Kafka Streams allows you to control the processing of the consumer records based on various notions of timestamp.
5 | By default, Kafka Streams extracts the timestamp metadata embedded in the consumer record.
6 | You can change this default behavior by providing a different `TimestampExtractor` implementation per input binding.
7 | Here are some details on how that can be done.
8 |
9 | ```
10 | @Bean
11 | public Function,
12 | Function,
13 | Function, KStream>>> process() {
14 | return orderStream ->
15 | customers ->
16 | products -> orderStream;
17 | }
18 |
19 | @Bean
20 | public TimestampExtractor timestampExtractor() {
21 | return new WallclockTimestampExtractor();
22 | }
23 | ```
24 |
25 | Then you set the above `TimestampExtractor` bean name per consumer binding.
26 |
27 | ```
28 | spring.cloud.stream.kafka.streams.bindings.process-in-0.consumer.timestampExtractorBeanName=timestampExtractor
29 | spring.cloud.stream.kafka.streams.bindings.process-in-1.consumer.timestampExtractorBeanName=timestampExtractor
30 | spring.cloud.stream.kafka.streams.bindings.process-in-2.consumer.timestampExtractorBeanName=timestampExtractor"
31 | ```
32 |
33 | If you skip an input consumer binding for setting a custom timestamp extractor, that consumer will use the default settings.
34 |
35 |
--------------------------------------------------------------------------------
/core/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/converter/CustomMimeTypeConverter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013-present 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.cloud.stream.converter;
18 |
19 | import org.springframework.core.convert.converter.Converter;
20 | import org.springframework.util.MimeType;
21 |
22 | /**
23 | * A custom converter for {@link MimeType} that accepts a plain java class name as a
24 | * shorthand for {@code application/x-java-object;type=the.qualified.ClassName}.
25 | *
26 | * @author Eric Bottard
27 | * @author David Turanski
28 | */
29 | public class CustomMimeTypeConverter implements Converter {
30 |
31 | @Override
32 | public MimeType convert(String source) {
33 | if (!source.contains("/")) {
34 | return MimeType.valueOf("application/x-java-object;type=" + source);
35 | }
36 | return MimeType.valueOf(source);
37 | }
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/docs/modules/ROOT/pages/kafka/kafka-binder/metrics.adoc:
--------------------------------------------------------------------------------
1 | [[kafka-metrics]]
2 | = Kafka Metrics
3 |
4 | Kafka binder module exposes the following metrics:
5 |
6 | `spring.cloud.stream.binder.kafka.offset`: This metric indicates how many messages have not been yet consumed from a given binder's topic by a given consumer group.
7 | The metrics provided are based on the Micrometer library.
8 | The binder creates the `KafkaBinderMetrics` bean if Micrometer is on the classpath and no other such beans provided by the application.
9 | The metric contains the consumer group information, topic and the actual lag in committed offset from the latest offset on the topic.
10 | This metric is particularly useful for providing auto-scaling feedback to a PaaS platform.
11 |
12 | The metric collection behaviour can be configured by setting properties in the `spring.cloud.stream.kafka.binder.metrics` namespace,
13 | refer to the <> for more information.
14 |
15 | You can exclude `KafkaBinderMetrics` from creating the necessary infrastructure like consumers and then reporting the metrics by providing the following component in the application.
16 |
17 | ```
18 | @Component
19 | class NoOpBindingMeters {
20 | NoOpBindingMeters(MeterRegistry registry) {
21 | registry.config().meterFilter(
22 | MeterFilter.denyNameStartsWith(KafkaBinderMetrics.OFFSET_LAG_METRIC_NAME));
23 | }
24 | }
25 | ```
26 |
27 | More details on how to suppress meters selectively can be found https://micrometer.io/docs/concepts#_meter_filters[here].
28 |
--------------------------------------------------------------------------------
/docs/modules/ROOT/pages/kafka/kafka-reactive-binder/sender_result.adoc:
--------------------------------------------------------------------------------
1 | [[sender-result-channel]]
2 | = Sender Result Channel
3 |
4 | Starting with version 4.0.3, you can configure the `resultMetadataChannel` to receive `SenderResult>` s to determine success/failure of sends.
5 |
6 | The `SenderResult` contains `correlationMetadata` to allow you to correlate results with sends; it also contains `RecordMetadata`, which indicates the `TopicPartition` and offset of the sent record.
7 |
8 | The `resultMetadataChannel` **must** be a `FluxMessageChannel` instance.
9 |
10 | Here is an example of how to use this feature, with correlation metadata of type `Integer`:
11 |
12 | [source, java]
13 | ----
14 | @Bean
15 | FluxMessageChannel sendResults() {
16 | return new FluxMessageChannel();
17 | }
18 |
19 | @ServiceActivator(inputChannel = "sendResults")
20 | void handleResults(SenderResult result) {
21 | if (result.exception() != null) {
22 | failureFor(result);
23 | }
24 | else {
25 | successFor(result);
26 | }
27 | }
28 | ----
29 |
30 | To set the correlation metadata on an output record, set the `CORRELATION_ID` header:
31 |
32 | [source, java]
33 | ----
34 | streamBridge.send("words1", MessageBuilder.withPayload("foobar")
35 | .setCorrelationId(42)
36 | .build());
37 | ----
38 |
39 | When using the feature with a `Function`, the function output type must be a `Message>` with the correlation id header set to the desired value.
40 |
41 | Metadata should be unique, at least for the duration of the send.
42 |
--------------------------------------------------------------------------------
/docs/modules/ROOT/pages/spring-cloud-stream/multiple-binders.adoc:
--------------------------------------------------------------------------------
1 | [[multiple-binders]]
2 | = Multiple Binders on the Classpath
3 | :page-section-summary-toc: 1
4 |
5 | When multiple binders are present on the classpath, the application must indicate which binder is to be used for each destination binding.
6 | Each binder configuration contains a `META-INF/spring.binders` file, which is a simple properties file, as shown in the following example:
7 |
8 | [source]
9 | ----
10 | rabbit:\
11 | org.springframework.cloud.stream.binder.rabbit.config.RabbitServiceAutoConfiguration
12 | ----
13 |
14 | Similar files exist for the other provided binder implementations (such as Kafka), and custom binder implementations are expected to provide them as well.
15 | The key represents an identifying name for the binder implementation, whereas the value is a comma-separated list of configuration classes that each contain one and only one bean definition of type `org.springframework.cloud.stream.binder.Binder`.
16 |
17 | Binder selection can either be performed globally, using the `spring.cloud.stream.defaultBinder` property (for example, `spring.cloud.stream.defaultBinder=rabbit`) or individually, by configuring the binder on each binding.
18 | For instance, a processor application (that has bindings named `input` and `output` for read and write respectively) that reads from Kafka and writes to RabbitMQ can specify the following configuration:
19 |
20 | [source]
21 | ----
22 | spring.cloud.stream.bindings.input.binder=kafka
23 | spring.cloud.stream.bindings.output.binder=rabbit
24 | ----
25 |
26 |
--------------------------------------------------------------------------------
/binders/rabbit-binder/spring-cloud-stream-binder-rabbit-test-support/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 |
5 | org.springframework.cloud
6 | spring-cloud-stream-binder-rabbit-parent
7 | 5.0.1-SNAPSHOT
8 |
9 | spring-cloud-stream-binder-rabbit-test-support
10 | ${project.artifactId}
11 | Rabbit related test classes
12 |
13 |
14 | org.springframework.boot
15 | spring-boot-starter-logging
16 |
17 |
18 | org.springframework.boot
19 | spring-boot-starter-amqp
20 | true
21 |
22 |
23 | org.springframework.boot
24 | spring-boot-starter-test
25 |
26 |
27 | org.junit.jupiter
28 | junit-jupiter
29 | compile
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/binders/kafka-binder/spring-cloud-stream-binder-kafka-core/src/main/java/org/springframework/cloud/stream/binder/kafka/common/TopicInformation.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023-present 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.cloud.stream.binder.kafka.common;
18 |
19 | import java.util.Collection;
20 |
21 | import org.apache.kafka.common.PartitionInfo;
22 |
23 | /**
24 | * Record to capture topic information for various binder related tasks.
25 | *
26 | * @param consumerGroup consumer group for the consumer
27 | * @param partitionInfos collection of {@link PartitionInfo}
28 | * @param isTopicPattern if the topic is specified as a pattern
29 | *
30 | * @author Soby Chacko (and previous authors before refactoring).
31 | */
32 | public record TopicInformation(String consumerGroup, Collection partitionInfos, boolean isTopicPattern) {
33 |
34 | public boolean isConsumerTopic() {
35 | return this.consumerGroup != null;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/schema-registry/spring-cloud-stream-schema-registry-core/src/main/java/org/springframework/cloud/stream/schema/registry/EnableSchemaRegistryServer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016-present 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.cloud.stream.schema.registry;
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 | import org.springframework.cloud.stream.schema.registry.config.SchemaServerConfiguration;
26 | import org.springframework.context.annotation.Import;
27 |
28 | /**
29 | * Enables the schema registry server enpoints.
30 | *
31 | * @author Vinicius Carvalho
32 | */
33 | @Target(ElementType.TYPE)
34 | @Retention(RetentionPolicy.RUNTIME)
35 | @Documented
36 | @Import(SchemaServerConfiguration.class)
37 | public @interface EnableSchemaRegistryServer {
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/core/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/binder/PartitionSelectorStrategy.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-present 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.cloud.stream.binder;
18 |
19 | /**
20 | * Strategy for determining the partition to which a message should be sent.
21 | *
22 | * @author Gary Russell
23 | */
24 | public interface PartitionSelectorStrategy {
25 |
26 | /**
27 | * Determine the partition based on a key. The partitionCount is 1 greater than the
28 | * maximum value of a valid partition. Typical implementations will return
29 | * {@code someValue % partitionCount}. The caller will apply that same modulo
30 | * operation (as well as enforcing absolute value) if the value exceeds partitionCount
31 | * - 1.
32 | * @param key the key
33 | * @param partitionCount the number of partitions
34 | * @return the partition
35 | */
36 | int selectPartition(Object key, int partitionCount);
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/core/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/binder/DefaultBinderTypeRegistry.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015-present 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.cloud.stream.binder;
18 |
19 | import java.util.Collections;
20 | import java.util.HashMap;
21 | import java.util.Map;
22 |
23 | /**
24 | * Default implementation of a {@link BinderTypeRegistry}.
25 | *
26 | * @author Marius Bogoevici
27 | */
28 | public class DefaultBinderTypeRegistry implements BinderTypeRegistry {
29 |
30 | private final Map binderTypes;
31 |
32 | public DefaultBinderTypeRegistry(Map binderTypes) {
33 | this.binderTypes = Collections.unmodifiableMap(new HashMap<>(binderTypes));
34 | }
35 |
36 | @Override
37 | public BinderType get(String name) {
38 | return this.binderTypes.get(name);
39 | }
40 |
41 | @Override
42 | public Map getAll() {
43 | return this.binderTypes;
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/core/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/utils/FooBindingProperties.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018-present 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.cloud.stream.utils;
18 |
19 | import org.springframework.cloud.stream.binder.BinderSpecificPropertiesProvider;
20 |
21 | /**
22 | * @author Soby Chacko
23 | */
24 | public class FooBindingProperties implements BinderSpecificPropertiesProvider {
25 |
26 | private FooProducerProperties producer = new FooProducerProperties();
27 |
28 | private FooConsumerProperties consumer = new FooConsumerProperties();
29 |
30 | public FooProducerProperties getProducer() {
31 | return this.producer;
32 | }
33 |
34 | public void setProducer(FooProducerProperties producer) {
35 | this.producer = producer;
36 | }
37 |
38 | public FooConsumerProperties getConsumer() {
39 | return this.consumer;
40 | }
41 |
42 | public void setConsumer(FooConsumerProperties consumer) {
43 | this.consumer = consumer;
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/binders/rabbit-binder/spring-cloud-stream-binder-rabbit/src/main/java/org/springframework/cloud/stream/binder/rabbit/deployer/RabbitDeployerEnvironmentPostProcessor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021-present 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.cloud.stream.binder.rabbit.deployer;
18 |
19 | import org.springframework.boot.EnvironmentPostProcessor;
20 | import org.springframework.boot.SpringApplication;
21 | import org.springframework.core.env.ConfigurableEnvironment;
22 |
23 | /**
24 | *
25 | * @author Oleg Zhurakousky
26 | *
27 | * @since 3.2
28 | *
29 | */
30 | class RabbitDeployerEnvironmentPostProcessor implements EnvironmentPostProcessor {
31 |
32 | @Override
33 | public void postProcessEnvironment(ConfigurableEnvironment environment,
34 | SpringApplication application) {
35 | if (!environment.containsProperty("spring.cloud.function.rsocket.enabled")) {
36 | environment.getSystemProperties().putIfAbsent("spring.cloud.function.rsocket.enabled", "false");
37 | }
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/schema-registry/spring-cloud-stream-schema-registry-client/src/test/java/org/springframework/cloud/stream/schema/avro/domain/FoodOrder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017-present 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.cloud.stream.schema.avro.domain;
18 |
19 | /**
20 | * @author Ish Mahajan
21 | */
22 | public class FoodOrder {
23 | private String restaurant;
24 | private String customerAddress;
25 | private String orderDescription;
26 | public String getRestaurant() {
27 | return restaurant;
28 | }
29 | public void setRestaurant(String restaurant) {
30 | this.restaurant = restaurant;
31 | }
32 | public String getCustomerAddress() {
33 | return customerAddress;
34 | }
35 | public void setCustomerAddress(String customerAddress) {
36 | this.customerAddress = customerAddress;
37 | }
38 | public String getOrderDescription() {
39 | return orderDescription;
40 | }
41 | public void setOrderDescription(String orderDescription) {
42 | this.orderDescription = orderDescription;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/core/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/binding/BinderAwareRouter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013-present 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.cloud.stream.binding;
18 |
19 | import org.springframework.integration.router.AbstractMappingMessageRouter;
20 | import org.springframework.messaging.MessageChannel;
21 | import org.springframework.messaging.core.DestinationResolver;
22 |
23 | /**
24 | * Sets a BinderAwareChannelResolver on any bean
25 | * of type {@link AbstractMappingMessageRouter} within the context.
26 | *
27 | * @author Mark Fisher
28 | * @author Gary Russell
29 | * @author Oleg Zhurakousky
30 | */
31 | public class BinderAwareRouter {
32 |
33 | public BinderAwareRouter(AbstractMappingMessageRouter[] routers,
34 | DestinationResolver channelResolver) {
35 | if (routers != null) {
36 | for (AbstractMappingMessageRouter router : routers) {
37 | router.setChannelResolver(channelResolver);
38 | }
39 | }
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/.github/workflows/ci-pr.yml:
--------------------------------------------------------------------------------
1 | name: CI PRs
2 |
3 | on:
4 | pull_request:
5 | branches:
6 | - 'main'
7 | - '4.1.x'
8 | paths-ignore:
9 | - '.github/**'
10 |
11 | env:
12 | MAVEN_THREADS: '-T 2'
13 |
14 | jobs:
15 | build_and_verify:
16 | name: Build and Verify
17 | if: github.repository == 'spring-cloud/spring-cloud-stream'
18 | runs-on: ubuntu-latest
19 | steps:
20 |
21 | - name: Checkout SCSt repo
22 | uses: actions/checkout@v2
23 |
24 | - name: Setup Maven cache
25 | uses: actions/cache@v4
26 | with:
27 | path: ~/.m2/repository
28 | key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
29 | restore-keys: |
30 | ${{ runner.os }}-m2-
31 |
32 | - name: Setup Java 17
33 | uses: actions/setup-java@v3
34 | with:
35 | java-version: '17'
36 | distribution: 'liberica'
37 |
38 | - name: Setup Maven
39 | uses: jvalkeal/setup-maven@v1
40 | with:
41 | maven-version: 3.8.9
42 | maven-mirror: 'https://dlcdn.apache.org/maven/maven-3/'
43 |
44 | - name: Build and run unit tests
45 | run: |
46 | mvn -B -s .github/settings.xml clean install
47 |
48 | - name: Clean Maven cache
49 | run: |
50 | find ~/.m2/repository -type d -name '*SNAPSHOT' | xargs rm -fr
51 |
52 | - name: Capture Test Results
53 | if: failure()
54 | uses: actions/upload-artifact@v4
55 | with:
56 | name: test-results
57 | path: '*/target/surefire-reports/*.*'
58 | retention-days: 3
59 |
--------------------------------------------------------------------------------
/core/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/binder/RequeueCurrentMessageException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018-present 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.cloud.stream.binder;
18 |
19 | /**
20 | * When using a {@code PollableMessageSource} throw this exception to cause the current
21 | * message to be requeued in the broker so that it will be redelivered on the next poll.
22 | *
23 | * @author Gary Russell
24 | * @since 2.1
25 | *
26 | */
27 | public class RequeueCurrentMessageException extends RuntimeException {
28 |
29 | private static final long serialVersionUID = 1L;
30 |
31 | public RequeueCurrentMessageException() {
32 | super();
33 | }
34 |
35 | public RequeueCurrentMessageException(String message, Throwable cause) {
36 | super(message, cause);
37 | }
38 |
39 | public RequeueCurrentMessageException(String message) {
40 | super(message);
41 | }
42 |
43 | public RequeueCurrentMessageException(Throwable cause) {
44 | super(cause);
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/core/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/config/ListenerContainerCustomizer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018-present 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.cloud.stream.config;
18 |
19 | /**
20 | * If a single bean of this type is in the application context, listener containers
21 | * created by the binder can be further customized after all the properties are set. For
22 | * example, to configure less-common properties.
23 | *
24 | * @param container type
25 | * @author Gary Russell
26 | * @author Oleg Zhurakousky
27 | * @since 2.1
28 | */
29 | @FunctionalInterface
30 | public interface ListenerContainerCustomizer {
31 |
32 | /**
33 | * Configure the container that is being created for the supplied queue name and
34 | * consumer group.
35 | * @param container the container.
36 | * @param destinationName the destination name.
37 | * @param group the consumer group.
38 | */
39 | void configure(T container, String destinationName, String group);
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/core/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/function/FunctionConstants.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019-present 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.cloud.stream.function;
18 |
19 | /**
20 | * Interfaces which defines constants used for naming conventions used in bindings
21 | * of multiple functions or functions with multiple inputs and outputs.
22 | *
23 | * @author Oleg Zhurakousky
24 | * @author Soby Chacko
25 | *
26 | * @since 3.0
27 | *
28 | */
29 | public final class FunctionConstants {
30 |
31 | private FunctionConstants() {
32 |
33 | }
34 |
35 | /**
36 | * Delimiter used for functional binding naming convention.
37 | */
38 | public static final String DELIMITER = "-";
39 |
40 | /**
41 | * Suffix used for functional binding naming convention.
42 | */
43 | public static final String DEFAULT_OUTPUT_SUFFIX = "out";
44 |
45 | /**
46 | * Prefix used for functional binding naming convention.
47 | */
48 | public static final String DEFAULT_INPUT_SUFFIX = "in";
49 | }
50 |
--------------------------------------------------------------------------------