Skip to content

Instantly share code, notes, and snippets.

@JohnChangUK
JohnChangUK / .java
Created January 9, 2021 13:50
EventConsumer
public interface EventConsumer<T extends Event> {
void consumeEvent(T event);
}
@JohnChangUK
JohnChangUK / .java
Created January 9, 2021 13:48
EventHandler
public interface EventHandler<T extends Event, R extends Event> {
R handleEvent(T event);
}
@JohnChangUK
JohnChangUK / .java
Last active January 9, 2021 14:26
OrderPurchaseEventHandler
@Component
public class OrderPurchaseEventHandler implements EventHandler<OrderPurchaseEvent, PaymentEvent> {
private final UserRepository userRepository;
@Autowired
public OrderPurchaseEventHandler(UserRepository userRepository) {
this.userRepository = userRepository;
}
@JohnChangUK
JohnChangUK / .java
Last active January 4, 2021 13:11
TransactionEventConsumer
public void consumeEvent(TransactionEvent event) {
Mono.fromRunnable(
() -> orderPurchaseRepository.findById(event.getOrderId())
.ifPresent(order -> {
setStatus(event, order);
orderPurchaseRepository.save(order);
}))
.subscribeOn(jdbcScheduler)
.subscribe();
}
@JohnChangUK
JohnChangUK / .java
Last active January 4, 2021 13:10
PaymentEventHandler
public TransactionEvent handleEvent(PaymentEvent event) {
Mono.fromRunnable(() -> transactionRepository.save(
new Transaction()
.setOrderId(event.getOrderId())
.setPrice(event.getPrice())))
.subscribeOn(jdbcScheduler)
.subscribe();
return new TransactionEvent()
.orderId(event.getOrderId())
@JohnChangUK
JohnChangUK / .java
Last active January 4, 2021 12:28
Create OrderPurchaseEvent
@Component
public class OrderPurchaseProcessor {
private final Sinks.Many<OrderPurchaseEvent> sink;
@Autowired
public OrderPurchaseProcessor(Sinks.Many<OrderPurchaseEvent> sink) {
this.sink = sink;
}

Keybase proof

I hereby claim:

  • I am JohnChangUK on github.
  • I am johnchang94 (https://keybase.io/johnchang94) on keybase.
  • I have a public key whose fingerprint is 295E 4B4B 6709 C7AB 5A63 0A35 51CA 56A1 EFC4 DEC2

To claim this, I am signing this object: