15
15
import org .springframework .boot .test .context .SpringBootTest ;
16
16
import org .springframework .context .annotation .Bean ;
17
17
import reactor .core .publisher .Mono ;
18
- import reactor .core .publisher .UnicastProcessor ;
18
+ import reactor .core .publisher .Sinks ;
19
19
import reactor .test .StepVerifier ;
20
20
21
21
import java .time .Duration ;
@@ -36,55 +36,52 @@ class SimpleDirectCommunicationTest {
36
36
@ Value ("${spring.application.name}" )
37
37
private String appName ;
38
38
39
- @ Autowired
40
- private UnicastProcessor <Command <Long >> listener ;
41
-
42
- private String commandId = ThreadLocalRandom .current ().nextInt () + "" ;
43
- private Long data = ThreadLocalRandom .current ().nextLong ();
39
+ private final String commandId = ThreadLocalRandom .current ().nextInt () + "" ;
40
+ private final Long data = ThreadLocalRandom .current ().nextLong ();
44
41
45
42
@ Test
46
43
void commandShouldArrive () {
47
44
Command <Long > command = new Command <>(COMMAND_NAME , commandId , data );
48
45
gateway .sendCommand (command , appName ).subscribe ();
46
+ Sinks .Many <Command <Long >> listener = Sinks .many ().unicast ().onBackpressureBuffer ();
49
47
50
- StepVerifier .create (listener .next ()).assertNext (cmd -> {
48
+ StepVerifier .create (listener .asFlux (). next ()).assertNext (cmd -> {
51
49
assertThat (cmd ).extracting (Command ::getCommandId , Command ::getData , Command ::getName )
52
- .containsExactly (commandId , data , COMMAND_NAME );
50
+ .containsExactly (commandId , data , COMMAND_NAME );
53
51
}).verifyComplete ();
54
52
}
55
53
56
54
@ Test
57
55
void shouldReceiveResponse () {
58
56
final Mono <Integer > reply = gateway .requestReply (new AsyncQuery <>("double" , 42 ), appName , Integer .class );
59
57
StepVerifier .create (reply .timeout (Duration .ofSeconds (15 )))
60
- .expectNext (42 * 2 )
61
- .verifyComplete ();
58
+ .expectNext (42 * 2 )
59
+ .verifyComplete ();
62
60
}
63
61
64
-
65
62
@ SpringBootApplication
66
63
@ EnableDirectAsyncGateway
67
64
@ EnableMessageListeners
68
- static class App {
65
+ static class App {
69
66
public static void main (String [] args ) {
70
67
SpringApplication .run (App .class , args );
71
68
}
72
69
73
70
@ Bean
74
- public HandlerRegistry registry (UnicastProcessor <Command <Long >> listener ) {
71
+ public HandlerRegistry registry (Sinks . Many <Command <Long >> listener ) {
75
72
return HandlerRegistry .register ()
76
- .serveQuery ("double" , rqt -> just (rqt * 2 ), Long .class )
77
- .handleCommand (COMMAND_NAME , handle (listener ), Long .class );
73
+ .serveQuery ("double" , rqt -> just (rqt * 2 ), Long .class )
74
+ .handleCommand (COMMAND_NAME , handle (listener ), Long .class );
78
75
}
79
76
80
77
@ Bean
81
- public UnicastProcessor <Command <Long >> listener () {
82
- return UnicastProcessor . create ();
78
+ public Sinks . Many <Command <Long >> listener () {
79
+ return Sinks . many (). unicast (). onBackpressureBuffer ();
83
80
}
84
81
85
- private DomainCommandHandler <Long > handle (UnicastProcessor <Command <Long >> listener ) {
82
+ private DomainCommandHandler <Long > handle (Sinks . Many <Command <Long >> listener ) {
86
83
return command -> {
87
- listener .onNext (command );
84
+ listener .emitNext (command , Sinks . EmitFailureHandler . FAIL_FAST );
88
85
return empty ();
89
86
};
90
87
}
0 commit comments