Exemple #1
0
func startRpcServe(port string) {
	socket, err := thrift.NewTServerSocketTimeout(fmt.Sprintf(":%s", port), TIMEOUT)
	if err != nil {
		log.Fatalln("Unable to create server socket", err)
	}

	protocol := thrift.NewTBinaryProtocolFactoryDefault()
	transport := thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory())
	processor := thrift.NewTMultiplexedProcessor()

	registerProcessors(processor)

	server := thrift.NewTSimpleServer4(processor, socket, transport, protocol)
	server.Serve()
}
Exemple #2
0
func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())

	transportFactory := thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory())
	protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()

	serverTransport, err := thrift.NewTServerSocket(NetworkAddr)
	if err != nil {
		fmt.Println("Error!", err)
		os.Exit(1)
	}

	//不同的goroutine都使用同一个handler实例,不用锁么,测试一下便知
	handler := &BlogServiceImpl{}
	processor := thrift.NewTMultiplexedProcessor()
	processor.RegisterProcessor("BlogService", blogservice.NewBlogServiceProcessor(handler))

	//TFramedTransport性能测试
	server := thrift.NewTSimpleServer4(processor, serverTransport, transportFactory, protocolFactory)
	fmt.Println("thrift server in", NetworkAddr)
	server.Serve()
}
Exemple #3
0
	"github.com/gorilla/websocket"
	"github.com/huodon/wpc/thrift/impl"
	"github.com/huodon/wpc/thrift/service"
)

var upgrade = websocket.Upgrader{
	HandshakeTimeout: 15 * time.Second,
	Error: func(w http.ResponseWriter, r *http.Request, status int, reason error) {
		log.Printf("some error happend: %v, state: %d, reason: %s", r.Host, status, reason)
	},
}

var (
	trans   = thrift.NewTMemoryBufferLen(bytes.MinRead << 4)
	proto   = thrift.NewTJSONProtocol(trans)
	process = thrift.NewTMultiplexedProcessor()
	boxProc = service.NewBoxServiceProcessor(impl.GetServiceImpl())
	inChan  = make(chan []byte)
)

func init() {
	process.RegisterDefault(boxProc)
}

func wsHandle(w http.ResponseWriter, r *http.Request) {
	log.Println(`incomeing websocket request`)
	c, err := upgrade.Upgrade(w, r, nil)
	defer c.Close()

	go ThriftProcess(c)
Exemple #4
0
func NewAppServer(cfg Configuration) *AppServer {
	processor := thrift.NewTMultiplexedProcessor()

	//Register Processor after Processor
	//create config as u go
	fmt.Println("DATABASE " + cfg.MongoDatabase)
	metricsLogging := databases.NewMetricApi(cfg.InfluxHost, cfg.InfluxDatabase, cfg.InfluxUser, cfg.InfluxPass)

	//register User handler and stuff
	userCollection, err := databases.NewMongoConfig(cfg.MongoHost, cfg.MongoDatabase, cfg.MongoUser, cfg.MongoPw, "Users")
	userRepo := repositories.NewUserRepository(userCollection)
	userHandler := handlers.NewUserHandler(userRepo, metricsLogging)
	processor.RegisterProcessor(services.SERVICE_USER, services.NewUserSvcProcessor(userHandler))

	//register Image handler and stuff
	imageCollection, err := databases.NewMongoConfig(cfg.MongoHost, cfg.MongoDatabase, cfg.MongoUser, cfg.MongoPw, "Images")
	imageRepo := repositories.NewImageRepository(imageCollection)
	imageHandler := handlers.NewImageHandler(imageRepo, userRepo)
	processor.RegisterProcessor(services.SERVICE_IMAGE, services.NewImageSvcProcessor(imageHandler))

	//register city handler and stuff
	cityCollection, err := databases.NewMongoConfig(cfg.MongoHost, cfg.MongoDatabase, cfg.MongoUser, cfg.MongoPw, "Cities")
	cityRepo := repositories.NewCityRepository(cityCollection)
	processor.RegisterProcessor(services.SERVICE_CITY, services.NewCitySvcProcessor(handlers.NewCityHandler(cityRepo, metricsLogging)))

	//register sporthandler and stuff
	sportCollection, err := databases.NewMongoConfig(cfg.MongoHost, cfg.MongoDatabase, cfg.MongoUser, cfg.MongoPw, "Sports")
	sportRepo := repositories.NewSportRepository(sportCollection, imageRepo)
	sportHandler := handlers.NewSportHandler(sportRepo, userRepo, imageRepo, metricsLogging)
	processor.RegisterProcessor(services.SERVICE_SPORT, services.NewSportSvcProcessor(sportHandler))

	//register area handler and stuff
	areaCollection, err := databases.NewMongoConfig(cfg.MongoHost, cfg.MongoDatabase, cfg.MongoUser, cfg.MongoPw, "Areas")
	areaRepo := repositories.NewAreaRepository(areaCollection)
	processor.RegisterProcessor(services.SERVICE_AREA, services.NewAreaSvcProcessor(handlers.NewAreaHandler(areaRepo, userRepo, metricsLogging)))

	//register sportActivity handler and stuff
	sportactivityCollection, err := databases.NewMongoConfig(cfg.MongoHost, cfg.MongoDatabase, cfg.MongoUser, cfg.MongoPw, "Activities")
	sportactivityRepo := repositories.NewSportActivityRepository(sportactivityCollection)
	sportactivityHandler := handlers.NewSportActivityHandler(sportactivityRepo, userRepo, areaRepo, cityRepo, metricsLogging)
	processor.RegisterProcessor(services.SERVICE_SPORTACTIVITY, services.NewSportActivitySvcProcessor(sportactivityHandler))

	if err != nil {
		panic(err)
	}

	transport, err := thrift.NewTServerSocket(cfg.OwnIP)

	if err != nil {
		panic(err)
	}

	transportFactory := thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory())
	protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()

	server := thrift.NewTSimpleServer4(processor, transport, transportFactory, protocolFactory)

	return &AppServer{
		server: server,
		host:   cfg.OwnIP,
	}

}