This commit is contained in:
parent
d4302250f6
commit
588af78122
10
build.gradle
10
build.gradle
@ -36,17 +36,19 @@ repositories {
|
|||||||
mavenLocal()
|
mavenLocal()
|
||||||
jcenter()
|
jcenter()
|
||||||
maven { url 'https://kotlin.bintray.com/ktor' }
|
maven { url 'https://kotlin.bintray.com/ktor' }
|
||||||
|
maven {
|
||||||
|
url 'https://repo.maven.apache.org/maven2'
|
||||||
|
name 'Maven Central'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile 'org.postgresql:postgresql:42.2.23'
|
compile 'org.postgresql:postgresql:42.2.23'
|
||||||
compile 'org.jetbrains.exposed:exposed-core:0.32.1'
|
compile 'org.jetbrains.exposed:exposed-core:0.33.1'
|
||||||
compile 'org.jetbrains.exposed:exposed-dao:0.32.1'
|
compile 'org.jetbrains.exposed:exposed-dao:0.33.1'
|
||||||
compile 'org.jetbrains.exposed:exposed-jdbc:0.33.1'
|
compile 'org.jetbrains.exposed:exposed-jdbc:0.33.1'
|
||||||
compile 'org.jetbrains.exposed:exposed-java-time:0.33.1'
|
compile 'org.jetbrains.exposed:exposed-java-time:0.33.1'
|
||||||
compile 'com.rabbitmq:amqp-client:5.13.0'
|
|
||||||
compile 'com.zaxxer:HikariCP:5.0.0'
|
compile 'com.zaxxer:HikariCP:5.0.0'
|
||||||
compile 'com.viartemev:the-white-rabbit:0.0.5'
|
|
||||||
implementation "org.koin:koin-ktor:$koin_version"
|
implementation "org.koin:koin-ktor:$koin_version"
|
||||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
|
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
|
||||||
implementation "io.ktor:ktor-server-netty:$ktor_version"
|
implementation "io.ktor:ktor-server-netty:$ktor_version"
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package com.kmalbz
|
package com.kmalbz
|
||||||
|
|
||||||
import com.kmalbz.api.route.OutputServiceRDBServer
|
import com.kmalbz.api.route.OutputServiceRDBServer
|
||||||
import com.kmalbz.consumer.DatabaseConsumer
|
|
||||||
import io.ktor.application.*
|
import io.ktor.application.*
|
||||||
import io.ktor.response.*
|
import io.ktor.response.*
|
||||||
import io.ktor.routing.*
|
import io.ktor.routing.*
|
||||||
@ -11,9 +10,6 @@ import io.ktor.features.*
|
|||||||
import org.apache.http.HttpException
|
import org.apache.http.HttpException
|
||||||
import com.kmalbz.database.DatabaseFactory
|
import com.kmalbz.database.DatabaseFactory
|
||||||
import com.kmalbz.database.dao.SampleObjects
|
import com.kmalbz.database.dao.SampleObjects
|
||||||
import com.rabbitmq.client.*
|
|
||||||
import com.typesafe.config.ConfigFactory
|
|
||||||
import io.ktor.config.HoconApplicationConfig
|
|
||||||
import io.ktor.util.*
|
import io.ktor.util.*
|
||||||
import org.jetbrains.exposed.sql.SchemaUtils
|
import org.jetbrains.exposed.sql.SchemaUtils
|
||||||
import org.jetbrains.exposed.sql.transactions.transaction
|
import org.jetbrains.exposed.sql.transactions.transaction
|
||||||
@ -39,24 +35,6 @@ fun Application.module() {
|
|||||||
SchemaUtils.create(SampleObjects)
|
SchemaUtils.create(SampleObjects)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
val appConfig = HoconApplicationConfig(ConfigFactory.load())
|
|
||||||
val factory = ConnectionFactory()
|
|
||||||
factory.host = appConfig.property("ktor.mq.host").getString()
|
|
||||||
factory.username = appConfig.property("ktor.mq.username").getString()
|
|
||||||
factory.password = appConfig.property("ktor.mq.password").getString()
|
|
||||||
|
|
||||||
val connection = factory.newConnection()
|
|
||||||
val channel = connection.createChannel()
|
|
||||||
|
|
||||||
val rabbitExchangeName = appConfig.property("ktor.mq.exchange").getString()
|
|
||||||
|
|
||||||
channel.exchangeDeclare(rabbitExchangeName, BuiltinExchangeType.DIRECT)
|
|
||||||
val queueName = channel.queueDeclare().queue
|
|
||||||
channel.queueBind(queueName, rabbitExchangeName, "")
|
|
||||||
|
|
||||||
channel.basicConsume(queueName, true, DatabaseConsumer())
|
|
||||||
|
|
||||||
routing {
|
routing {
|
||||||
install(StatusPages) {
|
install(StatusPages) {
|
||||||
exception<HttpException> {
|
exception<HttpException> {
|
||||||
|
@ -1,37 +0,0 @@
|
|||||||
package com.kmalbz.consumer
|
|
||||||
|
|
||||||
import com.google.gson.Gson
|
|
||||||
import com.kmalbz.api.model.ApiObject
|
|
||||||
import com.kmalbz.database.service.SampleObjectService
|
|
||||||
import com.rabbitmq.client.AMQP.BasicProperties
|
|
||||||
import com.rabbitmq.client.Consumer
|
|
||||||
import com.rabbitmq.client.Envelope
|
|
||||||
import com.rabbitmq.client.ShutdownSignalException
|
|
||||||
import io.ktor.util.*
|
|
||||||
|
|
||||||
@KtorExperimentalAPI
|
|
||||||
class DatabaseConsumer : Consumer {
|
|
||||||
private val sampleObjectService = SampleObjectService()
|
|
||||||
|
|
||||||
private val gson = Gson()
|
|
||||||
override fun handleConsumeOk(consumerTag : String?) {
|
|
||||||
}
|
|
||||||
override fun handleCancelOk(p0 : String?) {
|
|
||||||
throw UnsupportedOperationException()
|
|
||||||
}
|
|
||||||
override fun handleRecoverOk(p0 : String?) {
|
|
||||||
throw UnsupportedOperationException()
|
|
||||||
}
|
|
||||||
override fun handleCancel(p0 : String?) {
|
|
||||||
throw UnsupportedOperationException()
|
|
||||||
}
|
|
||||||
override fun handleDelivery(consumerTag : String?, envelope : Envelope?, basicProperties : BasicProperties?, body : ByteArray?) {
|
|
||||||
val rawJson = body!!.toString(Charsets.UTF_8)
|
|
||||||
val apiObject = gson.fromJson(rawJson, ApiObject::class.java)
|
|
||||||
|
|
||||||
sampleObjectService.addOne(apiObject)
|
|
||||||
}
|
|
||||||
override fun handleShutdownSignal(p0 : String?, p1 : ShutdownSignalException?) {
|
|
||||||
println("got shutdown signal")
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user