-
Notifications
You must be signed in to change notification settings - Fork 0
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
6f990ea
commit 17b989e
Showing
10 changed files
with
161 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
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
70 changes: 70 additions & 0 deletions
70
src/main/kotlin/com/hero/alignlab/client/WebClientFactory.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,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
10
src/main/kotlin/com/hero/alignlab/client/fcm/PushService.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,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, | ||
) { | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/kotlin/com/hero/alignlab/client/fcm/client/FcmClient.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,4 @@ | ||
package com.hero.alignlab.client.fcm.client | ||
|
||
interface FcmClient { | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/kotlin/com/hero/alignlab/client/fcm/client/ReactiveFcmClient.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.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
32
src/main/kotlin/com/hero/alignlab/client/fcm/config/FcmConfig.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,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 | ||
) |
3 changes: 3 additions & 0 deletions
3
src/main/kotlin/com/hero/alignlab/client/fcm/model/FcmModel.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,3 @@ | ||
package com.hero.alignlab.client.fcm.model | ||
|
||
|
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