Пример #1
0
func init() {

	l := &MockListener{rc: rc, txc: txc}

	rc := turbo.NewRemotingConfig(
		"remoting-127.0.0.1:13800",
		2000, 16*1024,
		16*1024, 10000, 10000,
		10*time.Second, 160000)

	kc := server.NewKiteQConfig(server.MockServerOption(), rc)
	kiteQ = server.NewKiteQServer(kc)

	// 创建客户端
	manager = NewKiteClientManager("localhost:2181", "ps-trade-a", "123456", l)
	manager.SetPublishTopics([]string{"trade"})

	// 设置接收类型
	manager.SetBindings(
		[]*binding.Binding{
			binding.Bind_Direct("ps-trade-a", "trade", "pay-succ", 1000, true),
		},
	)

	kiteQ.Start()
	time.Sleep(10 * time.Second)
	manager.Start()
}
Пример #2
0
func main() {

	//加载启动参数
	so := server.Parse()

	runtime.GOMAXPROCS(runtime.NumCPU())

	rc := turbo.NewRemotingConfig(
		"remoting",
		20000, 16*1024,
		16*1024, 10000, 10000,
		10*time.Second, 160000)

	kc := server.NewKiteQConfig(so, rc)

	qserver := server.NewKiteQServer(kc)
	qserver.Start()

	var s = make(chan os.Signal, 1)
	signal.Notify(s, syscall.SIGKILL, syscall.SIGUSR1)
	//是否收到kill的命令
	for {
		cmd := <-s
		if cmd == syscall.SIGKILL {
			break
		} else if cmd == syscall.SIGUSR1 {
			//如果为siguser1则进行dump内存
			unixtime := time.Now().Unix()
			path := fmt.Sprintf("./heapdump-kiteq-%d", unixtime)
			f, err := os.Create(path)
			if nil != err {
				continue
			} else {
				debug.WriteHeapDump(f.Fd())
			}
		}
	}

	qserver.Shutdown()
	log.InfoLog("kite_server", "KiteQServer IS STOPPED!")

}
Пример #3
0
func main() {
	fly := flag.Bool("fly", false, "-fly=true //开启服务端优先投递,false为优先存储")
	logxml := flag.String("logxml", "./log/log.xml", "-logxml=./log/log.xml")
	bindHost := flag.String("bind", ":13800", "-bind=localhost:13800")
	zkhost := flag.String("zkhost", "localhost:2181", "-zkhost=localhost:2181")
	topics := flag.String("topics", "", "-topics=trade,a,b")
	dlqHourPerDay := flag.Int("dlqHourPerDay", 2, "-dlqExecHour=2 过期消息迁移时间点")
	db := flag.String("db", "memory://initcap=100000&maxcap=200000",
		"-db=mysql://master:3306,slave:3306?db=kite&username=root&password=root&maxConn=500&batchUpdateSize=1000&batchDelSize=1000&flushSeconds=1000")
	pprofPort := flag.Int("pport", -1, "pprof port default value is -1 ")
	flag.Parse()

	//加载log4go的配置
	log.LoadConfiguration(*logxml)

	flag.VisitAll(func(f *flag.Flag) {
		log.InfoLog("kite_server", "KiteQ[%s:%s]", f.Name, f.Value.String())
	})

	runtime.GOMAXPROCS(runtime.NumCPU())

	host, port, _ := net.SplitHostPort(*bindHost)

	rc := turbo.NewRemotingConfig(
		"remoting-"+*bindHost,
		20000, 16*1024,
		16*1024, 10000, 10000,
		10*time.Second, 160000)

	kc := server.NewKiteQConfig("kiteq-"+*bindHost, *bindHost, *zkhost, *fly, 5*time.Second, 8000,
		5*time.Second, *dlqHourPerDay /*每天凌晨2点执行*/, strings.Split(*topics, ","), *db, rc)

	qserver := server.NewKiteQServer(kc)
	qserver.Start()

	go func() {
		if *pprofPort > 0 {
			http.HandleFunc("/stat", qserver.HandleStat)
			http.HandleFunc("/binds", qserver.HandleBindings)
			log.Error(http.ListenAndServe(host+":"+strconv.Itoa(*pprofPort), nil))
		}
	}()

	var s = make(chan os.Signal, 1)
	signal.Notify(s, syscall.SIGKILL, syscall.SIGUSR1)
	//是否收到kill的命令
	for {
		cmd := <-s
		if cmd == syscall.SIGKILL {
			break
		} else if cmd == syscall.SIGUSR1 {
			//如果为siguser1则进行dump内存
			unixtime := time.Now().Unix()
			path := "./heapdump-kiteq-" + host + "_" + port + fmt.Sprintf("%d", unixtime)
			f, err := os.Create(path)
			if nil != err {
				continue
			} else {
				debug.WriteHeapDump(f.Fd())
			}
		}
	}

	qserver.Shutdown()
	log.InfoLog("kite_server", "KiteQServer IS STOPPED!")

}