Ejemplo n.º 1
0
//启动dm303
func Start(port int, serviceName string) {
	transportFactory := thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory())
	protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()
	networkAddr := fmt.Sprintf(":%d", port)
	serverTransport, err := thrift.NewTServerSocket(networkAddr)
	if err != nil {
		panic(err.Error())
	}
	handler := NewDomobBase(serviceName)
	processor := NewDomobServiceProcessor(handler)
	server := thrift.NewTSimpleServer4(processor, serverTransport, transportFactory, protocolFactory)
	err = server.Serve()
	if err != nil {
		panic(err.Error())
	}
}
Ejemplo n.º 2
0
// BootStrap a thrift Server
func BootStrapThriftServer(processor thrift.TProcessor, customizedConfig func()) {
	initGloabl(customizedConfig)

	transportFactory := thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory())
	protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()
	port, _ := config.GlobalConfiger.Int("serverport")
	networkAddr := fmt.Sprintf(":%d", port)
	serverTransport, err := thrift.NewTServerSocket(networkAddr)
	if err != nil {
		bootStrapLogger.Errorf("Error! %s", err)
		os.Exit(1)
	}
	thriftServer = thrift.NewTSimpleServer4(processor, serverTransport, transportFactory, protocolFactory)
	fmt.Printf("thrift server in %s\n", networkAddr)
	if err := thriftServer.Serve(); err != nil {
		bootStrapLogger.Errorf("server start error: %s", err)
	}
}