-
Notifications
You must be signed in to change notification settings - Fork 0
/
SpringPgmqApplication.kt
48 lines (42 loc) · 1.92 KB
/
SpringPgmqApplication.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package com.vdsirotkin.pgmq.spring
import com.fasterxml.jackson.databind.ObjectMapper
import com.vdsirotkin.pgmq.PgmqClient
import com.vdsirotkin.pgmq.config.PgmqConfiguration
import com.vdsirotkin.pgmq.config.PgmqConnectionFactory
import com.vdsirotkin.pgmq.objectMapper
import com.vdsirotkin.pgmq.serialization.JacksonPgmqSerializationProvider
import com.vdsirotkin.pgmq.serialization.PgmqSerializationProvider
import org.springframework.boot.autoconfigure.SpringBootApplication
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
import org.springframework.jdbc.datasource.DataSourceUtils
import javax.sql.DataSource
import kotlin.time.Duration.Companion.seconds
import kotlin.time.toJavaDuration
@SpringBootApplication
@EnableConfigurationProperties(PgmqConfigurationProps::class)
open class SpringPgmqApplication {
@Configuration(proxyBeanMethods = false)
open class PgmqConfig {
@Bean
open fun objectMapper() = objectMapper
@Bean
open fun pgmqConnectionFactory(dataSource: DataSource) = PgmqConnectionFactory {
DataSourceUtils.getConnection(dataSource)
}
@Bean
open fun pgmqSerializer(objectMapper: ObjectMapper) = JacksonPgmqSerializationProvider(objectMapper)
@Bean
open fun pgmqClient(
pgmqConnectionFactory: PgmqConnectionFactory,
pgmqSerializationProvider: PgmqSerializationProvider,
pgmqConfiguration: PgmqConfiguration
) = PgmqClient(pgmqConnectionFactory, pgmqSerializationProvider, pgmqConfiguration)
}
}
@ConfigurationProperties(prefix = "pgmq")
data class PgmqConfigurationProps(
override val defaultVisibilityTimeout: java.time.Duration = 30.seconds.toJavaDuration()
) : PgmqConfiguration