networking orientated java core library for the tottori minecraft server network
| .idea | ||
| gradle/wrapper | ||
| src/main/java/de/kentoj/tottorinetworkcore | ||
| .env | ||
| .gitignore | ||
| build.gradle.kts | ||
| gradlew | ||
| gradlew.bat | ||
| README.md | ||
| settings.gradle.kts | ||
docker run -it --rm --name tottori-rabbitmq -p 5672:5672 rabbitmq:4.2.0-alpine
rpc
object Balance {
object Get : RpcType<UUID, Double> {
override val topic = "balance"
override val rpcName = "get"
override val requestMapper = DataMapper({
UUID.fromString(getValue("uuid").asString)
}, {
mapOf("uuid" to JsonPrimitive(this.toString()))
})
override val responseMapper = DataMapper({
getValue("amount").asDouble
}, {
mapOf("amount" to JsonPrimitive(this))
})
}
}
suspend fun main() {
val rpcService: RepoRpcService = /* TODO */;
// handle Balance.Get call
rpcService[Balance.Get] = {
Random.nextDouble(0.0, 100.0)
}
// call Balance.Get with uuid as parameter to receive Result<Double>
val balance = rpcService.call(Balance.Get, uuid)
println("balance: ${balanceOld.getOrThrow()}")
}
RepoSpcService#call does not support multiple parameters, so multiple parameters must be wrapped in a data class like
data class Params(val uuid: UUID, val amount: Double)
to set Balance. Also the RpcType implementation gets a little more complex of course.
TODO
- support multiple workers on one topic in RPC/MessageService
- do not use one exchange with n queues for each subscriber but just one queue