Compare commits
4 Commits
functional
...
stream-bri
| Author | SHA1 | Date | |
|---|---|---|---|
| bdd312cfba | |||
| c707a6dedc | |||
| b2ac356484 | |||
| 09d090a438 |
@@ -18,4 +18,9 @@ public class ConsumerApplication {
|
|||||||
public Consumer<Date> sink1() {
|
public Consumer<Date> sink1() {
|
||||||
return System.out::println;
|
return System.out::println;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public Consumer<String> sink2() {
|
||||||
|
return System.out::println;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,11 +7,16 @@ spring:
|
|||||||
cloud:
|
cloud:
|
||||||
stream:
|
stream:
|
||||||
bindings:
|
bindings:
|
||||||
sink1-in-0:
|
send1:
|
||||||
destination: test1
|
destination: test2
|
||||||
function:
|
send2:
|
||||||
definition: sink1
|
destination: test3
|
||||||
|
function:
|
||||||
|
# 定义别名
|
||||||
|
bindings:
|
||||||
|
sink1-in-0: send1
|
||||||
|
sink2-in-0: send2
|
||||||
|
definition: sink1;sink2
|
||||||
|
|
||||||
server:
|
server:
|
||||||
port: 8081
|
port: 8081
|
||||||
@@ -1,11 +1,13 @@
|
|||||||
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.function.StreamBridge;
|
||||||
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 java.time.LocalDateTime;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author F嘉阳
|
* @author F嘉阳
|
||||||
@@ -15,12 +17,18 @@ import java.util.function.Supplier;
|
|||||||
public class Producer {
|
public class Producer {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private Supplier<Date> supplier;
|
private StreamBridge streamBridge;
|
||||||
|
|
||||||
@RequestMapping("/send")
|
@RequestMapping("/send1")
|
||||||
public String send() {
|
public String send1() {
|
||||||
supplier.get();
|
streamBridge.send("send1", new Date());
|
||||||
return "success";
|
return "success1";
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping("/send2")
|
||||||
|
public String send2() {
|
||||||
|
streamBridge.send("send2", LocalDateTime.now().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
|
||||||
|
return "success2";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,10 +2,6 @@ package top.fjy8018.producer;
|
|||||||
|
|
||||||
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.Supplier;
|
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
public class ProducerApplication {
|
public class ProducerApplication {
|
||||||
@@ -13,9 +9,4 @@ public class ProducerApplication {
|
|||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(ProducerApplication.class, args);
|
SpringApplication.run(ProducerApplication.class, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
|
||||||
public Supplier<Date> source1() {
|
|
||||||
return () -> new Date();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,10 +7,10 @@ spring:
|
|||||||
cloud:
|
cloud:
|
||||||
stream:
|
stream:
|
||||||
bindings:
|
bindings:
|
||||||
source1-out-0:
|
send1:
|
||||||
destination: test1
|
destination: test2
|
||||||
function:
|
send2:
|
||||||
definition: source1
|
destination: test3
|
||||||
|
|
||||||
|
|
||||||
server:
|
server:
|
||||||
|
|||||||
Reference in New Issue
Block a user