编程模型从命令式升级为函数式
This commit is contained in:
@@ -1,16 +0,0 @@
|
|||||||
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() {
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
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<String> message) {
|
|
||||||
System.out.println("接收到MQ消息:" + message.getPayload());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -2,6 +2,10 @@ package top.fjy8018.consumer;
|
|||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
public class ConsumerApplication {
|
public class ConsumerApplication {
|
||||||
@@ -9,4 +13,9 @@ public class ConsumerApplication {
|
|||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(ConsumerApplication.class, args);
|
SpringApplication.run(ConsumerApplication.class, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public Consumer<Date> receive() {
|
||||||
|
return System.out::println;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
spring:
|
spring:
|
||||||
rabbitmq:
|
rabbitmq:
|
||||||
host: 192.168.163.128
|
host: 192.168.133.128
|
||||||
username: cms
|
username: dev-user
|
||||||
password: cms-mq-admin
|
password: devpassword
|
||||||
cloud:
|
cloud:
|
||||||
stream:
|
stream:
|
||||||
bindings:
|
bindings:
|
||||||
|
|||||||
@@ -1,16 +0,0 @@
|
|||||||
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() {
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
<artifactId>consumer</artifactId>
|
<artifactId>consumer</artifactId>
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
<name>consumer</name>
|
<name>consumer</name>
|
||||||
<description>Demo project for Spring Boot</description>
|
<description>Demo project for Spring Boot</description>
|
||||||
|
|||||||
6
pom.xml
6
pom.xml
@@ -6,7 +6,7 @@
|
|||||||
<groupId>top.fjy8018</groupId>
|
<groupId>top.fjy8018</groupId>
|
||||||
<artifactId>cloud-stream</artifactId>
|
<artifactId>cloud-stream</artifactId>
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
<name>cloud-stream</name>
|
<name>cloud-stream</name>
|
||||||
<description>Demo project for Spring Boot</description>
|
<description>Demo project for Spring Boot</description>
|
||||||
@@ -19,7 +19,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-parent</artifactId>
|
<artifactId>spring-boot-starter-parent</artifactId>
|
||||||
<version>2.0.5.RELEASE</version>
|
<version>2.4.2</version>
|
||||||
<relativePath/> <!-- lookup parent from repository -->
|
<relativePath/> <!-- lookup parent from repository -->
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
@@ -27,7 +27,7 @@
|
|||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||||
<java.version>1.8</java.version>
|
<java.version>1.8</java.version>
|
||||||
<spring-cloud.version>Finchley.SR1</spring-cloud.version>
|
<spring-cloud.version>2020.0.1</spring-cloud.version>
|
||||||
<project.version>0.0.1-SNAPSHOT</project.version>
|
<project.version>0.0.1-SNAPSHOT</project.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
<artifactId>producer</artifactId>
|
<artifactId>producer</artifactId>
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
<modules>
|
<modules>
|
||||||
<module>producer-common</module>
|
<module>producer-common</module>
|
||||||
|
|||||||
@@ -1,16 +0,0 @@
|
|||||||
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() {
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,10 +1,7 @@
|
|||||||
package top.fjy8018.producer;
|
package top.fjy8018.producer;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.cloud.stream.annotation.EnableBinding;
|
import org.springframework.cloud.stream.function.StreamBridge;
|
||||||
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.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
import top.fjy8018.consumer.common.MySource;
|
import top.fjy8018.consumer.common.MySource;
|
||||||
@@ -16,15 +13,15 @@ import java.util.Date;
|
|||||||
* @date 2018-10-08 17:57
|
* @date 2018-10-08 17:57
|
||||||
*/
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
@EnableBinding(MySource.class)
|
|
||||||
public class Producer {
|
public class Producer {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private MySource channel;
|
private StreamBridge streamBridge;
|
||||||
|
|
||||||
@RequestMapping("/send")
|
@RequestMapping("/send")
|
||||||
public String send() {
|
public String send() {
|
||||||
channel.output().send(MessageBuilder.withPayload(new Date()).build());
|
streamBridge.send(MySource.OUTPUT, new Date());
|
||||||
return "success";
|
return "success";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
spring:
|
spring:
|
||||||
rabbitmq:
|
rabbitmq:
|
||||||
host: 192.168.163.128
|
host: 192.168.133.128
|
||||||
username: cms
|
username: dev-user
|
||||||
password: cms-mq-admin
|
password: devpassword
|
||||||
cloud:
|
cloud:
|
||||||
stream:
|
stream:
|
||||||
bindings:
|
bindings:
|
||||||
|
|||||||
@@ -1,16 +0,0 @@
|
|||||||
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() {
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user