remove consumer
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Torma Kristóf 2021-08-12 12:19:04 +02:00
parent d4302250f6
commit 588af78122
Signed by: tormakris
GPG Key ID: DC83C4F2C41B1047
3 changed files with 6 additions and 63 deletions

View File

@ -36,17 +36,19 @@ repositories {
mavenLocal()
jcenter()
maven { url 'https://kotlin.bintray.com/ktor' }
maven {
url 'https://repo.maven.apache.org/maven2'
name 'Maven Central'
}
}
dependencies {
compile 'org.postgresql:postgresql:42.2.23'
compile 'org.jetbrains.exposed:exposed-core:0.32.1'
compile 'org.jetbrains.exposed:exposed-dao:0.32.1'
compile 'org.jetbrains.exposed:exposed-core:0.33.1'
compile 'org.jetbrains.exposed:exposed-dao:0.33.1'
compile 'org.jetbrains.exposed:exposed-jdbc: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.viartemev:the-white-rabbit:0.0.5'
implementation "org.koin:koin-ktor:$koin_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
implementation "io.ktor:ktor-server-netty:$ktor_version"

View File

@ -1,7 +1,6 @@
package com.kmalbz
import com.kmalbz.api.route.OutputServiceRDBServer
import com.kmalbz.consumer.DatabaseConsumer
import io.ktor.application.*
import io.ktor.response.*
import io.ktor.routing.*
@ -11,9 +10,6 @@ import io.ktor.features.*
import org.apache.http.HttpException
import com.kmalbz.database.DatabaseFactory
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 org.jetbrains.exposed.sql.SchemaUtils
import org.jetbrains.exposed.sql.transactions.transaction
@ -39,24 +35,6 @@ fun Application.module() {
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 {
install(StatusPages) {
exception<HttpException> {

View File

@ -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")
}
}