We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
// Service Layer private final EventBus eventBus; eventBus.post(new CommentCreatedEvent(comment)); // CommentCreatedEvent는 댓글 관련 Entity public class CommentCreatedEvent { private final Id<Post, Long> postId; private final Id<User, Long> userId; private final Writer commentWriter; private final Id<Comment, Long> commentId; ... // CommentCreatedEventListener public class CommentCreateEventListener implements AutoCloseable { private final EventBus eventBus; private final PostService postService; private final KafkaTemplate<String, CommentCreatedMessage> kafkaTemplate; public CommentCreateEventListener(EventBus eventBus, PostService postService, KafkaTemplate<String, CommentCreatedMessage> kafkaTemplate) { this.eventBus = eventBus; this.postService = postService; this.kafkaTemplate = kafkaTemplate; eventBus.register(this); // 등록.. 이벤트를 구독할 수 있는 상태 } /** * EventBus를 등록하고 EventBus에 특정 Event를 발송하면 * EventBus가 그 Event를 SubScribe하고 있는 대상에게 알아서 전달해주는 역할 * 컨트롤러나 서비스가 CommentCreateEventListener에 대한 존재를 알 필요가 없이, EventBus만 바라보고 있으면 된다. * Service의 eventBus.post(new CommentCreateEvent(comment));를 통해 아래 메서드가 호출됨 */ @Subscribe public void handleCommentCreateEvent(CommentCreatedEvent event) throws Exception { Id<Post, Long> postId = event.getPostId(); // Kafka 에게 발송(send) 로직 .... } // Event Configure 설정 @Bean public EventBus eventBus(TaskExecutor eventTaskExecutor, EventExceptionHandler eventExceptionHandler) { return new AsyncEventBus(eventTaskExecutor, eventExceptionHandler); } @Bean() public CommentCreateEventListener commentCreateEventListener(EventBus eventBus, PostService postService, KafkaTemplate kafkaTemplate) { return new CommentCreateEventListener(eventBus, postService, kafkaTemplate); }
https://www.baeldung.com/guava-eventbus
The text was updated successfully, but these errors were encountered:
No branches or pull requests
BeanUtils.copyProperties()
Guava의 EventBus ... Event Driven(Comment<댓글> Event)
References
https://www.baeldung.com/guava-eventbus
The text was updated successfully, but these errors were encountered: