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
@@ -14,11 +14,11 @@ The project uses https://github.com/reactor/reactor-core[Reactor Core] to expose
14
14
15
15
=== Semantic Messages Classes
16
16
17
-
Reactice Commons has 2 classes that represent eventsor commands, it give it a semantic meaning for a message. So, let talks about DomainEvent and Command classes .
17
+
Reactice Commons has 3 classes that represent events, commands or queries, giving a semantic meaning for a message. So, let's talk about DomainEvent and Command classes .
18
18
19
19
==== DomainEvent<T>
20
20
21
-
This class let you represent a Event in the system. It accepts a generic class that will be the information to transport for that event, a eventId and a name for the event. The structure for a DomainEvent is:
21
+
:This class lets you represent a Event in the system. It accepts a generic class that will be the information to transport for that event, a eventId and a name for the event. The structure for a DomainEvent is
22
22
23
23
[source,java]
24
24
--------
@@ -42,7 +42,7 @@ public class DomainEvent<T> {
42
42
43
43
==== Command<T>
44
44
45
-
An other basic structure is the Command class. This class let you represent a Command/Request in the system. It accepts a generic class that will be the information for that command, a eventId and a name for that event. The structure for a DomainEvent is:
45
+
An other basic structure is the Command class. This class lets you represent a Command in the system. It accepts a generic class that will be the information for that command, a commandId and a name for that event. The structure for a Command is:
46
46
47
47
[source,java]
48
48
--------
@@ -61,7 +61,21 @@ public class Command<T> {
61
61
}
62
62
--------
63
63
64
-
=== Reactive Commons - Sending Events and Commands
64
+
==== AsyncQuery<T>
65
+
66
+
An other basic structure is the AsyncQuery class. This class lets you represent a Query in the system. It accepts a generic class that will be the information for that query and a name for that resoruce. The structure is:
67
+
68
+
69
+
[source,java]
70
+
--------
71
+
@Data
72
+
public class AsyncQuery<T> {
73
+
private final String resource;
74
+
private final T queryData;
75
+
}
76
+
--------
77
+
78
+
=== Reactive Commons - Sending Events, Commands and Request/Reply messages
65
79
66
80
Outbound messages are sent to an event bus using `DomainEventBus` or `DirectAsyncGateway` classes. If you are using Spring Boot, you can have a Main class like this:
The @EnableDomainEventBus annotation enable to the application to emit Events to the System. This annotation create a EnableDomainEventBus Bean, so you can use it for emit events. This interface looks like:
104
+
==== DomainEventBus
105
+
106
+
The @EnableDomainEventBus annotation enable to the application to emit Events to the System. This annotation create a EnableDomainEventBus bean, so you can use it for emitting events. This interface looks like:
90
107
91
108
[source,java]
92
109
--------
@@ -99,28 +116,209 @@ public interface DomainEventBus {
99
116
}
100
117
--------
101
118
102
-
The emit method recive a DomainEvent<T> class where you can publish information to the system. The method will respond you in a reacive way with a Publisher, like a Mono or a Flux object. So, for example, if you want to send a UserRegistered event to the system ,you have to us
103
-
119
+
The emit method recive a DomainEvent<T> class where you can publish information to the system. The method will respond you in a reacive way with a Publisher, like a mono object. So, for example, if you want to send a UserRegistered event to the system ,you can do this:
104
120
105
121
[source,java]
106
122
--------
107
123
108
124
public class AnyUseCase {
109
125
110
-
private DomainEventBus eventBus;
126
+
private DomainEventBus eventBus; // Injected
111
127
112
-
public ManageTasksUseCase( DomainEventBus eventBus) {
If you want to send Commands to the system, the @EnableDirectAsyncGateway annotation enable to the application to emit Commands to the System. This annotation create a DirectAsyncGateway bean, so you can use it for emitting commands. This interface looks like:
115
138
116
-
public Mono<TaskToDo> doSomething(String name, String description) {
The sendCommand method recive a Command<T> class where you can publish information to the system. The method will respond you in a reacive way with a Publisher, like a mono object. So, for example, if you want to send a UserRegister command to the "target.name" component ,you can do this:
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
+
165
+
[NOTE]
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
+
168
+
==== DirectAsyncGateway - Request/Reply
169
+
170
+
The DirectAsyncGateway class has another method called "requestReply", this method lets you to send a query and wait for an answer for that query. The method will respond you in a reacive way with a Publisher, like a mono object with the generic data. So, for example, if you want to send a query with QueryUser data, to the "target.name" component and recive an User object response, you can do this:
=== Reactive Commons - Listening for Events, Commands and Query messages
187
+
188
+
==== HandlerRegistry
189
+
190
+
Inbound messages are listened from an event bus using `HandlerRegistry` class. The @EnableMessageListeners annotation enable you to listen messages like Events, Commands or Queries. You have to create a HandlerRegistry object, so you can register handlers for specifc messages.
191
+
192
+
[source,java]
193
+
--------
194
+
@SpringBootApplication
195
+
@EnableMessageListeners
196
+
public class MainApplication {
197
+
...
198
+
}
199
+
--------
200
+
201
+
The HandlerRegistry implements builder patter, so each time you use some method, it will return a HanlderRegistry object. HanlderRegistry has the following methods:
202
+
203
+
* listenEvent: It lets listen for an event
204
+
* serveQuery: It lets listen for a query
205
+
* handleCommand: It lets listen for a command
206
+
207
+
===== HandlerRegistry - listenEvent
208
+
209
+
listenEvent method lets you register a handler for a specific event. It has the next signature:
0 commit comments