Exemple #1
0
func NewManager(cfg *ManagerConfig) *Manager {
	return &Manager{
		cfg: cfg,
		sessionStore: storage.NewSessionStore(storage.NewRedisStore(&storage.RedisStoreOptions{
			Network:        "tcp",
			Address:        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,
		})),
		topicStore: storage.NewTopicStore(storage.NewRedisStore(&storage.RedisStoreOptions{
			Network:        "tcp",
			Address:        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,
		})),
	}
}
Exemple #2
0
func NewRouter(cfg *RouterConfig) *Router {
	return &Router{
		cfg:                cfg,
		msgServerClientMap: make(map[string]*libnet.Session),
		sessionStore: storage.NewSessionStore(storage.NewRedisStore(&storage.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),
	}
}
func main() {
	version()
	fmt.Printf("built on %s\n", BuildTime())
	flag.Parse()
	cfg := NewMsgServerConfig(*InputConfFile)
	err := cfg.LoadConfig()
	if err != nil {
		glog.Error(err.Error())
		return
	}

	rs := storage.NewRedisStore(&storage.RedisStoreOptions{
		Network:        "tcp",
		Address:        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)
	}
	glog.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) {
		glog.Info("a new client ", session.Conn().RemoteAddr().String(), " | come in")
		go handleSession(ms, session)
	})
}