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

[kafka] If you believe this class is safe to deserialize, please provide its name. If the serialization is only done by a trusted source, you can also enable trust all #7

Open
saechimdaeki opened this issue Mar 12, 2024 · 0 comments
Labels

Comments

@saechimdaeki
Copy link
Owner

문제발생

서버 A와 서버 B의 Payload 모델 규격은 동일한 상황에서 서버 A에서 카프카 브로커에 메시지를 produce했을때 서버B에서
payload 모델을 consume했는데 다음과 같은 에러가 발생

If you believe this class is safe to deserialize, please provide its name. If the serialization is only done by a trusted source, you can also enable trust all (*)

발생 원인 :

카프카 메세지를 deserialize 할 때 헤더의 값에 패키지명이 포함되어 있다.

즉, producer와 consumer에서 같은 동일 모델을 payload로 사용한다 해도 패키지명이 달라서 생겼던 이슈

해결방법은 3가지가 있다.

  1. 먼저 가장 간단하게는 패키지명 또한 통일한다
  2. 헤더 검사를 실행하지 않겠다는 옵션을 consumerfactory 빈 설정에 추가한다
public ConsumerFactory<String, KafkaPayloadModel> originConsumerFactory() {
       return new DefaultKafkaConsumerFactory<>(createPropMap(),
                                                new StringDeserializer(),
                                                new JsonDeserializer<>(KafkaPayloadModel.class,false));
   }
  1. 모든 패키지를 신뢰하겠다는 옵션을 준다
public ConsumerFactory<String, KafkaPayloadModel> originConsumerFactory() {
    JsonDeserializer<KafkaPayloadModel> kafkaPayloadModelJsonDeserializer = new JsonDeserializer<>(KafkaPayloadModel.class);
    kafkaPayloadModelJsonDeserializer.addTrustedPackages("*");
 
    return new DefaultKafkaConsumerFactory<>(createPropMap(),
                                             new StringDeserializer(),
                                             kafkaPayloadModelJsonDeserializer);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant