Example #1
0
func main() {
	version()
	fmt.Printf("built on %s\n", BuildTime())
	flag.Parse()
	cfg := NewRouterConfig(*InputConfFile)
	err := cfg.LoadConfig()
	if err != nil {
		log.Error(err.Error())
		return
	}

	server, err := libnet.Listen(cfg.TransportProtocols, cfg.Listen)
	if err != nil {
		log.Error(err.Error())
		return
	}
	log.Info("server start: ", server.Listener().Addr().String())

	rs := redis_store.NewRedisStore(&redis_store.RedisStoreOptions{
		Network:        "tcp",
		Address:        cfg.Redis.Addr + cfg.Redis.Port,
		ConnectTimeout: time.Duration(cfg.Redis.ConnectTimeout) * time.Millisecond,
		ReadTimeout:    time.Duration(cfg.Redis.ReadTimeout) * time.Millisecond,
		WriteTimeout:   time.Duration(cfg.Redis.WriteTimeout) * time.Millisecond,
		Database:       1,
		KeyPrefix:      base.COMM_PREFIX,
	})
	r := NewRouter(cfg, rs)
	//TODO not use go
	go r.subscribeChannels()
	server.Serve(func(session *libnet.Session) {

	})
}
Example #2
0
func NewManager(cfg *ManagerConfig) *Manager {
	return &Manager{
		cfg: cfg,
		sessionCache: redis_store.NewSessionCache(redis_store.NewRedisStore(&redis_store.RedisStoreOptions{
			Network:        "tcp",
			Address:        cfg.Redis.Addr + cfg.Redis.Port,
			ConnectTimeout: time.Duration(cfg.Redis.ConnectTimeout) * time.Millisecond,
			ReadTimeout:    time.Duration(cfg.Redis.ReadTimeout) * time.Millisecond,
			WriteTimeout:   time.Duration(cfg.Redis.WriteTimeout) * time.Millisecond,
			Database:       1,
			KeyPrefix:      base.COMM_PREFIX,
		})),
		topicCache: redis_store.NewTopicCache(redis_store.NewRedisStore(&redis_store.RedisStoreOptions{
			Network:        "tcp",
			Address:        cfg.Redis.Addr + cfg.Redis.Port,
			ConnectTimeout: time.Duration(cfg.Redis.ConnectTimeout) * time.Millisecond,
			ReadTimeout:    time.Duration(cfg.Redis.ReadTimeout) * time.Millisecond,
			WriteTimeout:   time.Duration(cfg.Redis.WriteTimeout) * time.Millisecond,
			Database:       1,
			KeyPrefix:      base.COMM_PREFIX,
		})),
		mongoStore: mongo_store.NewMongoStore(cfg.Mongo.Addr, cfg.Mongo.Port, cfg.Mongo.User, cfg.Mongo.Password),
	}
}
Example #3
0
func NewMonitor(cfg *MonitorConfig) *Monitor {
	return &Monitor{
		cfg:                cfg,
		msgServerClientMap: make(map[string]*libnet.Session),
		sessionStore: redis_store.NewSessionCache(redis_store.NewRedisStore(&redis_store.RedisStoreOptions{
			Network:        "tcp",
			Address:        cfg.Redis.Addr + cfg.Redis.Port,
			ConnectTimeout: time.Duration(cfg.Redis.ConnectTimeout) * time.Millisecond,
			ReadTimeout:    time.Duration(cfg.Redis.ReadTimeout) * time.Millisecond,
			WriteTimeout:   time.Duration(cfg.Redis.WriteTimeout) * time.Millisecond,
			Database:       1,
			KeyPrefix:      base.COMM_PREFIX,
		})),
		topicServerMap: make(map[string]string),
	}
}
Example #4
0
func main() {
	version()
	fmt.Printf("built on %s\n", BuildTime())
	flag.Parse()
	cfg := NewMsgServerConfig(*InputConfFile)
	err := cfg.LoadConfig()
	if err != nil {
		log.Error(err.Error())
		return
	}

	rs := redis_store.NewRedisStore(&redis_store.RedisStoreOptions{
		Network:        "tcp",
		Address:        cfg.Redis.Addr + cfg.Redis.Port,
		ConnectTimeout: time.Duration(cfg.Redis.ConnectTimeout) * time.Millisecond,
		ReadTimeout:    time.Duration(cfg.Redis.ReadTimeout) * time.Millisecond,
		WriteTimeout:   time.Duration(cfg.Redis.WriteTimeout) * time.Millisecond,
		Database:       1,
		KeyPrefix:      base.COMM_PREFIX,
	})

	ms := NewMsgServer(cfg, rs)

	ms.server, err = libnet.Listen(cfg.TransportProtocols, cfg.Listen)
	if err != nil {
		panic(err)
	}
	log.Info("msg_server running at  ", ms.server.Listener().Addr().String())

	ms.createChannels()

	go ms.scanDeadSession()

	go ms.sendMonitorData()

	ms.server.Serve(func(session *libnet.Session) {
		log.Info("a new client ", session.Conn().RemoteAddr().String(), " | come in")
		go handleSession(ms, session)
	})
}