You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

54 lines
1.3 KiB

  1. // Copyright 2017 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package main
  15. import (
  16. "flag"
  17. "fmt"
  18. "log"
  19. "math/rand"
  20. "net"
  21. "strconv"
  22. "cloud.google.com/go/pubsub/loadtest"
  23. pb "cloud.google.com/go/pubsub/loadtest/pb"
  24. "google.golang.org/grpc"
  25. )
  26. func main() {
  27. port := flag.Uint("worker_port", 6000, "port to bind worker to")
  28. role := flag.String("r", "", "role: pub/sub")
  29. flag.Parse()
  30. var lts pb.LoadtestWorkerServer
  31. switch *role {
  32. case "pub":
  33. lts = &loadtest.PubServer{ID: strconv.Itoa(rand.Int())}
  34. case "sub":
  35. lts = &loadtest.SubServer{}
  36. default:
  37. log.Fatalf("unknown role: %q", *role)
  38. }
  39. serv := grpc.NewServer()
  40. pb.RegisterLoadtestWorkerServer(serv, lts)
  41. lis, err := net.Listen("tcp", fmt.Sprintf(":%d", *port))
  42. if err != nil {
  43. log.Fatalf("failed to listen: %v", err)
  44. }
  45. serv.Serve(lis)
  46. }