Example #1
0
		if err != nil {
			ctx.WithError(err).Fatal("Could not start gRPC server")
		}
		grpc := grpc.NewServer(component.ServerOptions()...)

		// Register and Listen
		component.RegisterHealthServer(grpc)
		broker.RegisterRPC(grpc)
		broker.RegisterManager(grpc)
		go grpc.Serve(lis)

		sigChan := make(chan os.Signal)
		signal.Notify(sigChan, os.Interrupt, syscall.SIGTERM)
		ctx.WithField("signal", <-sigChan).Info("signal received")

		grpc.Stop()
		broker.Shutdown()
	},
}

func init() {
	RootCmd.AddCommand(brokerCmd)

	brokerCmd.Flags().String("networkserver-address", "localhost:1903", "Networkserver host and port")
	viper.BindPFlag("broker.networkserver-address", brokerCmd.Flags().Lookup("networkserver-address"))
	brokerCmd.Flags().String("networkserver-cert", "", "Networkserver certificate to use")
	viper.BindPFlag("broker.networkserver-cert", brokerCmd.Flags().Lookup("networkserver-cert"))
	brokerCmd.Flags().String("networkserver-token", "", "Networkserver token to use")
	viper.BindPFlag("broker.networkserver-token", brokerCmd.Flags().Lookup("networkserver-token"))

	brokerCmd.Flags().Int("deduplication-delay", 200, "Deduplication delay (in ms)")
Example #2
0
		}
		defer handler.Shutdown()

		// gRPC Server
		lis, err := net.Listen("tcp", fmt.Sprintf("%s:%d", viper.GetString("handler.server-address"), viper.GetInt("handler.server-port")))
		if err != nil {
			ctx.WithError(err).Fatal("Could not start gRPC server")
		}
		grpc := grpc.NewServer(component.ServerOptions()...)

		// Register and Listen
		component.RegisterHealthServer(grpc)
		handler.RegisterRPC(grpc)
		handler.RegisterManager(grpc)
		go grpc.Serve(lis)
		defer grpc.Stop()

		if httpActive {
			proxyConn, err := component.Identity.Dial()
			if err != nil {
				ctx.WithError(err).Fatal("Could not start client for gRPC proxy")
			}
			mux := runtime.NewServeMux()
			netCtx, cancel := context.WithCancel(context.Background())
			defer cancel()
			pb.RegisterApplicationManagerHandler(netCtx, mux, proxyConn)

			prxy := proxy.WithToken(mux)
			prxy = proxy.WithLogger(prxy, ctx)

			go func() {