Пример #1
0
func StartServer() {
	handler := &DBHandler{}
	if _, err := common.NsqConsumerGO(common.USER_CENTER_TOPIC, "user_center_channel", 5, handler); err != nil {
		panic(err)
	}
	select {}
}
Пример #2
0
func StartServer() {
	for i := 0; i < 10; i++ {
		if _, err := common.NsqConsumerGO(common.MSG_CENTER_TOPIC, "msgcenter-channel", 10, &Handler{}); err != nil {
			panic(err)
		}
	}
	select {}
	syslog.SysLogDeinit()
	return
}
Пример #3
0
func StartServer() {
	handler := &Handler{}

	for i := 0; i < 10; i++ {
		if _, err := common.NsqConsumerGO(common.MSG_SERVER_TOPIC, "msg_server_channel", uint(10), handler); err != nil {
			panic(err)
		}
	}
	select {}
	syslog.SysLogDeinit()
	return
}
Пример #4
0
func StartServer() {
	iniConf := common.Config()
	ip := iniConf.DefaultString("tcp_ip", "10.0.2.15")
	port := iniConf.DefaultString("tcp_port", "8888")
	g_IP = util.IPToInt(ip)
	g_Port = uint32(util.Atoi(port))

	listener, err := common.TCPServer(ip + ":" + port)
	if err != nil {
		panic(err)
	}
	/*
		udp_addr1 := iniConf.DefaultString("udp_address1", "127.0.0.1:9100")
		udp_addr2 := iniConf.DefaultString("udp_address2", "127.0.0.1:9101")

		udpSocket1, err := common.UDPServer(udp_addr1)
		if err != nil {
			panic(err)
		}
		udpSocket2, err := common.UDPServer(udp_addr2)
		if err != nil {
			panic(err)
		}
	*/
	service := &Service{
		Listener:  listener,
		ClientCh:  make(chan *Client, 1000),
		WaitGroup: sync_.NewWaitGroup(),
		ClientMap: make(map[uint32]*Client),
		RWMutex:   &sync.RWMutex{},
	}
	for i := 0; i < CLIENT_GROUP_NUM; i++ {
		NewClientGroup(service)
	}
	go service.Serve()
	//go service.P2pService(udpSocket1)
	//go service.P2pService(udpSocket2)

	topic := fmt.Sprintf("conn_%v_%v", ip, port)
	if _, err := common.NsqConsumerGO(topic, "conn-channel", 3, service); err != nil {
		panic(err)
	}
	// Handle SIGINT and SIGTERM.
	ch := make(chan os.Signal)
	signal.Notify(ch, syscall.SIGINT, syscall.SIGTERM, syscall.SIGKILL)
	syslog.Info("recv signal and exit:", <-ch)
	service.Stop()
	return
}