16
16
17
17
package org .springframework .cloud .stream .binder .rabbit .deployer ;
18
18
19
+ import java .util .function .Consumer ;
19
20
import java .util .function .Function ;
20
21
21
22
import org .springframework .boot .SpringApplication ;
22
23
import org .springframework .boot .autoconfigure .SpringBootApplication ;
24
+ import org .springframework .boot .autoconfigure .condition .ConditionalOnProperty ;
25
+ import org .springframework .cloud .function .context .FunctionProperties ;
26
+ import org .springframework .cloud .stream .function .StreamBridge ;
23
27
import org .springframework .context .annotation .Bean ;
28
+ import org .springframework .core .env .Environment ;
29
+ import org .springframework .messaging .Message ;
30
+ import org .springframework .messaging .rsocket .RSocketRequester ;
31
+ import org .springframework .messaging .support .MessageBuilder ;
24
32
25
33
26
34
/**
32
40
@ SpringBootApplication
33
41
public class RabbitDeployer {
34
42
43
+ /*
44
+ * SpringApplication.run(RabbitDeployer.class,
45
+ "--spring.cloud.function.definition=reverseFunction",
46
+ "--spring.cloud.function.location=/bootjar-1.0.0.RELEASE-exec.jar",
47
+ "--spring.cloud.function.function-class=function.example.ReverseFunction"
48
+ );
49
+ */
35
50
public static void main (String [] args ) {
36
- SpringApplication .run (RabbitDeployer .class ,
37
- //target/it/bootjar/target/bootjar-1.0.0.RELEASE-exec.jar
38
- "--spring.cloud.function.definition=reverseFunction;echo" ,
39
- "--spring.cloud.function.location=/Users/ozhurakousky/dev/repo/spring-cloud-function/spring-cloud-function-deployer/target/it/bootjar/target/bootjar-1.0.0.RELEASE-exec.jar" ,
40
- "--spring.cloud.function.function-class=function.example.ReverseFunction" );
51
+ SpringApplication .run (RabbitDeployer .class );
41
52
}
42
53
43
-
44
54
@ Bean
45
- public Function <String , String > echo () {
46
- // java -jar timesource-kafka.jar
47
-
48
- // java -jar rabbit-bundle.jar -Dspring.cloud.function.location=.....jar
49
- // java -jar rabbit-kafka-bundle.jar -Dspring.cloud.function.location=.....jar
55
+ @ ConditionalOnProperty (name = FunctionProperties .PREFIX + ".rsocket.enabled" , matchIfMissing = true )
56
+ public Function <Message <byte []>, Message <byte []>> gateway (StreamBridge bridge ) {
57
+ return message -> {
58
+ String destinationName = (String ) message .getHeaders ().get ("target_destination" );
59
+ bridge .send (destinationName , message );
60
+ return MessageBuilder .withPayload ("Successfully sent to reverseFunction-in-0" .getBytes ()).build ();
61
+ };
62
+ }
50
63
51
- // java -jar rabbit-rsocket-bundle.jar = GATEWAY
52
- return v -> v ;
64
+ /*
65
+ * Just like any other stream bean. This one will subscribe to broker destination (using regular stream mechanisms)
66
+ * and using some configuration provided by the user will propagate message to remote (rsocket) subscriber
67
+ */
68
+ @ Bean
69
+ @ ConditionalOnProperty (name = FunctionProperties .PREFIX + ".rsocket.enabled" , matchIfMissing = true )
70
+ public Consumer <Message <byte []>> delegatingConsumer (RSocketRequester .Builder rsocketRequesterBuilder , Environment environment ) {
71
+ String host = environment .getProperty ("spring.cloud.function.rsocket.subscriber.host" );
72
+ String port = environment .getProperty ("spring.cloud.function.rsocket.subscriber.port" );
73
+ return message -> {
74
+ // rsocketRequesterBuilder.tcp("host", Integer.valueOf(port))
75
+ // .route("pojoToString")
76
+ // .data(message)
77
+ // .retrieveMono(String.class);
78
+ };
53
79
}
54
80
55
81
// Step-1 - rabbit-bundle.jar(time) | rabbit-bundle.jar(log) - Step One - local
@@ -59,6 +85,4 @@ public Function<String, String> echo() {
59
85
60
86
//http | rabbit-rsocket-bundle.jar(producer) | python | rabbit-rsocket-bundle.jar(consumer) | rabbit-bundle.jar(log)
61
87
62
- //http => pyjon
63
-
64
88
}
0 commit comments