Compare commits
1 Commits
main
...
publish-ev
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
798bc9fc47 |
@@ -0,0 +1,32 @@
|
|||||||
|
package com.food.order.domain;
|
||||||
|
|
||||||
|
import com.food.order.domain.event.publisher.DomainEventPublisher;
|
||||||
|
import com.food.order.system.domain.event.OrderCreatedEvent;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.BeansException;
|
||||||
|
import org.springframework.context.ApplicationContext;
|
||||||
|
import org.springframework.context.ApplicationContextAware;
|
||||||
|
import org.springframework.context.ApplicationEventPublisher;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@Slf4j
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class ApplicationDomainEventPublisher implements
|
||||||
|
ApplicationContextAware,
|
||||||
|
DomainEventPublisher<OrderCreatedEvent> {
|
||||||
|
|
||||||
|
private final ApplicationEventPublisher applicationEventPublisher;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void publish(OrderCreatedEvent event) {
|
||||||
|
this.applicationEventPublisher.publishEvent(event);
|
||||||
|
log.info("publish order created event with id : {}", event.getOrder().getId().getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -29,6 +29,8 @@ public class OrderCreateCommandHandler {
|
|||||||
private final RestaurantRepository restaurantRepository;
|
private final RestaurantRepository restaurantRepository;
|
||||||
private final OrderDataMapper orderDataMapper;
|
private final OrderDataMapper orderDataMapper;
|
||||||
|
|
||||||
|
private final ApplicationDomainEventPublisher applicationDomainEventPublisher;
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public CreateOrderResponse createOrder(CreateOrderCommand createOrderCommand) {
|
public CreateOrderResponse createOrder(CreateOrderCommand createOrderCommand) {
|
||||||
log.info("createOrder: {}", createOrderCommand);
|
log.info("createOrder: {}", createOrderCommand);
|
||||||
@@ -38,6 +40,7 @@ public class OrderCreateCommandHandler {
|
|||||||
var createdEventOrder = orderDomainService.validateAndInitiateOrder(order, restaurant);
|
var createdEventOrder = orderDomainService.validateAndInitiateOrder(order, restaurant);
|
||||||
var savedOrder = saveOrder(order);
|
var savedOrder = saveOrder(order);
|
||||||
log.info("createOrder with id: {}", savedOrder.getId().getValue());
|
log.info("createOrder with id: {}", savedOrder.getId().getValue());
|
||||||
|
applicationDomainEventPublisher.publish(createdEventOrder);
|
||||||
return orderDataMapper.orderToCreateOrderResponse(savedOrder,"Order created successfully");
|
return orderDataMapper.orderToCreateOrderResponse(savedOrder,"Order created successfully");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package com.food.order.domain;
|
||||||
|
|
||||||
|
import com.food.order.domain.ports.output.message.publisher.payment.OrderCreatedPaymentRequestMessagePublisher;
|
||||||
|
import com.food.order.system.domain.event.OrderCreatedEvent;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.transaction.event.TransactionalEventListener;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Component
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class OrderCreatedEventApplicationListener {
|
||||||
|
|
||||||
|
private final OrderCreatedPaymentRequestMessagePublisher orderCreatedPaymentRequestMessagePublisher;
|
||||||
|
|
||||||
|
@TransactionalEventListener
|
||||||
|
public void process(OrderCreatedEvent event) {
|
||||||
|
orderCreatedPaymentRequestMessagePublisher.publish(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user