Skip to content

Commit 891cc8f

Browse files
author
Daniel Bustamante Ospina
committed
Merge remote-tracking branch 'origin/master'
2 parents de22a43 + 36dd8bd commit 891cc8f

File tree

1 file changed

+49
-2
lines changed

1 file changed

+49
-2
lines changed

README.md

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,53 @@ Example Code:
148148
}
149149
```
150150

151+
### Direct Commands
151152

152-
## Disclaimer
153-
This Alpha version is a first development version intended for initial internal use with direct support from the developer of this module, so use with so much care.
153+
```java
154+
package org.reactivecommons.async.api;
155+
156+
import org.reactivecommons.api.domain.Command;
157+
import reactor.core.publisher.Mono;
158+
159+
public interface DirectAsyncGateway {
160+
<T> Mono<Void> sendCommand(Command<T> command, String targetName);
161+
<T, R> Mono<R> requestReply(AsyncQuery<T> query, String targetName, Class<R> type);
162+
}
163+
```
164+
165+
#### Command Type
166+
167+
```java
168+
package org.reactivecommons.api.domain;
169+
170+
public class Command<T> {
171+
private final String name;
172+
private final String commandId;
173+
private final T data;
174+
}
175+
```
176+
177+
#### Send Commands
178+
179+
180+
```java
181+
private static final String REGISTER_MEMBER = "Members.registerMember";
182+
private static final String TARGET = "Members";
183+
private DirectAsyncGateway asyncGateway;
184+
185+
public Mono<Void> registerMember(Member member){
186+
String uuid = UUID.randomUUID().toString();
187+
return asyncGateway.sendCommand(new Command<>(REGISTER_MEMBER, uuid, member), TARGET);
188+
}
189+
```
190+
191+
#### Handle Commands
192+
```java
193+
private static final String REGISTER_MEMBER = "Members.registerMember";
194+
195+
@Bean
196+
public HandlerRegistry commandHandlers(MembersRegistryUseCase useCase) {
197+
return HandlerRegistry.register()
198+
.handleCommand(REGISTER_MEMBER, useCase::registerMember, Member.class);
199+
}
200+
```

0 commit comments

Comments
 (0)