Compare commits
8 Commits
489bd376e3
...
master
Author | SHA1 | Date | |
---|---|---|---|
7aaa6988cd | |||
bb69905ede | |||
ce1aa81dbd | |||
13eec03d8e
|
|||
2ae6742cd5
|
|||
e4bcfab2af
|
|||
874480aadb
|
|||
1529649389
|
12
.drone.yml
12
.drone.yml
@ -30,6 +30,18 @@ steps:
|
|||||||
- latest
|
- latest
|
||||||
- ${DRONE_BUILD_NUMBER}
|
- ${DRONE_BUILD_NUMBER}
|
||||||
|
|
||||||
|
- name: dockerhub
|
||||||
|
image: plugins/docker
|
||||||
|
settings:
|
||||||
|
repo: birbnetes/${DRONE_REPO_NAME}
|
||||||
|
username:
|
||||||
|
from_secret: DOCKERHUB_USER
|
||||||
|
password:
|
||||||
|
from_secret: DOCKERHUB_PASSWORD
|
||||||
|
tags:
|
||||||
|
- latest
|
||||||
|
- ${DRONE_BUILD_NUMBER}
|
||||||
|
|
||||||
- name: ms-teams
|
- name: ms-teams
|
||||||
image: kuperiu/drone-teams
|
image: kuperiu/drone-teams
|
||||||
settings:
|
settings:
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
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"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -16,7 +17,19 @@ repositories {
|
|||||||
jcenter()
|
jcenter()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
buildscript {
|
||||||
|
repositories { mavenCentral() }
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
val kotlinVersion = "1.5.10"
|
||||||
|
classpath(kotlin("gradle-plugin", version = kotlinVersion))
|
||||||
|
classpath(kotlin("serialization", version = kotlinVersion))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.2.2")
|
||||||
|
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.2.1")
|
||||||
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")
|
||||||
@ -26,7 +39,6 @@ dependencies {
|
|||||||
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,10 +1,11 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName
|
import kotlinx.datetime.LocalDateTime
|
||||||
import java.time.LocalDate
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
|
@Serializable
|
||||||
data class ApiObject(
|
data class ApiObject(
|
||||||
@SerializedName("tag") val tag: String,
|
val tag: String,
|
||||||
@SerializedName("device_id") val device_id: Int,
|
val device_id: Int,
|
||||||
@SerializedName("device_date") val device_date: LocalDate
|
val device_date: LocalDateTime
|
||||||
)
|
)
|
@ -7,5 +7,5 @@ data class EnvConfig (
|
|||||||
var mqExchange: String = System.getenv("MQ_EXCHANGE") ?: "sample",
|
var mqExchange: String = System.getenv("MQ_EXCHANGE") ?: "sample",
|
||||||
var dbJdbc: String = System.getenv("DB_JDBC") ?: "jdbc:postgresql://localhost:5432/sample-service",
|
var dbJdbc: String = System.getenv("DB_JDBC") ?: "jdbc:postgresql://localhost:5432/sample-service",
|
||||||
var dbUsername: String = System.getenv("DB_USERNAME") ?: "sample-service",
|
var dbUsername: String = System.getenv("DB_USERNAME") ?: "sample-service",
|
||||||
var dbPassowrd: String = System.getenv("DB_PASSOWRD") ?: "sample-service"
|
var dbPassowrd: String = System.getenv("DB_PASSWORD") ?: "sample-service"
|
||||||
)
|
)
|
@ -2,13 +2,13 @@ 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`.date
|
import org.jetbrains.exposed.sql.`java-time`.datetime
|
||||||
import java.time.LocalDate
|
import java.time.LocalDateTime
|
||||||
|
|
||||||
object SampleObjects : IntIdTable() {
|
object SampleObjects : IntIdTable() {
|
||||||
val tag: Column<String> = varchar("tag", 32)
|
val tag: Column<String> = varchar("tag", 32)
|
||||||
val timestamp: Column<LocalDate> = date("timestamp").default(LocalDate.now())
|
val timestamp: Column<LocalDateTime> = datetime("timestamp").default(LocalDateTime.now())
|
||||||
val device_id: Column<Int> = integer("device_id")
|
val device_id: Column<Int> = integer("device_id")
|
||||||
val device_date: Column<LocalDate> = date("device_date")
|
val device_date: Column<LocalDateTime> = datetime("device_date")
|
||||||
override val primaryKey = PrimaryKey(id, name = "PK_SampleObject_Id")
|
override val primaryKey = PrimaryKey(id, name = "PK_SampleObject_Id")
|
||||||
}
|
}
|
@ -2,6 +2,7 @@ package database.service
|
|||||||
|
|
||||||
import database.model.SampleObject
|
import database.model.SampleObject
|
||||||
import api.ApiObject
|
import api.ApiObject
|
||||||
|
import kotlinx.datetime.toJavaLocalDateTime
|
||||||
import org.jetbrains.exposed.sql.transactions.transaction
|
import org.jetbrains.exposed.sql.transactions.transaction
|
||||||
|
|
||||||
class SampleObjectService : ISampleObjectService {
|
class SampleObjectService : ISampleObjectService {
|
||||||
@ -10,7 +11,7 @@ class SampleObjectService : ISampleObjectService {
|
|||||||
transaction {
|
transaction {
|
||||||
SampleObject.new {
|
SampleObject.new {
|
||||||
tag = apiObject.tag
|
tag = apiObject.tag
|
||||||
device_date = apiObject.device_date
|
device_date = apiObject.device_date.toJavaLocalDateTime()
|
||||||
device_id = apiObject.device_id
|
device_id = apiObject.device_id
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,9 +16,9 @@ class ConsumerWrapper {
|
|||||||
val inputConnection = factory.newConnection()
|
val inputConnection = factory.newConnection()
|
||||||
val inputChannel = inputConnection.createChannel()
|
val inputChannel = inputConnection.createChannel()
|
||||||
|
|
||||||
inputChannel.exchangeDeclare(envConfig.mqExchange, BuiltinExchangeType.FANOUT)
|
inputChannel.exchangeDeclare(envConfig.mqExchange, BuiltinExchangeType.DIRECT)
|
||||||
val inputQueueName = inputChannel.queueDeclare().queue
|
val inputQueueName = inputChannel.queueDeclare().queue
|
||||||
inputChannel.queueBind(inputQueueName, envConfig.mqExchange, "")
|
inputChannel.queueBind(inputQueueName, envConfig.mqExchange, "meta")
|
||||||
|
|
||||||
inputChannel.basicConsume(inputQueueName, false, DatabaseConsumer(inputChannel))
|
inputChannel.basicConsume(inputQueueName, false, DatabaseConsumer(inputChannel))
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
package mq
|
package mq
|
||||||
|
|
||||||
import api.ApiObject
|
import api.ApiObject
|
||||||
import com.google.gson.Gson
|
import kotlinx.serialization.json.*
|
||||||
import com.rabbitmq.client.*
|
import com.rabbitmq.client.*
|
||||||
import database.service.ISampleObjectService
|
import database.service.ISampleObjectService
|
||||||
|
import kotlinx.serialization.decodeFromString
|
||||||
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: ISampleObjectService by inject()
|
private val resultObjectService: ISampleObjectService by inject()
|
||||||
private val gson = Gson()
|
|
||||||
private val basicChannel = channel
|
private val basicChannel = channel
|
||||||
override fun handleConsumeOk(consumerTag: String?) {
|
override fun handleConsumeOk(consumerTag: String?) {
|
||||||
}
|
}
|
||||||
@ -38,7 +38,7 @@ class DatabaseConsumer (channel: Channel) : Consumer, KoinComponent {
|
|||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
val rawJson = body!!.toString(Charsets.UTF_8)
|
val rawJson = body!!.toString(Charsets.UTF_8)
|
||||||
val apiObject = gson.fromJson(rawJson, ApiObject::class.java)
|
val apiObject = Json{ ignoreUnknownKeys = true }.decodeFromString<ApiObject>(rawJson)
|
||||||
resultObjectService.addOne(apiObject)
|
resultObjectService.addOne(apiObject)
|
||||||
basicChannel.basicAck(envelope!!.deliveryTag,false)
|
basicChannel.basicAck(envelope!!.deliveryTag,false)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
|
Reference in New Issue
Block a user