add order command query for test in project and add consumer kfka for test event driven read model design pattern
dont forget change implementation of kafka consumer to list of values
This commit is contained in:
@ -0,0 +1,33 @@
|
||||
package com.example.mmad.testapp.command;
|
||||
|
||||
import com.example.mmad.testapp.entity.OrderEntity;
|
||||
import com.example.mmad.testapp.event.OrderCreatedEvent;
|
||||
import com.example.mmad.testapp.repository.UserRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class OrderCommandHandler {
|
||||
@Autowired
|
||||
private ApplicationEventPublisher applicationEventPublisher;
|
||||
private final UserRepository userRepository;
|
||||
|
||||
public OrderCommandHandler(UserRepository userRepository) {
|
||||
this.userRepository = userRepository;
|
||||
}
|
||||
|
||||
public void createUser(CreateOrderCommand createUserCommand) {
|
||||
OrderEntity orderEntity = new OrderEntity();
|
||||
orderEntity.setId(createUserCommand.getOrderId());
|
||||
orderEntity.setOrderName(createUserCommand.getOrderName());
|
||||
orderEntity.setDescription(createUserCommand.getDescription());
|
||||
// userRepository.save(orderEntity);
|
||||
OrderCreatedEvent event = new OrderCreatedEvent(
|
||||
orderEntity.getId(),
|
||||
orderEntity.getOrderName(),
|
||||
orderEntity.getDescription()
|
||||
);
|
||||
applicationEventPublisher.publishEvent(event);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user