diff --git a/non-self-contained-aggregate-app/README.md b/non-self-contained-aggregate-app/README.md new file mode 100644 index 0000000..3f955b1 --- /dev/null +++ b/non-self-contained-aggregate-app/README.md @@ -0,0 +1,30 @@ +Spring Cloud Stream - Non self-contained Aggregate application sample +============================= + +In this *Spring Cloud Stream* sample, the application shows how to write a non self-contained aggregate application. +A non self-contained application is the one that has its applications directly bound but either or both the input and output of the application is bound to the external broker. + +## Requirements + +To run this sample, you will need to have installed: + +* Java 8 or Above + +## Code Tour + +* NonSelfContainedAggregateApplication - the Spring Boot Main Aggregate Application that directly binds `Source` and `Processor` application while the processor application's output is bound to RabbitMQ. +* ProcessorModuleDefinition - the processor application configuration +* SourceModuleDefinition - the source application configuration + +## Building with Maven + +Build the sample by executing: + + >$ mvn clean package + +## Running the Sample + +To start the non self-contained aggregate application execute the following: + + >$ java -jar target/spring-cloud-stream-sample-non-self-contained-aggregate-app--exec.jar + diff --git a/non-self-contained-aggregate-app/pom.xml b/non-self-contained-aggregate-app/pom.xml new file mode 100644 index 0000000..af11b16 --- /dev/null +++ b/non-self-contained-aggregate-app/pom.xml @@ -0,0 +1,56 @@ + + + 4.0.0 + + spring-cloud-stream-sample-non-self-contained-aggregate-app + jar + + spring-cloud-stream-sample-non-self-contained-aggregate-app + Demo project for non self contained Aggregate Application + + + org.springframework.cloud + spring-cloud-stream-samples + 1.1.0.BUILD-SNAPSHOT + + + + demo.NonSelfContainedAggregateApplication + + + + + org.springframework.cloud + spring-cloud-stream + + + org.springframework.boot + spring-boot-configuration-processor + true + + + + org.springframework.boot + spring-boot-starter-test + test + + + + org.springframework.cloud + spring-cloud-stream-binder-rabbit + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + exec + + + + + + diff --git a/non-self-contained-aggregate-app/src/main/java/config/processor/ProcessorApplication.java b/non-self-contained-aggregate-app/src/main/java/config/processor/ProcessorApplication.java new file mode 100644 index 0000000..576a1a7 --- /dev/null +++ b/non-self-contained-aggregate-app/src/main/java/config/processor/ProcessorApplication.java @@ -0,0 +1,27 @@ +/* + * Copyright 2017 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package config.processor; + +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * @author Marius Bogoevici + */ +@SpringBootApplication +public class ProcessorApplication { + +} diff --git a/non-self-contained-aggregate-app/src/main/java/config/processor/ProcessorModuleDefinition.java b/non-self-contained-aggregate-app/src/main/java/config/processor/ProcessorModuleDefinition.java new file mode 100644 index 0000000..8b3e263 --- /dev/null +++ b/non-self-contained-aggregate-app/src/main/java/config/processor/ProcessorModuleDefinition.java @@ -0,0 +1,34 @@ +/* + * Copyright 2017 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package config.processor; + +import org.springframework.cloud.stream.annotation.EnableBinding; +import org.springframework.cloud.stream.messaging.Processor; +import org.springframework.integration.annotation.Transformer; +import org.springframework.messaging.Message; + +/** + * @author Marius Bogoevici + */ +@EnableBinding(Processor.class) +public class ProcessorModuleDefinition { + + @Transformer(inputChannel = Processor.INPUT, outputChannel = Processor.OUTPUT) + public Message transform(Message inbound) { + return inbound; + } +} diff --git a/non-self-contained-aggregate-app/src/main/java/config/source/SourceApplication.java b/non-self-contained-aggregate-app/src/main/java/config/source/SourceApplication.java new file mode 100644 index 0000000..c1d45a6 --- /dev/null +++ b/non-self-contained-aggregate-app/src/main/java/config/source/SourceApplication.java @@ -0,0 +1,26 @@ +/* + * Copyright 2017 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package config.source; + +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * @author Marius Bogoevici + */ +@SpringBootApplication +public class SourceApplication { +} diff --git a/non-self-contained-aggregate-app/src/main/java/config/source/SourceModuleDefinition.java b/non-self-contained-aggregate-app/src/main/java/config/source/SourceModuleDefinition.java new file mode 100644 index 0000000..45742f0 --- /dev/null +++ b/non-self-contained-aggregate-app/src/main/java/config/source/SourceModuleDefinition.java @@ -0,0 +1,45 @@ +/* + * Copyright 2017 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package config.source; + +import java.text.SimpleDateFormat; +import java.util.Date; + +import org.springframework.cloud.stream.annotation.EnableBinding; +import org.springframework.cloud.stream.messaging.Source; +import org.springframework.context.annotation.Bean; +import org.springframework.integration.annotation.InboundChannelAdapter; +import org.springframework.integration.annotation.Poller; +import org.springframework.integration.core.MessageSource; +import org.springframework.messaging.support.GenericMessage; + +/** + * @author Dave Syer + * @author Marius Bogoevici + */ +@EnableBinding(Source.class) +public class SourceModuleDefinition { + + private String format = "yyyy-MM-dd HH:mm:ss"; + + @Bean + @InboundChannelAdapter(value = Source.OUTPUT, poller = @Poller(fixedDelay = "${fixedDelay}", maxMessagesPerPoll = "1")) + public MessageSource timerMessageSource() { + return () -> new GenericMessage<>(new SimpleDateFormat(this.format).format(new Date())); + } + +} diff --git a/non-self-contained-aggregate-app/src/main/java/demo/NonSelfContainedAggregateApplication.java b/non-self-contained-aggregate-app/src/main/java/demo/NonSelfContainedAggregateApplication.java new file mode 100644 index 0000000..d68efed --- /dev/null +++ b/non-self-contained-aggregate-app/src/main/java/demo/NonSelfContainedAggregateApplication.java @@ -0,0 +1,37 @@ +/* + * Copyright 2017 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package demo; + +import config.processor.ProcessorApplication; +import config.source.SourceApplication; + +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.stream.aggregate.AggregateApplicationBuilder; + +/** + * @author Ilayaperumal Gopinathan + */ +@SpringBootApplication +public class NonSelfContainedAggregateApplication { + + public static void main(String[] args) { + new AggregateApplicationBuilder(NonSelfContainedAggregateApplication.class) + .from(SourceApplication.class).args("--fixedDelay=5000") + .via(ProcessorApplication.class).namespace("a").run("--spring.cloud.stream.bindings.output.destination=processor-output"); + } + +} diff --git a/non-self-contained-aggregate-app/src/main/resources/application.yml b/non-self-contained-aggregate-app/src/main/resources/application.yml new file mode 100644 index 0000000..d84e8d1 --- /dev/null +++ b/non-self-contained-aggregate-app/src/main/resources/application.yml @@ -0,0 +1 @@ +fixedDelay: 1000 diff --git a/non-self-contained-aggregate-app/src/test/java/demo/ModuleApplicationTests.java b/non-self-contained-aggregate-app/src/test/java/demo/ModuleApplicationTests.java new file mode 100644 index 0000000..d3943e3 --- /dev/null +++ b/non-self-contained-aggregate-app/src/test/java/demo/ModuleApplicationTests.java @@ -0,0 +1,37 @@ +/* + * Copyright 2015 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package demo; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.web.WebAppConfiguration; + +@RunWith(SpringJUnit4ClassRunner.class) +@SpringBootTest(classes = NonSelfContainedAggregateApplication.class) +@WebAppConfiguration +@DirtiesContext +public class ModuleApplicationTests { + + @Test + public void contextLoads() { + } + +} diff --git a/pom.xml b/pom.xml index 52289fd..94d2cb5 100644 --- a/pom.xml +++ b/pom.xml @@ -25,6 +25,7 @@ sink transform double + non-self-contained-aggregate-app multibinder multibinder-differentsystems rxjava-processor