| 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 |
|
| 15 |
package main |
| 16 |
|
| 17 |
import ( |
| 18 |
"flag" |
| 19 |
"fmt" |
| 20 |
"log" |
| 21 |
"math/rand" |
| 22 |
"net" |
| 23 |
"strconv" |
| 24 |
|
| 25 |
"cloud.google.com/go/pubsub/loadtest" |
| 26 |
pb "cloud.google.com/go/pubsub/loadtest/pb" |
| 27 |
"google.golang.org/grpc" |
| 28 |
) |
| 29 |
|
| 30 |
func main() { |
| 31 |
port := flag.Uint("worker_port", 6000, "port to bind worker to") |
| 32 |
role := flag.String("r", "", "role: pub/sub") |
| 33 |
flag.Parse() |
| 34 |
|
| 35 |
var lts pb.LoadtestWorkerServer |
| 36 |
switch *role { |
| 37 |
case "pub": |
| 38 |
lts = &loadtest.PubServer{ID: strconv.Itoa(rand.Int())} |
| 39 |
case "sub": |
| 40 |
lts = &loadtest.SubServer{} |
| 41 |
default: |
| 42 |
log.Fatalf("unknown role: %q", *role) |
| 43 |
} |
| 44 |
|
| 45 |
serv := grpc.NewServer() |
| 46 |
pb.RegisterLoadtestWorkerServer(serv, lts) |
| 47 |
|
| 48 |
lis, err := net.Listen("tcp", fmt.Sprintf(":%d", *port)) |
| 49 |
if err != nil { |
| 50 |
log.Fatalf("failed to listen: %v", err) |
| 51 |
} |
| 52 |
serv.Serve(lis) |
| 53 |
} |