Skip to content

Commit

Permalink
refactor: get userinfo 메시지 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
happysoy authored and kor-Chipmunk committed Feb 20, 2024
1 parent fb34b74 commit 025f5cf
Show file tree
Hide file tree
Showing 26 changed files with 633 additions and 0 deletions.
6 changes: 6 additions & 0 deletions chart-batch.iml
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>
6 changes: 6 additions & 0 deletions chart-consumer.iml
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>
26 changes: 26 additions & 0 deletions src/backend/chart-server/chart-batch/build.gradle.kts
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")
}
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)
}
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 {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.lalala.chart.batch.job

class SimpleJobConfig(
val jobBuilderFactor
) {
}
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()
}
}
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:-}]"
25 changes: 25 additions & 0 deletions src/backend/chart-server/chart-consumer/build.gradle.kts
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")
}
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)
}
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 {
}
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
}
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()
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)
}
}
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>
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)
}
}
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:-}]"
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,
)
}
}
}
5 changes: 5 additions & 0 deletions src/backend/chart-server/infra/00_scheme.sql
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;
Loading

0 comments on commit 025f5cf

Please sign in to comment.