Skip to content
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

Conversation

HyunSu1768
Copy link
Member

@HyunSu1768 HyunSu1768 commented Sep 21, 2023

close #ENTRY-26

νšŒμ›νƒˆν‡΄ μ‹œ Kafka delete-user 토픽에 λ©”μ‹œμ§€λ₯Ό λ°œν–‰ν•©λ‹ˆλ‹€.

λ‹€λ₯Έ μ„œλΉ„μŠ€μ—μ„œ ν•΄λ‹Ή 토픽에 μžˆλŠ” λ©”μ‹œμ§€λ₯Ό consume ν•˜μ—¬ status, entryinfoλ₯Ό μ‚­μ œν•˜λŠ” λ‘œμ§μ„ μˆ˜ν–‰ν•˜λ„λ‘ λ‘œμ§μ„ ꡬ성해야 ν•©λ‹ˆλ‹€.

그리고 Topic 에 λŒ€ν•΄μ„œ Replica, Partition 의 개수λ₯Ό μ‹€μ œ ν™˜κ²½μ—μ„œ Kafka ν΄λŸ¬μŠ€ν„° ꡬ좕을 ν•œ λ’€ 더 μžμ„Ένžˆ μ„€μ •ν•  κ³„νšμž…λ‹ˆλ‹€.

TEST

Screenshot 2023-09-21 at 9 42 13 AM

νšŒμ›νƒˆν‡΄ μ‹œ delete-user 토픽에 μœ μ €IDλ₯Ό ν¬ν•¨ν•œ λ©”μ‹œμ§€κ°€ λ°œν–‰λ©λ‹ˆλ‹€.

@linear
Copy link

linear bot commented Sep 21, 2023

ENTRY-26 μœ μ € νšŒμ› νƒˆν‡΄ API 개발

  • μœ μ € νšŒμ› νƒˆν‡΄ API 개발
    • νšŒμ› νƒˆν‡΄μ‹œ νšŒμ› νƒˆν‡΄ 이벀트 λ°œν–‰

@HyunSu1768 HyunSu1768 added the κΈ°λŠ₯ μΆ”κ°€ New feature or request label Sep 21, 2023
val user = userFacade.getCurrentUser()
userRepository.deleteById(user.id)
deleteUserKafkaTemplate.send(KafkaTopics.DELETE_USER, DeleteUserEventRequest(user.id))
}
Copy link
Member

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())
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Service처럼 각 상황별 KafkaProducer(ex: DeleteUserProducer)클래슀 μ•ˆμ— KafkaConfig의 kafkaTemplate.sendλ₯Ό μ‚¬μš©μ‹œν‚€λ©΄ 쒋을 것 κ°™μŒ.
  2. λ‚΄κ°€ μ•ŒκΈ°λ‘  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;
    }
}

Copy link
Member Author

@HyunSu1768 HyunSu1768 Sep 21, 2023

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
    }

Copy link
Member

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 γ„²

@HyunSu1768 HyunSu1768 merged commit 258b212 into develop Sep 21, 2023
1 check passed
@HyunSu1768 HyunSu1768 deleted the feature/entry-26-μœ μ €-νšŒμ›-νƒˆν‡΄-api-개발 branch September 21, 2023 09:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
κΈ°λŠ₯ μΆ”κ°€ New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants