Example #1
0
func main() {
	cmd.Init()

	r := router.NewRouter()
	c := client.NewClient(client.Selector(r))
	c = router.NewLabelWrapper(c)

	// Create new request to service go.micro.srv.greeter, method Say.Hello
	req := c.NewRequest("go.micro.srv.greeter", "Say.Hello", &hello.Request{
		Name: "John",
	})

	rsp := &hello.Response{}

	// Set arbitrary headers in context
	ctx := metadata.NewContext(context.Background(), map[string]string{
		router.LabelPrefix + "Greeter": "one",
	})

	// Call service
	if err := c.Call(ctx, req, rsp); err != nil {
		fmt.Println(err)
		return
	}

	fmt.Println(rsp.Msg)
}
Example #2
0
func main() {
	cmd.Init()

	t := trace.NewTrace()

	srv := &registry.Service{
		Name: "go.client",
	}

	client.DefaultClient = client.NewClient(
		client.Wrap(
			trace.ClientWrapper(t, srv),
		),
	)

	fmt.Println("Starting trace")
	if err := t.Start(); err != nil {
		fmt.Println(err)
		return
	}

	fmt.Println("\n--- Traced Call example ---\n")
	i := 0
	for {
		call(i)
		i++
		<-time.After(time.Second * 5)
	}

	if err := t.Stop(); err != nil {
		fmt.Println(err)
	}
}
Example #3
0
func TestBreaker(t *testing.T) {
	// setup
	r := mock.NewRegistry()
	s := selector.NewSelector(selector.Registry(r))

	c := client.NewClient(
		// set the selector
		client.Selector(s),
		// add the breaker wrapper
		client.Wrap(NewClientWrapper()),
	)

	req := c.NewJsonRequest("test.service", "Test.Method", map[string]string{
		"foo": "bar",
	})

	var rsp map[string]interface{}

	// Force to point of trip
	for i := 0; i < (hystrix.DefaultVolumeThreshold * 2); i++ {
		c.Call(context.TODO(), req, rsp)
	}

	err := c.Call(context.TODO(), req, rsp)
	if err == nil {
		t.Error("Expecting tripped breaker, got nil error")
	}

	if err.Error() != "hystrix: circuit open" {
		t.Errorf("Expecting tripped breaker, got %v", err)
	}
}
Example #4
0
func main() {
	cmd.Init()

	t := zipkin.NewTrace(
		trace.Collectors("192.168.99.100:9092"),
	)
	defer t.Close()

	client.DefaultClient = client.NewClient(
		client.Wrap(
			trace.ClientWrapper(t, nil),
		),
	)

	fmt.Println("\n--- Traced Call example ---\n")
	for i := 0; i < 10; i++ {
		call(i)
	}

	/*
		fmt.Println("\n--- Streamer example ---\n")
		stream(10)

		fmt.Println("\n--- Ping Pong example ---\n")
		pingPong(10)

		fmt.Println("\n--- Publisher example ---\n")
		pub()
	*/
	<-time.After(time.Second * 10)
}
Example #5
0
func NewLabelClient(serviceName string, c client.Client) LabelClient {
	if c == nil {
		c = client.NewClient()
	}
	if len(serviceName) == 0 {
		serviceName = "go.micro.srv.router.label"
	}
	return &labelClient{
		c:           c,
		serviceName: serviceName,
	}
}
Example #6
0
func NewGeoClient(serviceName string, c client.Client) GeoClient {
	if c == nil {
		c = client.NewClient()
	}
	if len(serviceName) == 0 {
		serviceName = "geo"
	}
	return &geoClient{
		c:           c,
		serviceName: serviceName,
	}
}
Example #7
0
func NewElasticClient(serviceName string, c client.Client) ElasticClient {
	if c == nil {
		c = client.NewClient()
	}
	if len(serviceName) == 0 {
		serviceName = "go.micro.srv.elastic"
	}
	return &elasticClient{
		c:           c,
		serviceName: serviceName,
	}
}
Example #8
0
func NewProfileClient(serviceName string, c client.Client) ProfileClient {
	if c == nil {
		c = client.NewClient()
	}
	if len(serviceName) == 0 {
		serviceName = "profile"
	}
	return &profileClient{
		c:           c,
		serviceName: serviceName,
	}
}
Example #9
0
func main() {
	cmd.Init()

	client.DefaultClient = client.NewClient(
		client.Wrap(NewDCWrapper),
	)

	fmt.Println("\n--- Call example ---\n")
	for i := 0; i < 10; i++ {
		call(i)
	}
}
func NewMonitorClient(serviceName string, c client.Client) MonitorClient {
	if c == nil {
		c = client.NewClient()
	}
	if len(serviceName) == 0 {
		serviceName = "monitor"
	}
	return &monitorClient{
		c:           c,
		serviceName: serviceName,
	}
}
Example #11
0
func NewDBClient(serviceName string, c client.Client) DBClient {
	if c == nil {
		c = client.NewClient()
	}
	if len(serviceName) == 0 {
		serviceName = "go.micro.srv.db.db"
	}
	return &dBClient{
		c:           c,
		serviceName: serviceName,
	}
}
Example #12
0
func NewSayClient(serviceName string, c client.Client) SayClient {
	if c == nil {
		c = client.NewClient()
	}
	if len(serviceName) == 0 {
		serviceName = "go.micro.srv.greeter"
	}
	return &sayClient{
		c:           c,
		serviceName: serviceName,
	}
}
Example #13
0
func NewGreeterClient(serviceName string, c client.Client) GreeterClient {
	if c == nil {
		c = client.NewClient()
	}
	if len(serviceName) == 0 {
		serviceName = "go.micro.api.greeter"
	}
	return &greeterClient{
		c:           c,
		serviceName: serviceName,
	}
}
Example #14
0
func NewAuthClient(serviceName string, c client.Client) AuthClient {
	if c == nil {
		c = client.NewClient()
	}
	if len(serviceName) == 0 {
		serviceName = "auth"
	}
	return &authClient{
		c:           c,
		serviceName: serviceName,
	}
}
Example #15
0
func NewAccountClient(serviceName string, c client.Client) AccountClient {
	if c == nil {
		c = client.NewClient()
	}
	if len(serviceName) == 0 {
		serviceName = "account"
	}
	return &accountClient{
		c:           c,
		serviceName: serviceName,
	}
}
Example #16
0
func NewRuleClient(serviceName string, c client.Client) RuleClient {
	if c == nil {
		c = client.NewClient()
	}
	if len(serviceName) == 0 {
		serviceName = "go.micro.srv.router.rule"
	}
	return &ruleClient{
		c:           c,
		serviceName: serviceName,
	}
}
Example #17
0
func NewKVClient(serviceName string, c client.Client) KVClient {
	if c == nil {
		c = client.NewClient()
	}
	if len(serviceName) == 0 {
		serviceName = "go.micro.os.kv"
	}
	return &kVClient{
		c:           c,
		serviceName: serviceName,
	}
}
Example #18
0
func NewExampleClient(serviceName string, c client.Client) ExampleClient {
	if c == nil {
		c = client.NewClient()
	}
	if len(serviceName) == 0 {
		serviceName = "go.micro.srv.example"
	}
	return &exampleClient{
		c:           c,
		serviceName: serviceName,
	}
}
Example #19
0
func main() {
	cmd.Init()

	client.DefaultClient = client.NewClient(
		client.Selector(DCSelector()),
	)

	fmt.Println("\n--- Call example ---\n")
	for i := 0; i < 10; i++ {
		call(i)
	}
}
Example #20
0
func NewConfigClient(serviceName string, c client.Client) ConfigClient {
	if c == nil {
		c = client.NewClient()
	}
	if len(serviceName) == 0 {
		serviceName = "go.micro.srv.config.config"
	}
	return &configClient{
		c:           c,
		serviceName: serviceName,
	}
}
Example #21
0
func NewHotelClient(serviceName string, c client.Client) HotelClient {
	if c == nil {
		c = client.NewClient()
	}
	if len(serviceName) == 0 {
		serviceName = "hotel"
	}
	return &hotelClient{
		c:           c,
		serviceName: serviceName,
	}
}
Example #22
0
func NewOauth2Client(serviceName string, c client.Client) Oauth2Client {
	if c == nil {
		c = client.NewClient()
	}
	if len(serviceName) == 0 {
		serviceName = "go.micro.srv.auth.oauth2"
	}
	return &oauth2Client{
		c:           c,
		serviceName: serviceName,
	}
}
Example #23
0
func NewRateClient(serviceName string, c client.Client) RateClient {
	if c == nil {
		c = client.NewClient()
	}
	if len(serviceName) == 0 {
		serviceName = "rate"
	}
	return &rateClient{
		c:           c,
		serviceName: serviceName,
	}
}
Example #24
0
func main() {
	// Create a new service. Optionally include some options here.
	service := micro.NewService(
		micro.Client(client.NewClient(client.Wrap(logWrap))),
		micro.Server(server.NewServer(server.WrapHandler(logHandlerWrapper))),
		micro.Name("greeter"),
		micro.Version("latest"),
		micro.Metadata(map[string]string{
			"type": "helloworld",
		}),

		// Setup some flags. Specify --client to run the client

		// Add runtime flags
		// We could do this below too
		micro.Flags(cli.BoolFlag{
			Name:  "client",
			Usage: "Launch the client",
		}),
	)

	// Init will parse the command line flags. Any flags set will
	// override the above settings. Options defined here will
	// override anything set on the command line.
	service.Init(
		// Add runtime action
		// We could actually do this above
		micro.Action(func(c *cli.Context) {
			if c.Bool("client") {
				runClient(service)
				os.Exit(0)
			}
		}),
	)

	// By default we'll run the server unless the flags catch us

	// Setup the server

	// Register handler
	proto.RegisterGreeterHandler(service.Server(), new(Greeter))

	// Run the server
	if err := service.Run(); err != nil {
		fmt.Println(err)
	}
}
Example #25
0
func main() {
	// optionally setup command line usage
	cmd.Init()

	t := trace.NewTrace()
	defer t.Close()

	srv := &registry.Service{
		Name: "go.micro.srv.example",
	}

	client.DefaultClient = client.NewClient(
		client.Wrap(
			trace.ClientWrapper(t, srv),
		),
	)

	server.DefaultServer = server.NewServer(
		server.WrapHandler(trace.HandlerWrapper(t, srv)),
	)

	// Initialise Server
	server.Init(
		server.Name("go.micro.srv.example"),
	)

	// Register Handlers
	server.Handle(
		server.NewHandler(
			new(handler.Example),
		),
	)

	server.Handle(
		server.NewHandler(
			new(Ping),
		),
	)

	// Run server
	if err := server.Run(); err != nil {
		log.Fatal(err)
	}
}
Example #26
0
func main() {
	cmd.Init()

	fmt.Println("\n--- Log Wrapper example ---\n")

	// Wrap the default client
	client.DefaultClient = logWrap(client.DefaultClient)

	call(0)

	fmt.Println("\n--- Log+Trace Wrapper example ---\n")

	// Wrap using client.Wrap option
	client.DefaultClient = client.NewClient(
		client.Wrap(traceWrap),
		client.Wrap(logWrap),
	)

	call(1)
}
Example #27
0
func main() {
	cmd.Init()

	t := zipkin.NewTrace(
		trace.Collectors([]string{"192.168.99.100:9092"}),
	)

	client.DefaultClient = client.NewClient(
		client.Wrap(
			trace.ClientWrapper(t, nil),
		),
	)

	fmt.Println("Starting trace")
	if err := t.Start(); err != nil {
		fmt.Println(err)
		return
	}

	fmt.Println("\n--- Traced Call example ---\n")
	for i := 0; i < 10; i++ {
		call(i)
	}

	/*
		fmt.Println("\n--- Streamer example ---\n")
		stream(10)

		fmt.Println("\n--- Ping Pong example ---\n")
		pingPong(10)

		fmt.Println("\n--- Publisher example ---\n")
		pub()
	*/
	<-time.After(time.Second * 10)

	if err := t.Stop(); err != nil {
		fmt.Println(err)
	}
}
Example #28
0
func main() {
	rabbitmq.DefaultExchange = "b2a"
	rabbitmq.DefaultRabbitURL = "amqp://localhost:5672"

	c := client.NewClient(
		client.Selector(mercury.NewSelector()),
		client.Transport(rabbitmq.NewTransport([]string{})),
		client.Codec("application/x-protobuf", mcodec.NewCodec),
		client.ContentType("application/x-protobuf"),
	)

	req := c.NewRequest("foo", "Say.Hello", &hello.Request{
		Name: "John",
	})

	rsp := &hello.Response{}

	if err := c.Call(context.Background(), req, rsp); err != nil {
		fmt.Println(err)
	}

	fmt.Println(rsp)
}
Example #29
0
func main() {
	cmd.Init()

	t := trace.NewTrace()
	defer t.Close()

	srv := &registry.Service{
		Name: "go.micro.client.example",
	}

	client.DefaultClient = client.NewClient(
		client.Wrap(
			trace.ClientWrapper(t, srv),
		),
	)

	fmt.Println("\n--- Traced Call example ---\n")
	i := 0
	for {
		call(i)
		i++
		<-time.After(time.Second * 5)
	}
}
Example #30
0
func NewClient(opts ...client.Option) client.Client {
	return client.NewClient(opts...)
}