-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: mongoDB 추가 확인 - 차후 필요 없는 것들 삭제할 예정 * detailnfoUpdateConsumer 변경 전 커밋 - 세부정보 저장할 때, rdb의 데이터를 가져옴 - dto로 변경한 다음 mongoDB로 저장 * feat: mysql의 데이터를 mongoDB로 옮기는 consumer 추가 - 새로운 토픽을 두어 update와 분리
- Loading branch information
Showing
28 changed files
with
298 additions
and
65 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
29 changes: 29 additions & 0 deletions
29
app/src/main/java/org/healthmap/app/controller/TestController.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,29 @@ | ||
package org.healthmap.app.controller; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.healthmap.db.mongodb.model.MedicalFacility; | ||
import org.healthmap.db.mongodb.repository.MedicalFacilityMongoRepository; | ||
import org.healthmap.db.mysql.model.MedicalFacilityEntity; | ||
import org.healthmap.db.mysql.repository.MedicalFacilityMysqlRepository; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
// mongoDB 적용 되는지 확인용 controller | ||
@RestController | ||
@RequiredArgsConstructor | ||
public class TestController { | ||
private final MedicalFacilityMongoRepository medicalFacilityMongoRepository; | ||
private final MedicalFacilityMysqlRepository medicalFacilityMysqlRepository; | ||
|
||
@GetMapping("/mongo/test2") | ||
public void contentTest2() { | ||
MedicalFacilityEntity testEntity = medicalFacilityMysqlRepository.findById("JDQ4MTAxMiM1MSMkMiMkMCMkMDAkMzgxMTkxIzExIyQxIyQ3IyQ5MiQzNjEwMDIjNTEjJDEjJDIjJDgz").orElse(null); | ||
MedicalFacility medicalFacility = MedicalFacility.of(testEntity.getId(), testEntity.getName(), testEntity.getAddress(), testEntity.getPhoneNumber(), testEntity.getUrl(), | ||
testEntity.getType(), testEntity.getState(), testEntity.getCity(), testEntity.getTown(), testEntity.getPostNumber(), testEntity.getCoordinate(), | ||
testEntity.getParking(), testEntity.getParkingEtc(), testEntity.getTreatmentMon(), testEntity.getTreatmentTue(), testEntity.getTreatmentWed(), | ||
testEntity.getTreatmentThu(), testEntity.getTreatmentFri(), testEntity.getTreatmentSat(), testEntity.getTreatmentSun(), testEntity.getReceiveWeek(), | ||
testEntity.getReceiveSat(), testEntity.getLunchWeek(), testEntity.getLunchSat(), testEntity.getNoTreatmentSun(), testEntity.getNoTreatmentHoliday(), | ||
testEntity.getEmergencyDay(), testEntity.getEmergencyNight(), testEntity.getCreatedAt(), testEntity.getUpdatedAt()); | ||
medicalFacilityMongoRepository.save(medicalFacility); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.healthmap.dto; | ||
|
||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
public class FacilityIdDto { | ||
private String id; | ||
|
||
public FacilityIdDto(String id) { | ||
this.id = id; | ||
} | ||
} |
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
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
55 changes: 55 additions & 0 deletions
55
consumer/src/main/java/org/healthmap/service/MySqlToMongoConsumer.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,55 @@ | ||
package org.healthmap.service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.kafka.clients.consumer.ConsumerRecord; | ||
import org.healthmap.db.mongodb.model.MedicalFacility; | ||
import org.healthmap.db.mongodb.repository.MedicalFacilityMongoRepository; | ||
import org.healthmap.db.mysql.model.MedicalFacilityEntity; | ||
import org.healthmap.db.mysql.repository.MedicalFacilityMysqlRepository; | ||
import org.healthmap.dto.FacilityIdDto; | ||
import org.springframework.kafka.annotation.KafkaListener; | ||
import org.springframework.kafka.core.KafkaTemplate; | ||
import org.springframework.kafka.support.Acknowledgment; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
@Slf4j | ||
@Service | ||
@RequiredArgsConstructor | ||
public class MySqlToMongoConsumer { | ||
private final KafkaTemplate<String, String> kafkaTemplate; | ||
private final MedicalFacilityMysqlRepository medicalFacilityMysqlRepository; | ||
private final MedicalFacilityMongoRepository medicalFacilityMongoRepository; | ||
private final AtomicInteger count = new AtomicInteger(0); | ||
|
||
|
||
@KafkaListener(topics = "${kafka-config.consumer.migration-topic}", | ||
groupId = "${kafka-config.consumer.migration-groupId}", | ||
containerFactory = "facilityIdContainerFactory") | ||
public void mysqlToMongo(ConsumerRecord<String, FacilityIdDto> consumerRecord, Acknowledgment ack) { | ||
String id = consumerRecord.value().getId(); | ||
MedicalFacilityEntity medicalFacilityEntity = medicalFacilityMysqlRepository.findById(id).orElse(null); | ||
|
||
if (medicalFacilityEntity != null) { | ||
MedicalFacility medicalFacility = convertEntityToDocument(medicalFacilityEntity); | ||
medicalFacilityMongoRepository.save(medicalFacility); | ||
count.incrementAndGet(); | ||
if (count.get() != 0 && count.get() % 100 == 0) { | ||
log.info("migration count : {}", count.get()); | ||
} | ||
ack.acknowledge(); | ||
} | ||
kafkaTemplate.send("finished", id); | ||
} | ||
|
||
private MedicalFacility convertEntityToDocument(MedicalFacilityEntity entity) { | ||
return MedicalFacility.of(entity.getId(), entity.getName(), entity.getAddress(), entity.getPhoneNumber(), entity.getUrl(), | ||
entity.getType(), entity.getState(), entity.getCity(), entity.getTown(), entity.getPostNumber(), entity.getCoordinate(), | ||
entity.getParking(), entity.getParkingEtc(), entity.getTreatmentMon(), entity.getTreatmentTue(), entity.getTreatmentWed(), | ||
entity.getTreatmentThu(), entity.getTreatmentFri(), entity.getTreatmentSat(), entity.getTreatmentSun(), | ||
entity.getReceiveWeek(), entity.getReceiveSat(), entity.getLunchWeek(), entity.getLunchSat(), entity.getNoTreatmentSun(), | ||
entity.getNoTreatmentHoliday(), entity.getEmergencyDay(), entity.getEmergencyNight(), entity.getCreatedAt(), entity.getUpdatedAt()); | ||
} | ||
} |
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
73 changes: 73 additions & 0 deletions
73
db/src/main/java/org/healthmap/db/mongodb/model/MedicalFacility.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,73 @@ | ||
package org.healthmap.db.mongodb.model; | ||
|
||
import jakarta.persistence.Id; | ||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import org.locationtech.jts.geom.Point; | ||
import org.springframework.data.mongodb.core.geo.GeoJsonPoint; | ||
import org.springframework.data.mongodb.core.index.GeoSpatialIndexType; | ||
import org.springframework.data.mongodb.core.index.GeoSpatialIndexed; | ||
import org.springframework.data.mongodb.core.mapping.Document; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@Getter | ||
@AllArgsConstructor(access = AccessLevel.PROTECTED) | ||
@NoArgsConstructor | ||
@Document(collection = "medicalFacility") | ||
public class MedicalFacility { | ||
@Id | ||
private String id; | ||
private String name; | ||
private String address; | ||
private String phoneNumber; | ||
private String url; | ||
private String type; | ||
private String state; | ||
private String city; | ||
private String town; | ||
private String postNumber; | ||
|
||
@GeoSpatialIndexed(type = GeoSpatialIndexType.GEO_2DSPHERE) // 지리적 인덱스 | ||
private GeoJsonPoint coordinate; // MongoDB의 GeoJSON Point 타입 | ||
|
||
private String parking; | ||
private String parkingEtc; | ||
private String treatmentMon; | ||
private String treatmentTue; | ||
private String treatmentWed; | ||
private String treatmentThu; | ||
private String treatmentFri; | ||
private String treatmentSat; | ||
private String treatmentSun; | ||
private String receiveWeek; | ||
private String receiveSat; | ||
private String lunchWeek; | ||
private String lunchSat; | ||
private String noTreatmentSun; | ||
private String noTreatmentHoliday; | ||
private String emergencyDay; | ||
private String emergencyNight; | ||
private LocalDateTime createdAt; | ||
private LocalDateTime updatedAt; | ||
|
||
public static MedicalFacility of(String id, String name, String address, String phoneNumber, String url, String type, String state, String city, | ||
String town, String postNumber, Point coordinate, String parking, String parkingEtc, String treatmentMon, | ||
String treatmentTue, String treatmentWed, String treatmentThu, String treatmentFri, String treatmentSat, | ||
String treatmentSun, String receiveWeek, String receiveSat, String lunchWeek, String lunchSat, | ||
String noTreatmentSun, String noTreatmentHoliday, String emergencyDay, String emergencyNight, | ||
LocalDateTime createdAt, LocalDateTime updatedAt | ||
) { | ||
GeoJsonPoint newCoordinate = new GeoJsonPoint(coordinate.getX(), coordinate.getY()); | ||
|
||
return new MedicalFacility( | ||
id, name, address, phoneNumber, url, type, state, city, town, | ||
postNumber, newCoordinate, parking, parkingEtc, treatmentMon, treatmentTue, | ||
treatmentWed, treatmentThu, treatmentFri, treatmentSat, treatmentSun, | ||
receiveWeek, receiveSat, lunchWeek, lunchSat, noTreatmentSun, | ||
noTreatmentHoliday, emergencyDay, emergencyNight, createdAt, updatedAt | ||
); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
db/src/main/java/org/healthmap/db/mongodb/repository/MedicalFacilityMongoRepository.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 org.healthmap.db.mongodb.repository; | ||
|
||
import org.healthmap.db.mongodb.model.MedicalFacility; | ||
import org.springframework.data.mongodb.repository.MongoRepository; | ||
|
||
public interface MedicalFacilityMongoRepository extends MongoRepository<MedicalFacility, String> { | ||
} |
4 changes: 3 additions & 1 deletion
4
...lthmap/db/medicalfacility/BaseEntity.java → .../healthmap/db/mysql/model/BaseEntity.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
2 changes: 1 addition & 1 deletion
2
...edicalfacility/MedicalFacilityEntity.java → ...db/mysql/model/MedicalFacilityEntity.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
2 changes: 1 addition & 1 deletion
2
...lity/CustomMedicalFacilityRepository.java → ...tory/CustomMedicalFacilityRepository.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package org.healthmap.db.medicalfacility; | ||
package org.healthmap.db.mysql.repository; | ||
|
||
import java.util.List; | ||
|
||
|
Oops, something went wrong.