This commit is contained in:
parent
a43b692acf
commit
f4ce568aa8
@ -25,7 +25,7 @@ services:
|
|||||||
POSTGRES_DB: "output-service-rdb"
|
POSTGRES_DB: "output-service-rdb"
|
||||||
DB_URL: "jdbc:postgresql://output-service-postgres:5432/output-service-rdb"
|
DB_URL: "jdbc:postgresql://output-service-postgres:5432/output-service-rdb"
|
||||||
MQ_HOST: rabbitmq
|
MQ_HOST: rabbitmq
|
||||||
MQ_USERNMAE: rabbitmq
|
MQ_USERNAME: rabbitmq
|
||||||
MQ_PASSWORD: rabbitmq
|
MQ_PASSWORD: rabbitmq
|
||||||
depends_on:
|
depends_on:
|
||||||
- rabbitmq
|
- rabbitmq
|
||||||
|
@ -26,6 +26,7 @@ import kotlinx.coroutines.Dispatchers
|
|||||||
import kotlinx.coroutines.GlobalScope
|
import kotlinx.coroutines.GlobalScope
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import org.jetbrains.exposed.sql.SchemaUtils
|
import org.jetbrains.exposed.sql.SchemaUtils
|
||||||
|
import org.jetbrains.exposed.sql.transactions.transaction
|
||||||
|
|
||||||
fun main(args: Array<String>): Unit = io.ktor.server.netty.EngineMain.main(args)
|
fun main(args: Array<String>): Unit = io.ktor.server.netty.EngineMain.main(args)
|
||||||
|
|
||||||
@ -45,21 +46,27 @@ fun Application.module(testing: Boolean = false) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
DatabaseFactory.init()
|
DatabaseFactory.init()
|
||||||
SchemaUtils.create(ResultObjects)
|
transaction{
|
||||||
|
SchemaUtils.create(ResultObjects)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
val appConfig = HoconApplicationConfig(ConfigFactory.load())
|
val appConfig = HoconApplicationConfig(ConfigFactory.load())
|
||||||
val factory = ConnectionFactory()
|
val factory = ConnectionFactory()
|
||||||
factory.host = appConfig.property("mq.host").getString()
|
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 connection = factory.newConnection()
|
||||||
val channel = connection.createChannel()
|
val channel = connection.createChannel()
|
||||||
|
|
||||||
channel.exchangeDeclare(RecieveOutput.EXCHANGE_NAME, "FANOUT")
|
channel.exchangeDeclare(RecieveOutput.EXCHANGE_NAME, BuiltinExchangeType.FANOUT)
|
||||||
val queueName = channel.queueDeclare().queue
|
val queueName = channel.queueDeclare().queue
|
||||||
channel.queueBind(queueName, RecieveOutput.EXCHANGE_NAME, "")
|
channel.queueBind(queueName, RecieveOutput.EXCHANGE_NAME, "")
|
||||||
|
|
||||||
GlobalScope.launch(Dispatchers.Default) {
|
GlobalScope.launch(Dispatchers.Default) {
|
||||||
connection.channel {
|
connection.channel {
|
||||||
consume("test_queue") {
|
consume(queueName) {
|
||||||
consumeMessageWithConfirm({
|
consumeMessageWithConfirm({
|
||||||
val resultObjectService = ResultObjectService()
|
val resultObjectService = ResultObjectService()
|
||||||
val rawJson = String(it.body)
|
val rawJson = String(it.body)
|
||||||
@ -93,6 +100,10 @@ fun Application.module(testing: Boolean = false) {
|
|||||||
exception<HttpException> { _ ->
|
exception<HttpException> { _ ->
|
||||||
call.respond(HttpStatusCode.BadRequest)
|
call.respond(HttpStatusCode.BadRequest)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exception<IllegalStateException> { _ ->
|
||||||
|
call.respond(HttpStatusCode.NotAcceptable)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
OutputServiceRDBServer().apply {
|
OutputServiceRDBServer().apply {
|
||||||
|
@ -24,13 +24,13 @@ class OutputServiceRDBServer() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get("/output/filter/negative") {
|
get("/output/filter/negative") {
|
||||||
val resultList = resultObjectService.getResultObjectbyDecision(false) ?: error(HttpStatusCode.NotFound)
|
val resultList = resultObjectService.getResultObjectbyDecision(false) ?: call.respond(HttpStatusCode.NotFound)
|
||||||
|
|
||||||
call.respond(resultList)
|
call.respond(resultList)
|
||||||
}
|
}
|
||||||
|
|
||||||
get("/output/filter/positive") {
|
get("/output/filter/positive") {
|
||||||
val resultList = resultObjectService.getResultObjectbyDecision(true) ?: error(HttpStatusCode.NotFound)
|
val resultList = resultObjectService.getResultObjectbyDecision(true) ?: call.respond(HttpStatusCode.NotFound)
|
||||||
|
|
||||||
call.respond(resultList)
|
call.respond(resultList)
|
||||||
}
|
}
|
||||||
@ -39,7 +39,7 @@ class OutputServiceRDBServer() {
|
|||||||
val dateAfter = call.parameters["dateAfter"] ?: error(HttpStatusCode.NotAcceptable)
|
val dateAfter = call.parameters["dateAfter"] ?: error(HttpStatusCode.NotAcceptable)
|
||||||
val dateTimeFormatter: DateTimeFormatter = DateTimeFormatter.ISO_LOCAL_DATE
|
val dateTimeFormatter: DateTimeFormatter = DateTimeFormatter.ISO_LOCAL_DATE
|
||||||
val localDateAfter : LocalDate = LocalDate.parse(dateAfter,dateTimeFormatter)
|
val localDateAfter : LocalDate = LocalDate.parse(dateAfter,dateTimeFormatter)
|
||||||
val resultList = resultObjectService.getResultObjectbeforeDate(localDateAfter) ?: error(HttpStatusCode.NotFound)
|
val resultList = resultObjectService.getResultObjectbeforeDate(localDateAfter) ?: call.respond(HttpStatusCode.NotFound)
|
||||||
|
|
||||||
call.respond(resultList)
|
call.respond(resultList)
|
||||||
}
|
}
|
||||||
@ -48,14 +48,14 @@ class OutputServiceRDBServer() {
|
|||||||
val dateAfter = call.parameters["dateBefore"] ?: error(HttpStatusCode.NotAcceptable)
|
val dateAfter = call.parameters["dateBefore"] ?: error(HttpStatusCode.NotAcceptable)
|
||||||
val dateTimeFormatter: DateTimeFormatter = DateTimeFormatter.ISO_LOCAL_DATE
|
val dateTimeFormatter: DateTimeFormatter = DateTimeFormatter.ISO_LOCAL_DATE
|
||||||
val localDateBefore : LocalDate = LocalDate.parse(dateAfter,dateTimeFormatter)
|
val localDateBefore : LocalDate = LocalDate.parse(dateAfter,dateTimeFormatter)
|
||||||
val resultList = resultObjectService.getResultObjectafterDate(localDateBefore) ?: error(HttpStatusCode.NotFound)
|
val resultList = resultObjectService.getResultObjectafterDate(localDateBefore) ?: call.respond(HttpStatusCode.NotFound)
|
||||||
|
|
||||||
call.respond(resultList)
|
call.respond(resultList)
|
||||||
}
|
}
|
||||||
|
|
||||||
get("/output/{tagID}") {
|
get("/output/{tagID}") {
|
||||||
val tagID = call.parameters["tagID"] ?: error(HttpStatusCode.NotAcceptable)
|
val tagID = call.parameters["tagID"] ?: error(HttpStatusCode.NotAcceptable)
|
||||||
val resultObject = resultObjectService.getResultObjectbyTag(tagID) ?: error(HttpStatusCode.NotFound)
|
val resultObject = resultObjectService.getResultObjectbyTag(tagID) ?: call.respond(HttpStatusCode.NotFound)
|
||||||
|
|
||||||
call.respond(resultObject)
|
call.respond(resultObject)
|
||||||
}
|
}
|
||||||
|
@ -14,11 +14,11 @@ object DatabaseFactory {
|
|||||||
@KtorExperimentalAPI
|
@KtorExperimentalAPI
|
||||||
private val appConfig = HoconApplicationConfig(ConfigFactory.load())
|
private val appConfig = HoconApplicationConfig(ConfigFactory.load())
|
||||||
@KtorExperimentalAPI
|
@KtorExperimentalAPI
|
||||||
private val dbUrl = appConfig.property("db.jdbc").getString()
|
private val dbUrl = appConfig.property("ktor.db.jdbc").getString()
|
||||||
@KtorExperimentalAPI
|
@KtorExperimentalAPI
|
||||||
private val dbUser = appConfig.property("db.user").getString()
|
private val dbUser = appConfig.property("ktor.db.user").getString()
|
||||||
@KtorExperimentalAPI
|
@KtorExperimentalAPI
|
||||||
private val dbPassword = appConfig.property("db.password").getString()
|
private val dbPassword = appConfig.property("ktor.db.password").getString()
|
||||||
|
|
||||||
@KtorExperimentalAPI
|
@KtorExperimentalAPI
|
||||||
fun init() {
|
fun init() {
|
||||||
|
Loading…
Reference in New Issue
Block a user