From 54d19c30cdaa5dc63e2742e3aa8f0d5a42e22a37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=E5=98=89=E9=98=B3?= Date: Mon, 8 Oct 2018 18:17:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B6=88=E6=81=AF=E8=AE=A2=E9=98=85=E3=80=81?= =?UTF-8?q?=E5=8F=91=E9=80=81=E6=88=90=E5=8A=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 25 ++++++++ consumer/.gitignore | 25 ++++++++ consumer/consumer-common/.gitignore | 25 ++++++++ consumer/consumer-common/pom.xml | 24 +++++++ .../top/fjy8018/consumer/common/MySink.java | 16 +++++ .../top/fjy8018/consumer/common/MySource.java | 15 +++++ .../ConsumerCommonApplicationTests.java | 16 +++++ consumer/consumer-server/.gitignore | 25 ++++++++ consumer/consumer-server/pom.xml | 41 ++++++++++++ .../java/top/fjy8018/consumer/Consumer.java | 18 ++++++ .../fjy8018/consumer/ConsumerApplication.java | 12 ++++ .../src/main/resources/application.yml | 12 ++++ .../ConsumerServerApplicationTests.java | 16 +++++ consumer/pom.xml | 41 ++++++++++++ pom.xml | 64 +++++++++++++++++++ producer/.gitignore | 25 ++++++++ producer/pom.xml | 41 ++++++++++++ producer/producer-common/.gitignore | 25 ++++++++ producer/producer-common/pom.xml | 24 +++++++ .../ProducerCommonApplicationTests.java | 16 +++++ producer/producer-server/.gitignore | 25 ++++++++ producer/producer-server/pom.xml | 48 ++++++++++++++ .../java/top/fjy8018/producer/Producer.java | 31 +++++++++ .../fjy8018/producer/ProducerApplication.java | 12 ++++ .../src/main/resources/application.yml | 12 ++++ .../ProducerServerApplicationTests.java | 16 +++++ 26 files changed, 650 insertions(+) create mode 100644 .gitignore create mode 100644 consumer/.gitignore create mode 100644 consumer/consumer-common/.gitignore create mode 100644 consumer/consumer-common/pom.xml create mode 100644 consumer/consumer-common/src/main/java/top/fjy8018/consumer/common/MySink.java create mode 100644 consumer/consumer-common/src/main/java/top/fjy8018/consumer/common/MySource.java create mode 100644 consumer/consumer-common/src/test/java/top/fjy8018/consumer/common/ConsumerCommonApplicationTests.java create mode 100644 consumer/consumer-server/.gitignore create mode 100644 consumer/consumer-server/pom.xml create mode 100644 consumer/consumer-server/src/main/java/top/fjy8018/consumer/Consumer.java create mode 100644 consumer/consumer-server/src/main/java/top/fjy8018/consumer/ConsumerApplication.java create mode 100644 consumer/consumer-server/src/main/resources/application.yml create mode 100644 consumer/consumer-server/src/test/java/top/fjy8018/consumerserver/ConsumerServerApplicationTests.java create mode 100644 consumer/pom.xml create mode 100644 pom.xml create mode 100644 producer/.gitignore create mode 100644 producer/pom.xml create mode 100644 producer/producer-common/.gitignore create mode 100644 producer/producer-common/pom.xml create mode 100644 producer/producer-common/src/test/java/top/fjy8018/producer/common/ProducerCommonApplicationTests.java create mode 100644 producer/producer-server/.gitignore create mode 100644 producer/producer-server/pom.xml create mode 100644 producer/producer-server/src/main/java/top/fjy8018/producer/Producer.java create mode 100644 producer/producer-server/src/main/java/top/fjy8018/producer/ProducerApplication.java create mode 100644 producer/producer-server/src/main/resources/application.yml create mode 100644 producer/producer-server/src/test/java/top/fjy8018/producer/server/ProducerServerApplicationTests.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..82eca33 --- /dev/null +++ b/.gitignore @@ -0,0 +1,25 @@ +/target/ +!.mvn/wrapper/maven-wrapper.jar + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/build/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ \ No newline at end of file diff --git a/consumer/.gitignore b/consumer/.gitignore new file mode 100644 index 0000000..82eca33 --- /dev/null +++ b/consumer/.gitignore @@ -0,0 +1,25 @@ +/target/ +!.mvn/wrapper/maven-wrapper.jar + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/build/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ \ No newline at end of file diff --git a/consumer/consumer-common/.gitignore b/consumer/consumer-common/.gitignore new file mode 100644 index 0000000..82eca33 --- /dev/null +++ b/consumer/consumer-common/.gitignore @@ -0,0 +1,25 @@ +/target/ +!.mvn/wrapper/maven-wrapper.jar + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/build/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ \ No newline at end of file diff --git a/consumer/consumer-common/pom.xml b/consumer/consumer-common/pom.xml new file mode 100644 index 0000000..9d15d75 --- /dev/null +++ b/consumer/consumer-common/pom.xml @@ -0,0 +1,24 @@ + + + 4.0.0 + + consumer-common + 0.0.1-SNAPSHOT + jar + + consumer-common + Demo project for Spring Boot + + + top.fjy8018 + consumer + 0.0.1-SNAPSHOT + + + + + + + + diff --git a/consumer/consumer-common/src/main/java/top/fjy8018/consumer/common/MySink.java b/consumer/consumer-common/src/main/java/top/fjy8018/consumer/common/MySink.java new file mode 100644 index 0000000..571919c --- /dev/null +++ b/consumer/consumer-common/src/main/java/top/fjy8018/consumer/common/MySink.java @@ -0,0 +1,16 @@ +package top.fjy8018.consumer.common; + +import org.springframework.cloud.stream.annotation.Input; +import org.springframework.cloud.stream.messaging.Sink; +import org.springframework.messaging.SubscribableChannel; + +/** + * @author F嘉阳 + * @date 2018-10-08 18:07 + */ +public interface MySink { + String INPUT = "input"; + + @Input(Sink.INPUT) + SubscribableChannel input(); +} diff --git a/consumer/consumer-common/src/main/java/top/fjy8018/consumer/common/MySource.java b/consumer/consumer-common/src/main/java/top/fjy8018/consumer/common/MySource.java new file mode 100644 index 0000000..cd36041 --- /dev/null +++ b/consumer/consumer-common/src/main/java/top/fjy8018/consumer/common/MySource.java @@ -0,0 +1,15 @@ +package top.fjy8018.consumer.common; + +import org.springframework.cloud.stream.annotation.Output; +import org.springframework.messaging.MessageChannel; + +/** + * @author F嘉阳 + * @date 2018-10-08 18:01 + */ +public interface MySource { + String OUTPUT = "output"; + + @Output("output") + MessageChannel output(); +} \ No newline at end of file diff --git a/consumer/consumer-common/src/test/java/top/fjy8018/consumer/common/ConsumerCommonApplicationTests.java b/consumer/consumer-common/src/test/java/top/fjy8018/consumer/common/ConsumerCommonApplicationTests.java new file mode 100644 index 0000000..d30280f --- /dev/null +++ b/consumer/consumer-common/src/test/java/top/fjy8018/consumer/common/ConsumerCommonApplicationTests.java @@ -0,0 +1,16 @@ +package top.fjy8018.consumer.common; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class ConsumerCommonApplicationTests { + + @Test + public void contextLoads() { + } + +} diff --git a/consumer/consumer-server/.gitignore b/consumer/consumer-server/.gitignore new file mode 100644 index 0000000..82eca33 --- /dev/null +++ b/consumer/consumer-server/.gitignore @@ -0,0 +1,25 @@ +/target/ +!.mvn/wrapper/maven-wrapper.jar + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/build/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ \ No newline at end of file diff --git a/consumer/consumer-server/pom.xml b/consumer/consumer-server/pom.xml new file mode 100644 index 0000000..c9efe08 --- /dev/null +++ b/consumer/consumer-server/pom.xml @@ -0,0 +1,41 @@ + + + 4.0.0 + + consumer-server + 0.0.1-SNAPSHOT + jar + + consumer-server + Demo project for Spring Boot + + + top.fjy8018 + consumer + 0.0.1-SNAPSHOT + + + + + org.springframework.boot + spring-boot-starter-web + + + top.fjy8018 + consumer-common + ${project.version} + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + + diff --git a/consumer/consumer-server/src/main/java/top/fjy8018/consumer/Consumer.java b/consumer/consumer-server/src/main/java/top/fjy8018/consumer/Consumer.java new file mode 100644 index 0000000..0a378b7 --- /dev/null +++ b/consumer/consumer-server/src/main/java/top/fjy8018/consumer/Consumer.java @@ -0,0 +1,18 @@ +package top.fjy8018.consumer; + +import org.springframework.cloud.stream.annotation.EnableBinding; +import org.springframework.cloud.stream.annotation.StreamListener; +import org.springframework.messaging.Message; +import top.fjy8018.consumer.common.MySink; + +/** + * @author F嘉阳 + * @date 2018-10-08 18:10 + */ +@EnableBinding(MySink.class) +public class Consumer { + @StreamListener(MySink.INPUT) + public void receive(Message message) { + System.out.println("接收到MQ消息:" + message); + } +} \ No newline at end of file diff --git a/consumer/consumer-server/src/main/java/top/fjy8018/consumer/ConsumerApplication.java b/consumer/consumer-server/src/main/java/top/fjy8018/consumer/ConsumerApplication.java new file mode 100644 index 0000000..3a8fe6e --- /dev/null +++ b/consumer/consumer-server/src/main/java/top/fjy8018/consumer/ConsumerApplication.java @@ -0,0 +1,12 @@ +package top.fjy8018.consumer; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class ConsumerApplication { + + public static void main(String[] args) { + SpringApplication.run(ConsumerApplication.class, args); + } +} diff --git a/consumer/consumer-server/src/main/resources/application.yml b/consumer/consumer-server/src/main/resources/application.yml new file mode 100644 index 0000000..0e0fd75 --- /dev/null +++ b/consumer/consumer-server/src/main/resources/application.yml @@ -0,0 +1,12 @@ +spring: + rabbitmq: + host: docker-1.fjy8018.cn + username: cms + password: cms-mq-admin + cloud: + stream: + bindings: + input: + destination: my-test-channel +server: + port: 8081 \ No newline at end of file diff --git a/consumer/consumer-server/src/test/java/top/fjy8018/consumerserver/ConsumerServerApplicationTests.java b/consumer/consumer-server/src/test/java/top/fjy8018/consumerserver/ConsumerServerApplicationTests.java new file mode 100644 index 0000000..bca1a63 --- /dev/null +++ b/consumer/consumer-server/src/test/java/top/fjy8018/consumerserver/ConsumerServerApplicationTests.java @@ -0,0 +1,16 @@ +package top.fjy8018.consumerserver; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class ConsumerServerApplicationTests { + + @Test + public void contextLoads() { + } + +} diff --git a/consumer/pom.xml b/consumer/pom.xml new file mode 100644 index 0000000..8cab1b8 --- /dev/null +++ b/consumer/pom.xml @@ -0,0 +1,41 @@ + + + 4.0.0 + + consumer + 0.0.1-SNAPSHOT + jar + + consumer + Demo project for Spring Boot + + + consumer-common + consumer-server + + + + top.fjy8018 + cloud-stream + 0.0.1-SNAPSHOT + + + + + org.springframework.cloud + spring-cloud-starter-stream-rabbit + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + + diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..f560953 --- /dev/null +++ b/pom.xml @@ -0,0 +1,64 @@ + + + 4.0.0 + + top.fjy8018 + cloud-stream + 0.0.1-SNAPSHOT + jar + + cloud-stream + Demo project for Spring Boot + + + producer + consumer + + + + org.springframework.boot + spring-boot-starter-parent + 2.0.5.RELEASE + + + + + UTF-8 + UTF-8 + 1.8 + Finchley.SR1 + 0.0.1-SNAPSHOT + + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.cloud + spring-cloud-dependencies + ${spring-cloud.version} + pom + import + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + + diff --git a/producer/.gitignore b/producer/.gitignore new file mode 100644 index 0000000..82eca33 --- /dev/null +++ b/producer/.gitignore @@ -0,0 +1,25 @@ +/target/ +!.mvn/wrapper/maven-wrapper.jar + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/build/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ \ No newline at end of file diff --git a/producer/pom.xml b/producer/pom.xml new file mode 100644 index 0000000..2cb9494 --- /dev/null +++ b/producer/pom.xml @@ -0,0 +1,41 @@ + + + 4.0.0 + + producer + 0.0.1-SNAPSHOT + jar + + + producer-common + producer-server + + + producer + Demo project for Spring Boot + + + top.fjy8018 + cloud-stream + 0.0.1-SNAPSHOT + + + + + org.springframework.cloud + spring-cloud-starter-stream-rabbit + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + + diff --git a/producer/producer-common/.gitignore b/producer/producer-common/.gitignore new file mode 100644 index 0000000..82eca33 --- /dev/null +++ b/producer/producer-common/.gitignore @@ -0,0 +1,25 @@ +/target/ +!.mvn/wrapper/maven-wrapper.jar + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/build/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ \ No newline at end of file diff --git a/producer/producer-common/pom.xml b/producer/producer-common/pom.xml new file mode 100644 index 0000000..ae89ccc --- /dev/null +++ b/producer/producer-common/pom.xml @@ -0,0 +1,24 @@ + + + 4.0.0 + + producer-common + 0.0.1-SNAPSHOT + jar + + producer-common + Demo project for Spring Boot + + + top.fjy8018 + producer + 0.0.1-SNAPSHOT + + + + + + + + diff --git a/producer/producer-common/src/test/java/top/fjy8018/producer/common/ProducerCommonApplicationTests.java b/producer/producer-common/src/test/java/top/fjy8018/producer/common/ProducerCommonApplicationTests.java new file mode 100644 index 0000000..69244f0 --- /dev/null +++ b/producer/producer-common/src/test/java/top/fjy8018/producer/common/ProducerCommonApplicationTests.java @@ -0,0 +1,16 @@ +package top.fjy8018.producer.common; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class ProducerCommonApplicationTests { + + @Test + public void contextLoads() { + } + +} diff --git a/producer/producer-server/.gitignore b/producer/producer-server/.gitignore new file mode 100644 index 0000000..82eca33 --- /dev/null +++ b/producer/producer-server/.gitignore @@ -0,0 +1,25 @@ +/target/ +!.mvn/wrapper/maven-wrapper.jar + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/build/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ \ No newline at end of file diff --git a/producer/producer-server/pom.xml b/producer/producer-server/pom.xml new file mode 100644 index 0000000..aa72312 --- /dev/null +++ b/producer/producer-server/pom.xml @@ -0,0 +1,48 @@ + + + 4.0.0 + + + producer-server + 0.0.1-SNAPSHOT + jar + + producer-server + Demo project for Spring Boot + + + top.fjy8018 + producer + 0.0.1-SNAPSHOT + + + + UTF-8 + UTF-8 + 1.8 + + + + + org.springframework.boot + spring-boot-starter-web + + + top.fjy8018 + consumer-common + ${project.version} + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + + diff --git a/producer/producer-server/src/main/java/top/fjy8018/producer/Producer.java b/producer/producer-server/src/main/java/top/fjy8018/producer/Producer.java new file mode 100644 index 0000000..838fbbd --- /dev/null +++ b/producer/producer-server/src/main/java/top/fjy8018/producer/Producer.java @@ -0,0 +1,31 @@ +package top.fjy8018.producer; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cloud.stream.annotation.EnableBinding; +import org.springframework.cloud.stream.annotation.Output; +import org.springframework.messaging.MessageChannel; +import org.springframework.messaging.support.MessageBuilder; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import top.fjy8018.consumer.common.MySource; + +import java.util.Date; + +/** + * @author F嘉阳 + * @date 2018-10-08 17:57 + */ +@RestController +@EnableBinding(MySource.class) +public class Producer { + + @Autowired + @Output(MySource.OUTPUT) + private MessageChannel channel; + + @RequestMapping("/send") + public String send() { + channel.send(MessageBuilder.withPayload(new Date()).build()); + return "success"; + } +} diff --git a/producer/producer-server/src/main/java/top/fjy8018/producer/ProducerApplication.java b/producer/producer-server/src/main/java/top/fjy8018/producer/ProducerApplication.java new file mode 100644 index 0000000..8af2dcb --- /dev/null +++ b/producer/producer-server/src/main/java/top/fjy8018/producer/ProducerApplication.java @@ -0,0 +1,12 @@ +package top.fjy8018.producer; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class ProducerApplication { + + public static void main(String[] args) { + SpringApplication.run(ProducerApplication.class, args); + } +} diff --git a/producer/producer-server/src/main/resources/application.yml b/producer/producer-server/src/main/resources/application.yml new file mode 100644 index 0000000..1067ebf --- /dev/null +++ b/producer/producer-server/src/main/resources/application.yml @@ -0,0 +1,12 @@ +spring: + rabbitmq: + host: docker-1.fjy8018.cn + username: cms + password: cms-mq-admin + cloud: + stream: + bindings: + output: + destination: my-test-channel +server: + port: 8082 \ No newline at end of file diff --git a/producer/producer-server/src/test/java/top/fjy8018/producer/server/ProducerServerApplicationTests.java b/producer/producer-server/src/test/java/top/fjy8018/producer/server/ProducerServerApplicationTests.java new file mode 100644 index 0000000..40768a7 --- /dev/null +++ b/producer/producer-server/src/test/java/top/fjy8018/producer/server/ProducerServerApplicationTests.java @@ -0,0 +1,16 @@ +package top.fjy8018.producer.server; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class ProducerServerApplicationTests { + + @Test + public void contextLoads() { + } + +}