-
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.
- Loading branch information
1 parent
fb34b74
commit 025f5cf
Showing
26 changed files
with
633 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<module version="4"> | ||
<component name="SonarLintModuleSettings"> | ||
<option name="uniqueId" value="08a87256-dfa8-461d-aafd-306d30a7463e" /> | ||
</component> | ||
</module> |
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,6 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<module version="4"> | ||
<component name="SonarLintModuleSettings"> | ||
<option name="uniqueId" value="1a31534e-6a15-4859-9a41-633f832e34f5" /> | ||
</component> | ||
</module> |
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,26 @@ | ||
tasks.getByName("bootJar") { | ||
enabled = true | ||
} | ||
|
||
dependencies { | ||
implementation(project(":common-module:common")) | ||
implementation(project(":common-module:common-mvc")) | ||
|
||
// Kotlin Libraries | ||
implementation("com.fasterxml.jackson.module:jackson-module-kotlin") | ||
implementation("org.jetbrains.kotlin:kotlin-reflect") | ||
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") | ||
|
||
// Spring | ||
testImplementation("org.springframework.boot:spring-boot-starter-test") | ||
|
||
// Spring Batch | ||
implementation("org.springframework.boot:spring-boot-starter-batch") | ||
testImplementation("org.springframework.batch:spring-batch-test") | ||
|
||
// Spring JPA | ||
implementation("org.springframework.boot:spring-boot-starter-data-jpa") | ||
|
||
// MySQL | ||
runtimeOnly("com.mysql:mysql-connector-j") | ||
} |
11 changes: 11 additions & 0 deletions
11
.../chart-server/chart-batch/src/main/kotlin/com/lalala/chart/batch/ChartBatchApplication.kt
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,11 @@ | ||
package com.lalala.chart.batch; | ||
|
||
import org.springframework.boot.autoconfigure.SpringBootApplication | ||
import org.springframework.boot.runApplication | ||
|
||
@SpringBootApplication | ||
class ChartBatchApplication | ||
|
||
fun main(args: Array<String>) { | ||
runApplication<ChartBatchApplication>(*args) | ||
} |
7 changes: 7 additions & 0 deletions
7
...end/chart-server/chart-batch/src/main/kotlin/com/lalala/chart/batch/config/BatchConfig.kt
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.lalala.chart.batch.config | ||
|
||
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing | ||
|
||
@EnableBatchProcessing | ||
class BatchConfig { | ||
} |
6 changes: 6 additions & 0 deletions
6
...nd/chart-server/chart-batch/src/main/kotlin/com/lalala/chart/batch/job/SimpleJobConfig.kt
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,6 @@ | ||
package com.lalala.chart.batch.job | ||
|
||
class SimpleJobConfig( | ||
val jobBuilderFactor | ||
) { | ||
} |
35 changes: 35 additions & 0 deletions
35
.../chart-server/chart-batch/src/main/kotlin/com/lalala/chart/batch/tasklet/SimpleTasklet.kt
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,35 @@ | ||
package com.lalala.chart.batch.tasklet | ||
|
||
import org.springframework.batch.core.Job | ||
import org.springframework.batch.core.Step | ||
import org.springframework.batch.core.StepContribution | ||
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory | ||
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory | ||
import org.springframework.batch.core.scope.context.ChunkContext | ||
import org.springframework.batch.repeat.RepeatStatus | ||
import org.springframework.context.annotation.Bean | ||
import org.springframework.context.annotation.Configuration | ||
|
||
@Configuration | ||
class SimpleTasklet( | ||
private val jobBuilderFactory: JobBuilderFactory, | ||
private val stepBuilderFactory: StepBuilderFactory | ||
) { | ||
|
||
@Bean | ||
fun singleStepJob(): Job { | ||
return jobBuilderFactory["singleStepJob"] | ||
.start(singleStep()) | ||
.build() | ||
} | ||
|
||
@Bean | ||
fun singleStep(): Step { | ||
return stepBuilderFactory["singleStep"] | ||
.tasklet { _: StepContribution, _: ChunkContext -> | ||
log.info { "Single Step!!" } | ||
RepeatStatus.FINISHED | ||
} | ||
.build() | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/backend/chart-server/chart-batch/src/main/resources/application.yml
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,38 @@ | ||
server: | ||
port: 27000 | ||
|
||
spring: | ||
application: | ||
name: chart-batch-server | ||
|
||
datasource: | ||
driver-class-name: com.mysql.cj.jdbc.Driver | ||
url: "jdbc:mysql://localhost:27100/chart?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&serverTimezone=Asia/Seoul" | ||
username: root | ||
password: admin | ||
|
||
jpa: | ||
database-platform: org.hibernate.dialect.MySQLDialect | ||
hibernate: | ||
ddl-auto: validate | ||
properties: | ||
dialect: org.hibernate.dialect.MySQLDialect | ||
hibernate: | ||
format_sql: true | ||
show_sql: true | ||
use_sql_comments: true | ||
|
||
management: | ||
tracing: | ||
sampling: | ||
probability: 1.0 | ||
propagation: | ||
consume: [b3, w3c] | ||
produce: [b3, w3c] | ||
zipkin: | ||
tracing: | ||
endpoint: "http://localhost:43000/api/v2/spans" | ||
|
||
logging: | ||
pattern: | ||
level: "%5p [%X{traceId:-},%X{spanId:-}]" |
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,25 @@ | ||
tasks.getByName("bootJar") { | ||
enabled = true | ||
} | ||
|
||
dependencies { | ||
implementation(project(":common-module:common")) | ||
implementation(project(":common-module:common-mvc")) | ||
|
||
// Kotlin | ||
implementation("org.jetbrains.kotlin:kotlin-reflect") | ||
|
||
// Spring | ||
implementation("org.springframework.boot:spring-boot-starter") | ||
testImplementation("org.springframework.boot:spring-boot-starter-test") | ||
|
||
// Spring Kafka | ||
implementation("org.springframework.kafka:spring-kafka") | ||
testImplementation("org.springframework.kafka:spring-kafka-test") | ||
|
||
// Spring JPA | ||
implementation("org.springframework.boot:spring-boot-starter-data-jpa") | ||
|
||
// MySQL | ||
runtimeOnly("com.mysql:mysql-connector-j") | ||
} |
16 changes: 16 additions & 0 deletions
16
...rver/chart-consumer/src/main/kotlin/com/lalala/chart/consumer/ChartConsumerApplication.kt
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,16 @@ | ||
package com.lalala.chart.consumer; | ||
|
||
import com.lalala.config.KafkaConsumerConfig | ||
import org.springframework.boot.autoconfigure.SpringBootApplication | ||
import org.springframework.boot.runApplication | ||
import org.springframework.context.annotation.Import | ||
|
||
@Import( | ||
KafkaConsumerConfig::class, | ||
) | ||
@SpringBootApplication | ||
class ChartBatchApplication | ||
|
||
fun main(args: Array<String>) { | ||
runApplication<ChartBatchApplication>(*args) | ||
} |
9 changes: 9 additions & 0 deletions
9
...art-consumer/src/main/kotlin/com/lalala/chart/consumer/config/JpaAuditingConfiguration.kt
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,9 @@ | ||
package com.lalala.chart.consumer.config | ||
|
||
import org.springframework.context.annotation.Configuration | ||
import org.springframework.data.jpa.repository.config.EnableJpaAuditing | ||
|
||
@Configuration | ||
@EnableJpaAuditing | ||
class JpaAuditingConfiguration { | ||
} |
21 changes: 21 additions & 0 deletions
21
...-server/chart-consumer/src/main/kotlin/com/lalala/chart/consumer/entity/BaseTimeEntity.kt
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,21 @@ | ||
package com.lalala.chart.consumer.entity | ||
|
||
import jakarta.persistence.Column | ||
import jakarta.persistence.EntityListeners | ||
import jakarta.persistence.MappedSuperclass | ||
import org.springframework.data.annotation.CreatedDate | ||
import org.springframework.data.annotation.LastModifiedDate | ||
import org.springframework.data.jpa.domain.support.AuditingEntityListener | ||
import java.time.LocalDateTime | ||
|
||
@EntityListeners(AuditingEntityListener::class) | ||
@MappedSuperclass | ||
abstract class BaseTimeEntity { | ||
@CreatedDate | ||
@Column(name = "created_at", insertable = false, updatable = false) | ||
private var createdAt: LocalDateTime? = null | ||
|
||
@LastModifiedDate | ||
@Column(name = "updated_at", insertable = false, updatable = false) | ||
private var updatedAt: LocalDateTime? = null | ||
} |
13 changes: 13 additions & 0 deletions
13
...rt-server/chart-consumer/src/main/kotlin/com/lalala/chart/consumer/entity/StreamingLog.kt
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,13 @@ | ||
package com.lalala.chart.consumer.entity | ||
|
||
import jakarta.persistence.Column | ||
import jakarta.persistence.GeneratedValue | ||
import jakarta.persistence.Id | ||
|
||
data class StreamingLog( | ||
@Id | ||
@GeneratedValue | ||
val id: Long = 0, | ||
@Column(nullable = false) | ||
val musicId: Long, | ||
) : BaseTimeEntity() |
20 changes: 20 additions & 0 deletions
20
...er/chart-consumer/src/main/kotlin/com/lalala/chart/consumer/listener/StreamingListener.kt
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,20 @@ | ||
package com.lalala.chart.consumer.listener | ||
|
||
import com.lalala.chart.consumer.service.StreamingLogService | ||
import com.lalala.event.StreamingCompleteEvent | ||
import org.springframework.kafka.annotation.KafkaListener | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class StreamingListener( | ||
val service: StreamingLogService | ||
) { | ||
@KafkaListener( | ||
topics = ["streaming_complete"], | ||
groupId = "\${spring.kafka.consumer.group-id}", | ||
containerFactory = "kafkaListenerContainerFactory" | ||
) | ||
fun consumeStreamingComplete(event: StreamingCompleteEvent) { | ||
service.create(event.musicId) | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
...t-consumer/src/main/kotlin/com/lalala/chart/consumer/repository/StreamingLogRepository.kt
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,6 @@ | ||
package com.lalala.chart.consumer.repository | ||
|
||
import com.lalala.chart.consumer.entity.StreamingLog | ||
import org.springframework.data.jpa.repository.JpaRepository | ||
|
||
interface StreamingLogRepository : JpaRepository<StreamingLog, Long> |
17 changes: 17 additions & 0 deletions
17
...r/chart-consumer/src/main/kotlin/com/lalala/chart/consumer/service/StreamingLogService.kt
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,17 @@ | ||
package com.lalala.chart.consumer.service | ||
|
||
import com.lalala.chart.consumer.entity.StreamingLog | ||
import com.lalala.chart.consumer.repository.StreamingLogRepository | ||
import org.springframework.transaction.annotation.Transactional | ||
|
||
class StreamingLogService( | ||
val repository: StreamingLogRepository | ||
) { | ||
@Transactional | ||
fun create(musicId: Long): StreamingLog { | ||
val log = StreamingLog( | ||
musicId = musicId | ||
) | ||
return repository.save(log) | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
src/backend/chart-server/chart-consumer/src/main/resources/application.yml
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,45 @@ | ||
server: | ||
port: 27500 | ||
|
||
spring: | ||
application: | ||
name: chart-consumer-server | ||
|
||
kafka: | ||
bootstrap-servers: localhost:40000,localhost:40001,localhost:40002 | ||
|
||
consumer: | ||
group-id: chart-service | ||
auto-offset-reset: latest | ||
|
||
datasource: | ||
driver-class-name: com.mysql.cj.jdbc.Driver | ||
url: "jdbc:mysql://localhost:27100/chart?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&serverTimezone=Asia/Seoul" | ||
username: root | ||
password: admin | ||
|
||
jpa: | ||
database-platform: org.hibernate.dialect.MySQLDialect | ||
hibernate: | ||
ddl-auto: validate | ||
properties: | ||
dialect: org.hibernate.dialect.MySQLDialect | ||
hibernate: | ||
format_sql: true | ||
show_sql: true | ||
use_sql_comments: true | ||
|
||
management: | ||
tracing: | ||
sampling: | ||
probability: 1.0 | ||
propagation: | ||
consume: [b3, w3c] | ||
produce: [b3, w3c] | ||
zipkin: | ||
tracing: | ||
endpoint: "http://localhost:43000/api/v2/spans" | ||
|
||
logging: | ||
pattern: | ||
level: "%5p [%X{traceId:-},%X{spanId:-}]" |
29 changes: 29 additions & 0 deletions
29
...hart-consumer/src/test/kotlin/com/lalala/chart/consumer/listener/StreamingListenerTest.kt
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 com.lalala.chart.consumer.listener | ||
|
||
import com.lalala.event.StreamingCompleteEvent | ||
import org.junit.jupiter.api.Test | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.boot.test.context.SpringBootTest | ||
import org.springframework.kafka.test.context.EmbeddedKafka | ||
|
||
|
||
@SpringBootTest | ||
@EmbeddedKafka | ||
internal class EventConsumerTest { | ||
@Autowired | ||
private val eventConsumer: StreamingListener? = null | ||
|
||
@Test | ||
fun consumePaintCreatedEvent() { | ||
val event: StreamingCompleteEvent = generatedEvent() | ||
eventConsumer?.consumeStreamingComplete(event) | ||
} | ||
|
||
companion object { | ||
private fun generatedEvent(): StreamingCompleteEvent { | ||
return StreamingCompleteEvent( | ||
1L, | ||
) | ||
} | ||
} | ||
} |
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,5 @@ | ||
CREATE DATABASE IF NOT EXISTS chart | ||
DEFAULT CHARACTER SET utf8 | ||
DEFAULT COLLATE utf8_general_ci; | ||
|
||
USE chart; |
Oops, something went wrong.