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