This commit is contained in:
parent
af37f8d193
commit
d9ca774f57
@ -10,18 +10,21 @@ import database.service.ISampleObjectService
|
|||||||
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: Consumer, KoinComponent {
|
class DatabaseConsumer : Consumer, KoinComponent {
|
||||||
private val resultObjectService : ISampleObjectService by inject()
|
private val resultObjectService: ISampleObjectService by inject()
|
||||||
private val gson = Gson()
|
private val gson = Gson()
|
||||||
override fun handleConsumeOk(consumerTag : String?) {
|
override fun handleConsumeOk(consumerTag: String?) {
|
||||||
}
|
}
|
||||||
override fun handleCancelOk(p0 : String?) {
|
|
||||||
|
override fun handleCancelOk(p0: String?) {
|
||||||
throw UnsupportedOperationException()
|
throw UnsupportedOperationException()
|
||||||
}
|
}
|
||||||
override fun handleRecoverOk(p0 : String?) {
|
|
||||||
|
override fun handleRecoverOk(p0: String?) {
|
||||||
throw UnsupportedOperationException()
|
throw UnsupportedOperationException()
|
||||||
}
|
}
|
||||||
override fun handleCancel(p0 : String?) {
|
|
||||||
|
override fun handleCancel(p0: String?) {
|
||||||
throw UnsupportedOperationException()
|
throw UnsupportedOperationException()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -29,9 +32,18 @@ class DatabaseConsumer: Consumer, KoinComponent {
|
|||||||
println("got shutdown signal")
|
println("got shutdown signal")
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
||||||
val rawJson = body!!.toString(Charsets.UTF_8)
|
val rawJson = body!!.toString(Charsets.UTF_8)
|
||||||
val apiObject = gson.fromJson(rawJson, ApiObject::class.java)
|
val apiObject = gson.fromJson(rawJson, ApiObject::class.java)
|
||||||
resultObjectService.addOne(apiObject)
|
resultObjectService.addOne(apiObject)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
println(e.stackTrace)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user