-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
π :: (ENTRY-26) User νμνν΄ API κ°λ° #9
The head ref may contain hidden characters: "feature/entry-26-\uC720\uC800-\uD68C\uC6D0-\uD0C8\uD1F4-api-\uAC1C\uBC1C"
π :: (ENTRY-26) User νμνν΄ API κ°λ° #9
Conversation
ENTRY-26 μ μ νμ νν΄ API κ°λ°
|
val user = userFacade.getCurrentUser() | ||
userRepository.deleteById(user.id) | ||
deleteUserKafkaTemplate.send(KafkaTopics.DELETE_USER, DeleteUserEventRequest(user.id)) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μν΄λ λκΈ΄ νλλ° interfaceλ‘ μΆμννκ±°λ AOPλ‘ μ μ©νλ©΄ λΉμ¦λμ€ λ‘μ§μ΄ λλ¬μμ§μ§ μμκ±° κ°μ
@Bean | ||
fun deleteUserKafkaTemplate(): KafkaTemplate<String, DeleteUserEventRequest> { | ||
return KafkaTemplate(deleteUserProducerFactory()) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Serviceμ²λΌ κ° μν©λ³ KafkaProducer(ex: DeleteUserProducer)ν΄λμ€ μμ KafkaConfigμ kafkaTemplate.sendλ₯Ό μ¬μ©μν€λ©΄ μ’μ κ² κ°μ.
- λ΄κ° μκΈ°λ‘ RequestDtoλ₯Ό λ°λ‘ μ μ‘νλκ² μλλΌ ObjectMapperλ‘ νλ² κ°μΈμ€μΌ λλκ²μΌλ‘ μ. κ·Έλμ λλμ± Producerν΄λμ€κ° λ¬Άμ΄μ£Όλ©΄ μ’μ κ² κ°μ. μλ μ½λ μ°Έκ³ νλ©΄ μ’μλ―
@Service
@Slf4j
@RequiredArgsConstructor
public class TestOrderProducer {
private final KafkaTemplate<String, String> kafkaTemplate;
public OrderDto send(String topic, OrderDto orderDto) {
ObjectMapper mapper = new ObjectMapper();
String jsonInString = "";
try {
jsonInString = mapper.writeValueAsString(orderDto);
} catch (JsonProcessingException e) {
e.printStackTrace();
}
kafkaTemplate.send(topic, jsonInString);
log.info("Kafka Producer sent data from the Order microservice: ", orderDto);
return orderDto;
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
requestdto μ μ‘νλκ² μ κΈ°μλ ν€λ°Έλ₯λ string,stringμΌλ‘ ν΄μ μ§λ ¬ν ν΄μ μ£Όλκ² κ°μλ°, μ λ λ°Έλ₯μ dtoλ₯Ό λ£μκΈ° λλ¬Έμ λ©μμ§ λ³΄λΌ λ KafkaConfigμμ μ μν΄ μ€κ² μ²λΌ μ§λ ¬ν ν΄μ£Όλ ν΄λμ€λ₯Ό μ μν΄μ μ§λ ¬ν νλλ° mapperκ° νμν κΉμ??
private fun producerConfig(): MutableMap<String, Any> {
val configs: MutableMap<String, Any> = HashMap<String, Any>()
configs[ProducerConfig.BOOTSTRAP_SERVERS_CONFIG] = kafkaProperty.serverAddress
configs[ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG] = StringSerializer::class.java
configs[ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG] = JsonSerializer::class.java
return configs
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
λ΄κ° ꡬνν λλ Serializer Config μ€μ νκ³ ObjectMapperμ¬μ©νκΈ΄ νμ΄
λλ μ ννλ λͺ°λΌμ ꡬκΈλ§μ΄λ Feedλ μ°λν΄μ μμ보μ.
νλ¨ λ λ merge γ²
close #ENTRY-26
νμνν΄ μ Kafka delete-user ν ν½μ λ©μμ§λ₯Ό λ°νν©λλ€.
λ€λ₯Έ μλΉμ€μμ ν΄λΉ ν ν½μ μλ λ©μμ§λ₯Ό consume νμ¬ status, entryinfoλ₯Ό μμ νλ λ‘μ§μ μννλλ‘ λ‘μ§μ ꡬμ±ν΄μΌ ν©λλ€.
κ·Έλ¦¬κ³ Topic μ λν΄μ Replica, Partition μ κ°μλ₯Ό μ€μ νκ²½μμ Kafka ν΄λ¬μ€ν° ꡬμΆμ ν λ€ λ μμΈν μ€μ ν κ³νμ λλ€.
TEST
νμνν΄ μ delete-user ν ν½μ μ μ IDλ₯Ό ν¬ν¨ν λ©μμ§κ° λ°νλ©λλ€.