Compare commits
2 Commits
788b636196
...
0809386bc3
Author | SHA1 | Date | |
---|---|---|---|
0809386bc3 | |||
2eb23dd9a6 |
@ -1,9 +1,20 @@
|
||||
plugins {
|
||||
application
|
||||
kotlin("jvm") version "1.5.10"
|
||||
kotlin("plugin.serialization") version "1.5.10"
|
||||
id("com.github.johnrengelman.shadow") version "7.0.0"
|
||||
}
|
||||
|
||||
buildscript {
|
||||
repositories { mavenCentral() }
|
||||
|
||||
dependencies {
|
||||
val kotlinVersion = "1.5.10"
|
||||
classpath(kotlin("gradle-plugin", version = kotlinVersion))
|
||||
classpath(kotlin("serialization", version = kotlinVersion))
|
||||
}
|
||||
}
|
||||
|
||||
application {
|
||||
mainClassName = "MainKt"
|
||||
}
|
||||
@ -20,13 +31,14 @@ dependencies {
|
||||
implementation("com.rabbitmq:amqp-client:5.13.0")
|
||||
implementation("com.viartemev:the-white-rabbit:0.0.6")
|
||||
implementation("com.zaxxer:HikariCP:5.0.0")
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.2.2")
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.2.1")
|
||||
implementation("org.jetbrains.exposed:exposed-core:0.33.1")
|
||||
implementation("org.jetbrains.exposed:exposed-dao:0.33.1")
|
||||
implementation("org.jetbrains.exposed:exposed-jdbc:0.33.1")
|
||||
implementation("org.jetbrains.exposed:exposed-java-time:0.33.1")
|
||||
implementation("io.insert-koin:koin-core:3.1.2")
|
||||
implementation("org.postgresql:postgresql:42.2.23")
|
||||
implementation("com.google.code.gson:gson:2.8.7")
|
||||
}
|
||||
|
||||
tasks {
|
||||
|
@ -1,8 +1,9 @@
|
||||
package api
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class ApiObject(
|
||||
@SerializedName("tag") val tag: String,
|
||||
@SerializedName("probability") val probability: Double
|
||||
val tag: String,
|
||||
val probability: Double
|
||||
)
|
@ -2,12 +2,12 @@ package database.dao
|
||||
|
||||
import org.jetbrains.exposed.dao.id.IntIdTable
|
||||
import org.jetbrains.exposed.sql.*
|
||||
import org.jetbrains.exposed.sql.`java-time`.date
|
||||
import java.time.LocalDate
|
||||
import org.jetbrains.exposed.sql.`java-time`.datetime
|
||||
import java.time.LocalDateTime
|
||||
|
||||
object ResultObjects : IntIdTable() {
|
||||
val tag: Column<String> = varchar("tag", 32)
|
||||
val date: Column<LocalDate> = date("date").default(LocalDate.now())
|
||||
val date: Column<LocalDateTime> = datetime("date").default(LocalDateTime.now())
|
||||
val probability: Column<Double> = double("probability")
|
||||
override val primaryKey = PrimaryKey(id, name = "PK_ResultObject_Id")
|
||||
}
|
@ -1,14 +1,8 @@
|
||||
package database.service
|
||||
|
||||
import database.DatabaseFactory.dbQuery
|
||||
import database.model.ResultObject
|
||||
import database.dao.ResultObjects
|
||||
import api.ApiObject
|
||||
import org.jetbrains.exposed.sql.ResultRow
|
||||
import org.jetbrains.exposed.sql.select
|
||||
import org.jetbrains.exposed.sql.selectAll
|
||||
import org.jetbrains.exposed.sql.transactions.transaction
|
||||
import java.time.LocalDate
|
||||
|
||||
class ResultObjectService : IResultObjectService {
|
||||
|
||||
|
@ -1,15 +1,15 @@
|
||||
package mq
|
||||
|
||||
import api.ApiObject
|
||||
import com.google.gson.Gson
|
||||
import com.rabbitmq.client.*
|
||||
import database.service.IResultObjectService
|
||||
import kotlinx.serialization.decodeFromString
|
||||
import kotlinx.serialization.json.Json
|
||||
import org.koin.core.component.KoinComponent
|
||||
import org.koin.core.component.inject
|
||||
|
||||
class DatabaseConsumer(channel: Channel): Consumer, KoinComponent {
|
||||
private val resultObjectService : IResultObjectService by inject()
|
||||
private val gson = Gson()
|
||||
private val basicChannel = channel
|
||||
override fun handleConsumeOk(consumerTag : String?) {
|
||||
}
|
||||
@ -30,7 +30,7 @@ class DatabaseConsumer(channel: Channel): Consumer, KoinComponent {
|
||||
override fun handleDelivery(consumerTag : String?, envelope : Envelope?, basicProperties : AMQP.BasicProperties?, body : ByteArray?) {
|
||||
try {
|
||||
val rawJson = body!!.toString(Charsets.UTF_8)
|
||||
val apiObject = gson.fromJson(rawJson, ApiObject::class.java)
|
||||
val apiObject = Json.decodeFromString<ApiObject>(rawJson)
|
||||
resultObjectService.addOne(apiObject)
|
||||
basicChannel.basicAck(envelope!!.deliveryTag, false)
|
||||
} catch (e: Exception) {
|
||||
|
Loading…
Reference in New Issue
Block a user