You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/asciidoc/api-guide.adoc
+59-22Lines changed: 59 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,8 +7,8 @@ This section describes the reactive API for producing and consuming messages usi
7
7
There are three main classes in Reactive Commons:
8
8
9
9
. `HandlerRegistry` for listening to events and commands messages and for registering their respective handlers.
10
-
. `DomainEventBus` for emiting events to an event bus
11
-
. `DirectAsyncGateway` for emiting commands to an event bus
10
+
. `DomainEventBus` for emiting events to an event bus
11
+
. `DirectAsyncGateway` for emiting commands to an event bus
12
12
13
13
The project uses https://github.com/reactor/reactor-core[Reactor Core] to expose a https://github.com/reactive-streams/reactive-streams-jvm["Reactive Streams"] API.
14
14
@@ -92,12 +92,12 @@ public class MainApplication {
public ManageTasksUseCase manageTasksUseCase(TaskToDoRepository tasks, DomainEventBus eventBus) {
98
98
return new ManageTasksUseCase(tasks, eventBus);
99
-
}
100
-
99
+
}
100
+
101
101
}
102
102
--------
103
103
@@ -160,9 +160,9 @@ public class AnyUseCase {
160
160
}
161
161
--------
162
162
163
-
The second parameter for sendCommand method is the name of the target component for that command, It's the name stablished in the properties file of Spring "application.properties" in the "spring.application.name" field.
163
+
The second parameter for sendCommand method is the name of the target component for that command, It's the name stablished in the properties file of Spring "application.properties" in the "spring.application.name" field.
164
164
165
-
[NOTE]
165
+
[NOTE]
166
166
you don't need this parameter in the emit method of DomainEventBus class, because an event is a fact for cero or more subscribers.
167
167
168
168
==== DirectAsyncGateway - Request/Reply
@@ -194,15 +194,15 @@ Inbound messages are listened from an event bus using `HandlerRegistry` class. T
194
194
@SpringBootApplication
195
195
@EnableMessageListeners
196
196
public class MainApplication {
197
-
...
197
+
...
198
198
}
199
199
--------
200
200
201
201
The HandlerRegistry implements builder patter, so each time you use some method, it will return a HanlderRegistry object. HanlderRegistry has the following methods:
The return type of the QueryHandlerDelegate should be Void
323
+
324
+
This second interface allows the request / reply pattern not to have to be resolved in the same flow. For example,
325
+
when the execution of a task is requested, and it can be processed by a group of workers, who leave the result in a database. There is another group of workers who are in charge of listening to the changes in the database and responding to that request. In this scenario, the process who receives the request is not the same process who responds to it. That is the usage scenario for QueryHandlerDelegate:
When the report creation task is completed, the process responsible of responding should call the reply method of DirectAsyncGateway passing the from object like this:
336
+
337
+
[source,java]
338
+
--------
339
+
gateway.reply(response, from)
340
+
--------
304
341
305
342
TIP: Remember HandlerRegistry use builder pattern, So, you can build a chain of listener for each message:
306
343
@@ -316,9 +353,9 @@ public class SomeConfigurationClass {
0 commit comments