From 8045ff4df97141f3247ff6bb04ab7d6e8aed65fb Mon Sep 17 00:00:00 2001 From: Oleg Zhurakousky Date: Tue, 17 Aug 2021 10:01:10 +0200 Subject: [PATCH] GH-335 Add initial support for attaching user application to a binder at startup time --- pom.xml | 1 + .../pom.xml | 5 ++ .../rabbit/deployer/RabbitDeployer.java | 77 ++++++------------- ...abbitDeployerEnvironmentPostProcessor.java | 4 +- spring-cloud-stream-binder-rabbit/pom.xml | 13 ++++ .../main/resources/META-INF/spring.factories | 5 +- src/checkstyle/checkstyle-suppressions.xml | 8 ++ 7 files changed, 58 insertions(+), 55 deletions(-) create mode 100644 src/checkstyle/checkstyle-suppressions.xml diff --git a/pom.xml b/pom.xml index 0a4f019d2..b8f9fd19e 100644 --- a/pom.xml +++ b/pom.xml @@ -13,6 +13,7 @@ 3.2.0-SNAPSHOT 1.8 + 3.2.0-SNAPSHOT true true diff --git a/spring-cloud-stream-binder-rabbit-deployer/pom.xml b/spring-cloud-stream-binder-rabbit-deployer/pom.xml index 097207b8a..07a217d2e 100644 --- a/spring-cloud-stream-binder-rabbit-deployer/pom.xml +++ b/spring-cloud-stream-binder-rabbit-deployer/pom.xml @@ -12,6 +12,10 @@ spring-cloud-stream-binder-rabbit-parent 3.2.0-SNAPSHOT + + + true + @@ -42,4 +46,5 @@ + diff --git a/spring-cloud-stream-binder-rabbit-deployer/src/main/java/org/springframework/cloud/stream/binder/rabbit/deployer/RabbitDeployer.java b/spring-cloud-stream-binder-rabbit-deployer/src/main/java/org/springframework/cloud/stream/binder/rabbit/deployer/RabbitDeployer.java index b05dcc96b..f31c9a48a 100644 --- a/spring-cloud-stream-binder-rabbit-deployer/src/main/java/org/springframework/cloud/stream/binder/rabbit/deployer/RabbitDeployer.java +++ b/spring-cloud-stream-binder-rabbit-deployer/src/main/java/org/springframework/cloud/stream/binder/rabbit/deployer/RabbitDeployer.java @@ -16,22 +16,34 @@ package org.springframework.cloud.stream.binder.rabbit.deployer; -import java.util.function.Consumer; -import java.util.function.Function; - import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.cloud.function.context.FunctionProperties; -import org.springframework.cloud.stream.function.StreamBridge; -import org.springframework.context.annotation.Bean; -import org.springframework.core.env.Environment; -import org.springframework.messaging.Message; -import org.springframework.messaging.rsocket.RSocketRequester; -import org.springframework.messaging.support.MessageBuilder; /** + * Main application class to trigger the deployment of Java Functions based + * user application with RabitMQ bindings. + *
+ *
+ * It is based on Spring Cloud Function + * deploy feature + * + *
+ * All you need to do is to provide few additional properties to assist Spring Cloud Function deployer. + *
+ * For example: + *
+ *
+ *
+ * java -jar spring-cloud-stream-binder-rabbit-deployer/target/spring-cloud-stream-binder-rabbit-deployer-3.2.0-SNAPSHOT.jar\
+ * 		 	--spring.cloud.function.location=/foo/bar/simplestjar-1.0.0.RELEASE.jar
+ * 			--spring.cloud.function.function-class=function.example.UpperCaseFunction
+ *
+ * 
+ * The only required property is 'spring.cloud.function.location'. Every other property is optional and is based on the style of user application. + * For more details on the supported styles of user application please refer to + * + * Deploying a Packaged Function section of Spring Cloud Function. * * @author Oleg Zhurakousky * @since 3.1.2 @@ -40,49 +52,8 @@ import org.springframework.messaging.support.MessageBuilder; @SpringBootApplication public class RabbitDeployer { - /* - * SpringApplication.run(RabbitDeployer.class, - "--spring.cloud.function.definition=reverseFunction", - "--spring.cloud.function.location=/bootjar-1.0.0.RELEASE-exec.jar", - "--spring.cloud.function.function-class=function.example.ReverseFunction" - ); - */ public static void main(String[] args) { - SpringApplication.run(RabbitDeployer.class); + SpringApplication.run(RabbitDeployer.class, args); } - @Bean - @ConditionalOnProperty(name = FunctionProperties.PREFIX + ".rsocket.enabled", matchIfMissing = true) - public Function, Message> gateway(StreamBridge bridge) { - return message -> { - String destinationName = (String) message.getHeaders().get("target_destination"); - bridge.send(destinationName, message); - return MessageBuilder.withPayload("Successfully sent to reverseFunction-in-0".getBytes()).build(); - }; - } - - /* - * Just like any other stream bean. This one will subscribe to broker destination (using regular stream mechanisms) - * and using some configuration provided by the user will propagate message to remote (rsocket) subscriber - */ - @Bean - @ConditionalOnProperty(name = FunctionProperties.PREFIX + ".rsocket.enabled", matchIfMissing = true) - public Consumer> delegatingConsumer(RSocketRequester.Builder rsocketRequesterBuilder, Environment environment) { - String host = environment.getProperty("spring.cloud.function.rsocket.subscriber.host"); - String port = environment.getProperty("spring.cloud.function.rsocket.subscriber.port"); - return message -> { -// rsocketRequesterBuilder.tcp("host", Integer.valueOf(port)) -// .route("pojoToString") -// .data(message) -// .retrieveMono(String.class); - }; - } - - // Step-1 - rabbit-bundle.jar(time) | rabbit-bundle.jar(log) - Step One - local - // Step-2 - polyglot - // Step-3 - SCDF - // Step-4 - Kubernetes - - //http | rabbit-rsocket-bundle.jar(producer) | python | rabbit-rsocket-bundle.jar(consumer) | rabbit-bundle.jar(log) - } diff --git a/spring-cloud-stream-binder-rabbit-deployer/src/main/java/org/springframework/cloud/stream/binder/rabbit/deployer/RabbitDeployerEnvironmentPostProcessor.java b/spring-cloud-stream-binder-rabbit-deployer/src/main/java/org/springframework/cloud/stream/binder/rabbit/deployer/RabbitDeployerEnvironmentPostProcessor.java index c5b2adbe1..10cbffbf3 100644 --- a/spring-cloud-stream-binder-rabbit-deployer/src/main/java/org/springframework/cloud/stream/binder/rabbit/deployer/RabbitDeployerEnvironmentPostProcessor.java +++ b/spring-cloud-stream-binder-rabbit-deployer/src/main/java/org/springframework/cloud/stream/binder/rabbit/deployer/RabbitDeployerEnvironmentPostProcessor.java @@ -35,7 +35,9 @@ class RabbitDeployerEnvironmentPostProcessor implements EnvironmentPostProcessor if (!environment.containsProperty("spring.cloud.function.rsocket.enabled")) { environment.getSystemProperties().putIfAbsent("spring.cloud.function.rsocket.enabled", false); } - + if (!environment.containsProperty("spring.cloud.function.deployer.enabled")) { + environment.getSystemProperties().putIfAbsent("spring.cloud.function.deployer.enabled", false); + } } } diff --git a/spring-cloud-stream-binder-rabbit/pom.xml b/spring-cloud-stream-binder-rabbit/pom.xml index 197d5c7bb..60d0c07a0 100644 --- a/spring-cloud-stream-binder-rabbit/pom.xml +++ b/spring-cloud-stream-binder-rabbit/pom.xml @@ -14,6 +14,11 @@ + + org.springframework.cloud + spring-cloud-function-deployer + ${spring-cloud-function.version} + org.springframework.cloud spring-cloud-stream-binder-rabbit-core @@ -92,4 +97,12 @@ 4.5.13 + + + + org.springframework.boot + spring-boot-maven-plugin + + + diff --git a/spring-cloud-stream-binder-rabbit/src/main/resources/META-INF/spring.factories b/spring-cloud-stream-binder-rabbit/src/main/resources/META-INF/spring.factories index c299f8ddf..bb946aecc 100644 --- a/spring-cloud-stream-binder-rabbit/src/main/resources/META-INF/spring.factories +++ b/spring-cloud-stream-binder-rabbit/src/main/resources/META-INF/spring.factories @@ -1 +1,4 @@ -org.springframework.boot.autoconfigure.EnableAutoConfiguration=org.springframework.cloud.stream.binder.rabbit.config.ExtendedBindingHandlerMappingsProviderConfiguration +org.springframework.boot.autoconfigure.EnableAutoConfiguration:\ +org.springframework.cloud.stream.binder.rabbit.config.ExtendedBindingHandlerMappingsProviderConfiguration +org.springframework.boot.env.EnvironmentPostProcessor:\ +org.springframework.cloud.stream.binder.rabbit.deployer.RabbitDeployerEnvironmentPostProcessor \ No newline at end of file diff --git a/src/checkstyle/checkstyle-suppressions.xml b/src/checkstyle/checkstyle-suppressions.xml new file mode 100644 index 000000000..9d0be9549 --- /dev/null +++ b/src/checkstyle/checkstyle-suppressions.xml @@ -0,0 +1,8 @@ + + + + + + \ No newline at end of file