package main

import (
	"mongo.games.com/game/common"
	"mongo.games.com/game/model"
	"mongo.games.com/game/mq"
	"mongo.games.com/goserver/core"
	"mongo.games.com/goserver/core/broker/rabbitmq"
	"time"
)

var RabbitMQPublisher *mq.RabbitMQPublisher
var RabbitMqConsumer *mq.RabbitMQConsumer

func init() {
	//首先加载游戏配置
	core.RegisteHook(core.HOOK_BEFORE_START, func() error {
		//初始化rpc
		model.StartupRPClient(common.CustomConfig.GetString("MgoRpcCliNet"), common.CustomConfig.GetString("MgoRpcCliAddr"), time.Duration(common.CustomConfig.GetInt("MgoRpcCliReconnInterV"))*time.Second)

		//rabbitmq打开链接
		RabbitMqConsumer = mq.NewRabbitMQConsumer(common.CustomConfig.GetString("RabbitMQURL"), rabbitmq.Exchange{Name: common.CustomConfig.GetString("RMQExchange"), Durable: true})
		if RabbitMqConsumer != nil {
			RabbitMqConsumer.Start()
		}
		return nil
	})

	core.RegisteHook(core.HOOK_AFTER_STOP, func() error {
		if RabbitMqConsumer != nil {
			RabbitMqConsumer.Stop()
		}
		return nil
	})
}
