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()
}
Example #2
0
func BenchmarkRemotingServer(t *testing.B) {

	//初始化存储

	var kiteClient *client.KiteQClient
	var kiteQServer *KiteQServer
	var c int32 = 0
	var lc int32 = 0

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

	kc := NewKiteQConfig("kiteq-localhost:13800", "localhost:13800", "localhost:2181", true, 1*time.Second, 10, 1*time.Minute, []string{"trade"}, "memory://", rc)

	kiteQServer = NewKiteQServer(kc)
	kiteQServer.Start()
	log.Println("KiteQServer START....")

	kiteClient = client.NewKiteQClient("localhost:2181", "s-trade-a", "123456", &defualtListener{})
	kiteClient.SetTopics([]string{"trade"})
	kiteClient.SetBindings([]*binding.Binding{
		binding.Bind_Direct("s-trade-a", "trade", "pay-succ", 1000, true),
	})
	kiteClient.Start()

	go func() {
		for {
			time.Sleep(1 * time.Second)
			log.Printf("%d\n", (c - lc))
			lc = c
		}
	}()

	t.SetParallelism(4)
	t.RunParallel(func(pb *testing.PB) {
		for pb.Next() {
			err := kiteClient.SendStringMessage(buildStringMessage("1"))
			if nil != err {
				t.Logf("SEND MESSAGE |FAIL|%s\n", err)
			}
		}
	})

	kiteClient.Destory()
	kiteQServer.Shutdown()
}
func main() {
	logxml := flag.String("logxml", "../log/log_consumer.xml", "-logxml=../log/log_consumer.xml")
	zkhost := flag.String("zkhost", "localhost:2181", "-zkhost=localhost:2181")
	flag.Parse()
	runtime.GOMAXPROCS(8)

	log.LoadConfiguration(*logxml)
	go func() {

		log.Info(http.ListenAndServe(":38000", nil))
	}()

	lis := &defualtListener{}
	go lis.monitor()

	kite := client.NewKiteQClient(*zkhost, "s-mts-test", "123456", lis)
	kite.SetBindings([]*binding.Binding{
		binding.Bind_Direct("s-mts-test", "relation", "pay-succ", 1000, true),
	})
	kite.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 := "./heapdump-consumer" + fmt.Sprintf("%d", unixtime)
			f, err := os.Create(path)
			if nil != err {
				continue
			} else {
				debug.WriteHeapDump(f.Fd())
			}
		}
	}
	kite.Destory()
}
Example #4
0
func TestRemotingServer(t *testing.T) {

	//初始化存储
	var kiteClient *client.KiteQClient
	var kiteQServer *KiteQServer
	var c int32 = 0
	var lc int32 = 0

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

	kc := NewKiteQConfig("kiteq-localhost:13800", "localhost:13800", "localhost:2181", true, 1*time.Second, 10, 1*time.Minute, []string{"trade"}, "memory://", rc)

	kiteQServer = NewKiteQServer(kc)
	kiteQServer.Start()
	log.Println("KiteQServer START....")

	kiteClient = client.NewKiteQClient("localhost:2181", "s-trade-a", "123456", &defualtListener{})
	kiteClient.SetTopics([]string{"trade"})
	kiteClient.SetBindings([]*binding.Binding{
		binding.Bind_Direct("s-trade-a", "trade", "pay-succ", 1000, true),
	})
	kiteClient.Start()

	go func() {
		for {
			time.Sleep(1 * time.Second)
			log.Printf("%d\n", (c - lc))
			lc = c
		}
	}()

	err := kiteClient.SendStringMessage(buildStringMessage("1"))
	if nil != err {
		t.Logf("SEND MESSAGE |FAIL|%s\n", err)
		t.Fail()

	}

	err = kiteClient.SendStringMessage(buildStringMessage("2"))
	if nil != err {
		t.Logf("SEND MESSAGE |FAIL|%s\n", err)
		t.Fail()

	}

	err = kiteClient.SendStringMessage(buildStringMessage("3"))
	if nil != err {
		t.Logf("SEND MESSAGE |FAIL|%s\n", err)
		t.Fail()

	}

	msg := buildStringMessage("4")
	msg.GetHeader().Commit = proto.Bool(false)

	err = kiteClient.SendStringMessage(msg)
	if nil != err {
		t.Logf("SEND MESSAGE |FAIL|%s\n", err)
		t.Fail()

	}

	time.Sleep(10 * time.Second)

	kiteClient.Destory()
	kiteQServer.Shutdown()
}