forked from microservices-patterns/ftgo-application
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConsumerServiceCommandHandlers.java
33 lines (27 loc) · 1.28 KB
/
ConsumerServiceCommandHandlers.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package net.chrisrichardson.ftgo.consumerservice.domain;
import io.eventuate.tram.commands.consumer.CommandHandlers;
import io.eventuate.tram.commands.consumer.CommandMessage;
import io.eventuate.tram.messaging.common.Message;
import io.eventuate.tram.sagas.participant.SagaCommandHandlersBuilder;
import net.chrisrichardson.ftgo.consumerservice.api.ValidateOrderByConsumer;
import org.springframework.beans.factory.annotation.Autowired;
import static io.eventuate.tram.commands.consumer.CommandHandlerReplyBuilder.withFailure;
import static io.eventuate.tram.commands.consumer.CommandHandlerReplyBuilder.withSuccess;
public class ConsumerServiceCommandHandlers {
@Autowired
private ConsumerService consumerService;
public CommandHandlers commandHandlers() {
return SagaCommandHandlersBuilder
.fromChannel("consumerService")
.onMessage(ValidateOrderByConsumer.class, this::validateOrderForConsumer)
.build();
}
private Message validateOrderForConsumer(CommandMessage<ValidateOrderByConsumer> cm) {
try {
consumerService.validateOrderForConsumer(cm.getCommand().getConsumerId(), cm.getCommand().getOrderTotal());
return withSuccess();
} catch (ConsumerVerificationFailedException e) {
return withFailure();
}
}
}