Beispiel #1
0
func NewKiteClientManager(zkAddr, groupId, secretKey string, listen listener.IListener) *KiteClientManager {

	flowstat := stat.NewFlowStat("kiteclient-" + groupId)
	rc := turbo.NewRemotingConfig(
		"remoting-"+groupId,
		50, 16*1024,
		16*1024, 10000, 10000,
		10*time.Second, 160000)

	//重连管理器
	reconnManager := c.NewReconnectManager(true, 30*time.Second, 100, handshake)

	//构造pipeline的结构
	pipeline := pipe.NewDefaultPipeline()
	clientm := c.NewClientManager(reconnManager)
	pipeline.RegisteHandler("kiteclient-packet", chandler.NewPacketHandler("kiteclient-packet"))
	pipeline.RegisteHandler("kiteclient-heartbeat", chandler.NewHeartbeatHandler("kiteclient-heartbeat", 10*time.Second, 5*time.Second, clientm))
	pipeline.RegisteHandler("kiteclient-accept", chandler.NewAcceptHandler("kiteclient-accept", listen))
	pipeline.RegisteHandler("kiteclient-remoting", pipe.NewRemotingHandler("kiteclient-remoting", clientm))

	manager := &KiteClientManager{
		ga:            c.NewGroupAuth(groupId, secretKey),
		kiteClients:   make(map[string][]*kiteClient, 10),
		topics:        make([]string, 0, 10),
		pipeline:      pipeline,
		clientManager: clientm,
		rc:            rc,
		flowstat:      flowstat,
		zkAddr:        zkAddr}
	//开启流量统计
	manager.remointflow()
	manager.flowstat.Start()
	return manager
}
Beispiel #2
0
func NewKiteQConfig(so ServerOption, rc *turbo.RemotingConfig) KiteQConfig {
	flowstat := stat.NewFlowStat("KiteQ-" + so.bindHost)
	for _, topic := range so.topics {
		flowstat.TopicsFlows[topic] = &turbo.Flow{}
	}
	return KiteQConfig{
		flowstat: flowstat,
		rc:       rc,
		so:       so}
}
Beispiel #3
0
func NewKiteQConfig(name string, server, zkhost string, fly bool, deliverTimeout time.Duration, maxDeliverWorkers int,
	recoverPeriod time.Duration,
	topics []string,
	db string,
	rc *turbo.RemotingConfig) KiteQConfig {
	return KiteQConfig{
		fly:               fly,
		flowstat:          stat.NewFlowStat(name),
		rc:                rc,
		server:            server,
		zkhost:            zkhost,
		deliverTimeout:    deliverTimeout,
		maxDeliverWorkers: maxDeliverWorkers,
		recoverPeriod:     recoverPeriod,
		topics:            topics,
		db:                db}
}
Beispiel #4
0
func NewKiteQConfig(name string, server, zkhost string, fly bool, deliverTimeout time.Duration, maxDeliverWorkers int,
	recoverPeriod time.Duration, dlqHour int,
	topics []string,
	db string,
	rc *turbo.RemotingConfig) KiteQConfig {
	flowstat := stat.NewFlowStat(name)
	for _, topic := range topics {
		flowstat.TopicsFlows[topic] = &turbo.Flow{}
	}
	return KiteQConfig{
		fly:               fly,
		flowstat:          flowstat,
		rc:                rc,
		server:            server,
		zkhost:            zkhost,
		deliverTimeout:    deliverTimeout,
		maxDeliverWorkers: maxDeliverWorkers,
		recoverPeriod:     recoverPeriod,
		dlqHour:           dlqHour,
		topics:            topics,
		db:                db}
}
func TestRecoverManager(t *testing.T) {

	pipeline := NewDefaultPipeline()

	kitedb := memory.NewKiteMemoryStore(100, 100)

	messageid := store.MessageId()
	t.Logf("messageid:%s\b", messageid)
	entity := store.NewMessageEntity(protocol.NewQMessage(buildStringMessage(messageid)))
	kitedb.Save(entity)
	go func() {
		for {
			log.Println(kitedb.Monitor())
			time.Sleep(1 * time.Second)
		}
	}()

	fs := stat.NewFlowStat("recover")
	fs.Start()
	ch := make(chan bool, 1)

	// 临时在这里创建的BindExchanger
	exchanger := binding.NewBindExchanger("localhost:2181", "127.0.0.1:13800")
	pipeline.RegisteHandler("deliverpre", handler.NewDeliverPreHandler("deliverpre", kitedb, exchanger, fs, 100))
	pipeline.RegisteHandler("deliver", newmockDeliverHandler("deliver", ch))
	hostname, _ := os.Hostname()
	rm := NewRecoverManager(hostname, 16*time.Second, pipeline, kitedb)
	rm.Start()
	select {
	case succ := <-ch:
		log.Printf("--------------recover %s\n", succ)
	case <-time.After(5 * time.Second):
		t.Fail()
		log.Println("waite recover  deliver timeout\n")
	}

}