-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: 카프카 추가 및 연동
- Loading branch information
Showing
14 changed files
with
444 additions
and
201 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
linknamu/src/main/java/com/kakao/linknamu/core/kafka/consumer/GoogleDocsConsumer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.kakao.linknamu.core.kafka.consumer; | ||
|
||
import static com.kakao.linknamu.core.util.KafkaTopics.*; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.kafka.annotation.KafkaListener; | ||
import org.springframework.stereotype.Service; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.kakao.linknamu.bookmark.entity.Bookmark; | ||
import com.kakao.linknamu.bookmark.service.BookmarkService; | ||
import com.kakao.linknamu.thirdparty.googledocs.entity.GooglePage; | ||
import com.kakao.linknamu.thirdparty.googledocs.util.GoogleDocsProvider; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
@Service | ||
public class GoogleDocsConsumer { | ||
private final BookmarkService bookmarkService; | ||
private final ObjectMapper om; | ||
private final GoogleDocsProvider googleDocsProvider; | ||
|
||
@KafkaListener(topics = {GOOGLE_DOCS_TOPIC}, groupId = "group-id-linknamu") | ||
public void googleDocsConsumer(String message) throws JsonProcessingException { | ||
GooglePage googlePage = om.readValue(message, GooglePage.class); | ||
List<Bookmark> bookmarkList = googleDocsProvider.getLinks(googlePage); | ||
bookmarkService.batchInsertBookmark(bookmarkList); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
linknamu/src/main/java/com/kakao/linknamu/core/kafka/consumer/NotionConsumer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.kakao.linknamu.core.kafka.consumer; | ||
|
||
import static com.kakao.linknamu.core.util.KafkaTopics.*; | ||
|
||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
|
||
import org.json.simple.JSONArray; | ||
import org.json.simple.JSONObject; | ||
import org.json.simple.parser.JSONParser; | ||
import org.springframework.beans.factory.ObjectProvider; | ||
import org.springframework.http.HttpEntity; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.HttpMethod; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.kafka.annotation.KafkaListener; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.web.client.HttpClientErrorException; | ||
import org.springframework.web.client.RestTemplate; | ||
import org.yaml.snakeyaml.parser.ParserException; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.kakao.linknamu.bookmark.entity.Bookmark; | ||
import com.kakao.linknamu.bookmark.service.BookmarkService; | ||
import com.kakao.linknamu.category.entity.Category; | ||
import com.kakao.linknamu.core.util.JsoupResult; | ||
import com.kakao.linknamu.core.util.JsoupUtils; | ||
import com.kakao.linknamu.thirdparty.notion.dto.NotionKafkaReqeusetDto; | ||
import com.kakao.linknamu.thirdparty.notion.entity.NotionPage; | ||
import com.kakao.linknamu.thirdparty.notion.repository.NotionPageJpaRepository; | ||
import com.kakao.linknamu.thirdparty.notion.util.InvalidNotionApiException; | ||
import com.kakao.linknamu.thirdparty.notion.util.NotionApiUriBuilder; | ||
import com.kakao.linknamu.thirdparty.notion.util.NotionProvider; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Slf4j | ||
@RequiredArgsConstructor | ||
@Service | ||
public class NotionConsumer { | ||
private final BookmarkService bookmarkService; | ||
private final ObjectMapper om; | ||
private final NotionProvider notionProvider; | ||
|
||
|
||
@KafkaListener(topics = {NOTION_TOPIC}, groupId = "group-id-linknamu") | ||
public void notionConsumer(String message) throws JsonProcessingException { | ||
NotionKafkaReqeusetDto requsetDto = om.readValue(message, NotionKafkaReqeusetDto.class); | ||
|
||
List<Bookmark> bookmarkList = notionProvider.getPageLinks( | ||
requsetDto.pageId(), | ||
requsetDto.accessToken(), | ||
requsetDto.categoryId() | ||
); | ||
bookmarkService.batchInsertBookmark(bookmarkList); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
linknamu/src/main/java/com/kakao/linknamu/core/util/KafkaTopics.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.kakao.linknamu.core.util; | ||
|
||
public class KafkaTopics { | ||
public static final String GOOGLE_DOCS_TOPIC = "google_docs"; | ||
public static final String NOTION_TOPIC = "notion"; | ||
public static final String KAKAO_TOPIC = "kakao"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.