Private
Public Access
1
0

Enable NATS Queue Groups for game.join, game.start, and game.input handlers to support load balancing.
All checks were successful
Dynamic Branch Deploy / build-and-deploy (push) Successful in 2m28s

This commit is contained in:
Sebastian Unterschütz
2026-01-04 16:32:47 +01:00
parent d7c2e8dc85
commit a85b519051

View File

@@ -100,8 +100,8 @@ func main() {
}
log.Printf("✅ Verbunden mit NATS: %s", natsURL)
// 3. HANDLER: GAME JOIN
sub, err := ec.Subscribe("game.join", func(req *game.JoinRequest) {
// 3. HANDLER: GAME JOIN (mit Queue Group für Load Balancing)
sub, err := ec.QueueSubscribe("game.join", "game-servers", func(req *game.JoinRequest) {
log.Printf("📥 JOIN empfangen: Name=%s, RoomID=%s", req.Name, req.RoomID)
playerID := req.Name
@@ -139,15 +139,10 @@ func main() {
if err != nil {
log.Fatal("❌ Fehler beim Subscribe auf game.join:", err)
}
log.Printf("👂 Lausche auf 'game.join'... (Sub Valid: %v)", sub.IsValid())
log.Printf("👂 Lausche auf 'game.join' in Queue Group 'game-servers'... (Sub Valid: %v)", sub.IsValid())
// TEST: Auch mit Raw-NATS lauschen
nc.Subscribe("game.join", func(m *nats.Msg) {
log.Printf("🔍 RAW NATS: Nachricht empfangen auf game.join: %s", string(m.Data))
})
// 4. HANDLER: GAME START
_, _ = ec.Subscribe("game.start", func(req *game.StartRequest) {
// 4. HANDLER: GAME START (mit Queue Group)
_, _ = ec.QueueSubscribe("game.start", "game-servers", func(req *game.StartRequest) {
log.Printf("▶️ START empfangen: RoomID=%s", req.RoomID)
mu.RLock()
@@ -164,8 +159,8 @@ func main() {
}
})
// 5. HANDLER: INPUT
_, _ = ec.Subscribe("game.input", func(input *game.ClientInput) {
// 5. HANDLER: INPUT (mit Queue Group)
_, _ = ec.QueueSubscribe("game.input", "game-servers", func(input *game.ClientInput) {
mu.RLock()
room, ok := playerSessions[input.PlayerID]
mu.RUnlock()