Skip to content

Commit

Permalink
feat: fcm client config
Browse files Browse the repository at this point in the history
  • Loading branch information
DongGeon0908 committed Jul 13, 2024
1 parent 6f990ea commit 17b989e
Show file tree
Hide file tree
Showing 10 changed files with 161 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,18 @@ jobs:
# Encrypt 환경 변수 주입
encrypt.key: ${{ secrets.encrypt.key }}
encrypt.algorithm: ${{ secrets.encrypt.algorithm }}
# FCM 환경 변수 주입
push.fcm.type: ${{ secrets.push.fcm.type }}
push.fcm.project-id: ${{ secrets.push.fcm.project-id }}
push.fcm.private-key-id: ${{ secrets.push.fcm.private-key-id }}
push.fcm.private-key: ${{ secrets.push.fcm.private-key }}
push.fcm.client-email: ${{ secrets.push.fcm.client-email }}
push.fcm.client-id: ${{ secrets.push.fcm.client-id }}
push.fcm.auth-uri: ${{ secrets.push.fcm.auth-uri }}
push.fcm.token-uri: ${{ secrets.push.fcm.token-uri }}
push.fcm.auth-provider-x509-cert-url: ${{ secrets.push.fcm.auth-provider-x509-cert-url }}
push.fcm.client-x509-cert-url: ${{ secrets.push.fcm.client-x509-cert-url }}
push.fcm.universe-domain: ${{ secrets.push.fcm.universe-domain }}

# gradlew 파일 실행권한 설정
- name: Grant execute permission for gradlew
Expand Down
3 changes: 3 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ dependencies {
/** jwt */
implementation("com.auth0:java-jwt:${DependencyVersion.AUTH_JWT}")

/** fcm */
implementation("com.google.firebase:firebase-admin:${DependencyVersion.FCM_ADMIN}")

/** test */
testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("io.projectreactor:reactor-test")
Expand Down
3 changes: 3 additions & 0 deletions buildSrc/src/main/kotlin/DependencyVersion.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ object DependencyVersion {
/** auth0-jwt */
const val AUTH_JWT = "4.4.0"

/** fcm */
const val FCM_ADMIN = "9.3.0"

/** test */
const val TEST_CONTAINER_MYSQL = "1.19.8"
const val P6SPY_LOG = "1.9.1"
Expand Down
70 changes: 70 additions & 0 deletions src/main/kotlin/com/hero/alignlab/client/WebClientFactory.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package com.hero.alignlab.client

import io.netty.channel.ChannelOption
import io.netty.handler.timeout.ReadTimeoutHandler
import io.netty.handler.timeout.WriteTimeoutHandler
import org.springframework.http.client.reactive.ClientHttpConnector
import org.springframework.http.client.reactive.ReactorClientHttpConnector
import org.springframework.web.reactive.function.client.WebClient
import reactor.netty.Connection
import reactor.netty.http.client.HttpClient
import java.util.concurrent.TimeUnit

class WebClientFactory {
companion object {
fun generate(
baseUrl: String? = null,
connectionTimeoutMillis: Int = 1000,
readTimeoutMillis: Long = 1000,
writeTimeoutMillis: Long = 1000,
): WebClient {
val clientHttpConnector = createFactory(
connectionTimeoutMillis = connectionTimeoutMillis,
readTimeoutMillis = readTimeoutMillis,
writeTimeoutMillis = writeTimeoutMillis
)

val webClient = WebClient.builder()

if (baseUrl != null) {
webClient.baseUrl(baseUrl)
}

return webClient
.codecs { it.defaultCodecs().enableLoggingRequestDetails(true) }
.clientConnector(clientHttpConnector)
.build()
}

private fun createFactory(
connectionTimeoutMillis: Int,
readTimeoutMillis: Long,
writeTimeoutMillis: Long,
): ClientHttpConnector {
val httpClient = httpClient(
connectionTimeoutMillis = connectionTimeoutMillis,
readTimeoutMillis = readTimeoutMillis,
writeTimeoutMillis = writeTimeoutMillis
)

return ReactorClientHttpConnector(httpClient)
}

private fun httpClient(
connectionTimeoutMillis: Int,
readTimeoutMillis: Long,
writeTimeoutMillis: Long,
): HttpClient {
return HttpClient.create()
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, connectionTimeoutMillis)
.doOnConnected { connection: Connection ->
connection
.addHandlerLast(ReadTimeoutHandler(readTimeoutMillis, TimeUnit.MILLISECONDS))
.addHandlerLast(WriteTimeoutHandler(writeTimeoutMillis, TimeUnit.MILLISECONDS))
}.apply {
this.warmup().block()
this.compress(true)
}
}
}
}
10 changes: 10 additions & 0 deletions src/main/kotlin/com/hero/alignlab/client/fcm/PushService.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.hero.alignlab.client.fcm

import com.hero.alignlab.client.fcm.client.FcmClient
import org.springframework.stereotype.Service

@Service
class PushService(
private val fcmClient: FcmClient,
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.hero.alignlab.client.fcm.client

interface FcmClient {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.hero.alignlab.client.fcm.client

import com.hero.alignlab.client.fcm.config.FcmProperties
import io.github.oshai.kotlinlogging.KotlinLogging

class ReactiveFcmClient(fcmProperties: FcmProperties) : FcmClient {
private val logger = KotlinLogging.logger {}

}
32 changes: 32 additions & 0 deletions src/main/kotlin/com/hero/alignlab/client/fcm/config/FcmConfig.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.hero.alignlab.client.fcm.config

import com.hero.alignlab.client.fcm.client.FcmClient
import com.hero.alignlab.client.fcm.client.ReactiveFcmClient
import org.springframework.boot.context.properties.ConfigurationProperties
import org.springframework.boot.context.properties.EnableConfigurationProperties
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration

@Configuration
@EnableConfigurationProperties(FcmProperties::class)
class FcmConfig {
@Bean
fun fcmClient(fcmProperties: FcmProperties): FcmClient {
return ReactiveFcmClient(fcmProperties)
}
}

@ConfigurationProperties(prefix = "push.fcm")
data class FcmProperties(
val type: String,
val projectId: String,
val privateKeyId: String,
val privateKey: String,
val clientEmail: String,
val clientId: String,
val authUri: String,
val tokenUri: String,
val authProviderX509CertUrl: String,
val clientX509CertUrl: String,
val universeDomain: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.hero.alignlab.client.fcm.model


15 changes: 15 additions & 0 deletions src/main/resources/config/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,18 @@ auth:
encrypt:
key:
algorithm:

push:
fcm:
type:
project-id:
private-key-id:
private-key:
client-email:
client-id:
auth-uri:
token-uri:
auth-provider-x509-cert-url:
client-x509-cert-url:
universe-domain:

0 comments on commit 17b989e

Please sign in to comment.