-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3480052
commit 1655df5
Showing
4 changed files
with
165 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package gg.beemo.latte | ||
|
||
import gg.beemo.latte.broker.BrokerClient | ||
import gg.beemo.latte.broker.BrokerConnection | ||
import kotlinx.coroutines.delay | ||
import kotlin.time.Duration.Companion.seconds | ||
|
||
// TODO This would be in the CommonConfig or similar. | ||
object BrokerServices { | ||
const val TEA = "tea" | ||
} | ||
|
||
class Tea { | ||
companion object { | ||
val cluster: Cluster = Cluster() | ||
} | ||
|
||
class Cluster { | ||
suspend fun restartShard(id: ShardId) {} | ||
} | ||
} | ||
|
||
class ShardId | ||
class RaidUser | ||
data class ShardRestartRequest(val shardId: ShardId) | ||
data class GreetingRequest(val name: String) | ||
data class GreetingResponse(val greeting: String) | ||
|
||
// ------------------------------ | ||
|
||
class TestBrokerClient(connection: BrokerConnection) : BrokerClient(connection) { | ||
|
||
init { | ||
consumer<ShardRestartRequest>( | ||
topic = "cluster.shard", | ||
key = "restart", | ||
) { req: ShardRestartRequest -> | ||
Tea.cluster.restartShard(req.shardId) | ||
} | ||
} | ||
|
||
private val raidBanQueue = producer<RaidUser>( | ||
topic = "raid.bans", | ||
key = "ban.enqueue", | ||
) | ||
|
||
private val greetingRpc = rpc<GreetingRequest, GreetingResponse>( | ||
topic = "rpc.greetings", | ||
key = "greeting.requests", | ||
) { req: GreetingRequest -> | ||
delay(2.seconds) | ||
return@rpc GreetingResponse("Hello, ${req.name}") | ||
} | ||
|
||
suspend fun createGreeting(name: String): String { | ||
// TODO Have to specify what cluster to send to. | ||
// Must also support external clusters such as milk... which aren't called clusters. | ||
// Maybe I should rename it to "service", so you specify the "target service". | ||
// Perhaps also the "target instance"? Because Tea as a whole would be a service. | ||
// So for a cluster-specific request, you send to service=tea, instance=0. | ||
// This is something that needs to be adapted at the connection level as well. | ||
val response = greetingRpc.call( | ||
GreetingRequest(name), | ||
service = BrokerServices.TEA, | ||
instance = "0", | ||
) | ||
return response.name | ||
} | ||
|
||
suspend fun enqueueRaidBan(user: RaidUser) { | ||
raidBanQueue.send(user) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters