commit
fe4362be5a
16
README.md
16
README.md
@ -110,10 +110,10 @@ $ consul agent -dev -advertise=127.0.0.1
|
||||
|
||||
### Run Service
|
||||
```
|
||||
$ go run examples/service/main.go --logtostderr
|
||||
I0102 00:22:26.413467 12018 rpc_server.go:297] Listening on [::]:62492
|
||||
I0102 00:22:26.413803 12018 http_broker.go:115] Broker Listening on [::]:62493
|
||||
I0102 00:22:26.414009 12018 rpc_server.go:212] Registering node: greeter-e6b2fc6f-b0e6-11e5-a42f-68a86d0d36b6
|
||||
$ go run examples/service/main.go
|
||||
2016/03/14 10:59:14 Listening on [::]:50137
|
||||
2016/03/14 10:59:14 Broker Listening on [::]:50138
|
||||
2016/03/14 10:59:14 Registering node: greeter-ca62b017-e9d3-11e5-9bbb-68a86d0d36b6
|
||||
```
|
||||
|
||||
### Test Service
|
||||
@ -216,10 +216,10 @@ func main() {
|
||||
|
||||
### Run service
|
||||
```
|
||||
go run examples/service/main.go --logtostderr
|
||||
I0102 00:22:26.413467 12018 rpc_server.go:297] Listening on [::]:62492
|
||||
I0102 00:22:26.413803 12018 http_broker.go:115] Broker Listening on [::]:62493
|
||||
I0102 00:22:26.414009 12018 rpc_server.go:212] Registering node: greeter-e6b2fc6f-b0e6-11e5-a42f-68a86d0d36b6
|
||||
go run examples/service/main.go
|
||||
2016/03/14 10:59:14 Listening on [::]:50137
|
||||
2016/03/14 10:59:14 Broker Listening on [::]:50138
|
||||
2016/03/14 10:59:14 Registering node: greeter-ca62b017-e9d3-11e5-9bbb-68a86d0d36b6
|
||||
```
|
||||
|
||||
### Define a client
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"math/rand"
|
||||
"net"
|
||||
"net/http"
|
||||
@ -17,7 +18,6 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
log "github.com/golang/glog"
|
||||
"github.com/micro/go-micro/errors"
|
||||
"github.com/micro/go-micro/registry"
|
||||
mls "github.com/micro/misc/lib/tls"
|
||||
@ -217,7 +217,7 @@ func (h *httpBroker) start() error {
|
||||
return err
|
||||
}
|
||||
|
||||
log.Infof("Broker Listening on %s", l.Addr().String())
|
||||
log.Printf("Broker Listening on %s", l.Addr().String())
|
||||
h.address = l.Addr().String()
|
||||
|
||||
go http.Serve(l, h)
|
||||
|
42
cmd/cmd.go
42
cmd/cmd.go
@ -1,7 +1,6 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"math/rand"
|
||||
@ -105,36 +104,6 @@ var (
|
||||
EnvVar: "MICRO_TRANSPORT_ADDRESS",
|
||||
Usage: "Comma-separated list of transport addresses",
|
||||
},
|
||||
|
||||
// logging flags
|
||||
cli.BoolFlag{
|
||||
Name: "logtostderr",
|
||||
Usage: "log to standard error instead of files",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "alsologtostderr",
|
||||
Usage: "log to standard error as well as files",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "log_dir",
|
||||
Usage: "log files will be written to this directory instead of the default temporary directory",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "stderrthreshold",
|
||||
Usage: "logs at or above this threshold go to stderr",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "v",
|
||||
Usage: "log level for V logs",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "vmodule",
|
||||
Usage: "comma-separated list of pattern=N settings for file-filtered logging",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "log_backtrace_at",
|
||||
Usage: "when logging hits line file:N, emit a stack trace",
|
||||
},
|
||||
}
|
||||
|
||||
DefaultBrokers = map[string]func([]string, ...broker.Option) broker.Broker{
|
||||
@ -218,17 +187,6 @@ func (c *cmd) Options() Options {
|
||||
}
|
||||
|
||||
func (c *cmd) Before(ctx *cli.Context) error {
|
||||
// Due to logger issues with glog, we need to do this
|
||||
os.Args = os.Args[:1]
|
||||
flag.Set("logtostderr", fmt.Sprintf("%v", ctx.Bool("logtostderr")))
|
||||
flag.Set("alsologtostderr", fmt.Sprintf("%v", ctx.Bool("alsologtostderr")))
|
||||
flag.Set("stderrthreshold", ctx.String("stderrthreshold"))
|
||||
flag.Set("log_backtrace_at", ctx.String("log_backtrace_at"))
|
||||
flag.Set("log_dir", ctx.String("log_dir"))
|
||||
flag.Set("vmodule", ctx.String("vmodule"))
|
||||
flag.Set("v", ctx.String("v"))
|
||||
flag.Parse()
|
||||
|
||||
// If flags are set then use them otherwise do nothing
|
||||
var serverOpts []server.Option
|
||||
var clientOpts []client.Option
|
||||
|
@ -2,8 +2,8 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
log "github.com/golang/glog"
|
||||
"github.com/micro/go-micro/broker"
|
||||
"github.com/micro/go-micro/cmd"
|
||||
// To enable rabbitmq plugin uncomment
|
||||
|
@ -2,9 +2,9 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
log "github.com/golang/glog"
|
||||
"github.com/micro/go-micro/broker"
|
||||
"github.com/micro/go-micro/cmd"
|
||||
)
|
||||
@ -24,7 +24,7 @@ func pub() {
|
||||
Body: []byte(fmt.Sprintf("%d: %s", i, time.Now().String())),
|
||||
}
|
||||
if err := broker.Publish(topic, msg); err != nil {
|
||||
log.Errorf("[pub] failed: %v", err)
|
||||
log.Printf("[pub] failed: %v", err)
|
||||
} else {
|
||||
fmt.Println("[pub] pubbed message:", string(msg.Body))
|
||||
}
|
||||
|
@ -2,9 +2,9 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
log "github.com/golang/glog"
|
||||
"github.com/micro/go-micro/broker"
|
||||
"github.com/micro/go-micro/cmd"
|
||||
// To enable rabbitmq plugin uncomment
|
||||
@ -26,7 +26,7 @@ func pub() {
|
||||
Body: []byte(fmt.Sprintf("%d: %s", i, time.Now().String())),
|
||||
}
|
||||
if err := broker.Publish(topic, msg); err != nil {
|
||||
log.Errorf("[pub] failed: %v", err)
|
||||
log.Printf("[pub] failed: %v", err)
|
||||
} else {
|
||||
fmt.Println("[pub] pubbed message:", string(msg.Body))
|
||||
}
|
||||
|
@ -1,7 +1,8 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
log "github.com/golang/glog"
|
||||
"log"
|
||||
|
||||
"github.com/micro/go-micro/cmd"
|
||||
"github.com/micro/go-micro/examples/server/subscriber"
|
||||
"github.com/micro/go-micro/server"
|
||||
@ -13,16 +14,16 @@ import (
|
||||
type Example struct{}
|
||||
|
||||
func (e *Example) Call(ctx context.Context, req *example.Request, rsp *example.Response) error {
|
||||
log.Info("Received Example.Call request")
|
||||
log.Print("Received Example.Call request")
|
||||
rsp.Msg = server.DefaultOptions().Id + ": Hello " + req.Name
|
||||
return nil
|
||||
}
|
||||
|
||||
func (e *Example) Stream(ctx context.Context, req *example.StreamingRequest, stream example.Example_StreamStream) error {
|
||||
log.Infof("Received Example.Stream request with count: %d", req.Count)
|
||||
log.Printf("Received Example.Stream request with count: %d", req.Count)
|
||||
|
||||
for i := 0; i < int(req.Count); i++ {
|
||||
log.Infof("Responding: %d", i)
|
||||
log.Printf("Responding: %d", i)
|
||||
if err := stream.Send(&example.StreamingResponse{
|
||||
Count: int64(i),
|
||||
}); err != nil {
|
||||
@ -39,7 +40,7 @@ func (e *Example) PingPong(ctx context.Context, stream example.Example_PingPongS
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
log.Infof("Got ping %v", req.Stroke)
|
||||
log.Printf("Got ping %v", req.Stroke)
|
||||
if err := stream.Send(&example.Pong{Stroke: req.Stroke}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -1,7 +1,8 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
log "github.com/golang/glog"
|
||||
"log"
|
||||
|
||||
example "github.com/micro/go-micro/examples/server/proto/example"
|
||||
"github.com/micro/go-micro/metadata"
|
||||
"github.com/micro/go-micro/server"
|
||||
@ -13,25 +14,25 @@ type Example struct{}
|
||||
|
||||
func (e *Example) Call(ctx context.Context, req *example.Request, rsp *example.Response) error {
|
||||
md, _ := metadata.FromContext(ctx)
|
||||
log.Infof("Received Example.Call request with metadata: %v", md)
|
||||
log.Printf("Received Example.Call request with metadata: %v", md)
|
||||
rsp.Msg = server.DefaultOptions().Id + ": Hello " + req.Name
|
||||
return nil
|
||||
}
|
||||
|
||||
func (e *Example) Stream(ctx context.Context, stream server.Streamer) error {
|
||||
log.Info("Executing streaming handler")
|
||||
log.Print("Executing streaming handler")
|
||||
req := &example.StreamingRequest{}
|
||||
|
||||
// We just want to receive 1 request and then process here
|
||||
if err := stream.Recv(req); err != nil {
|
||||
log.Errorf("Error receiving streaming request: %v", err)
|
||||
log.Printf("Error receiving streaming request: %v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
log.Infof("Received Example.Stream request with count: %d", req.Count)
|
||||
log.Printf("Received Example.Stream request with count: %d", req.Count)
|
||||
|
||||
for i := 0; i < int(req.Count); i++ {
|
||||
log.Infof("Responding: %d", i)
|
||||
log.Printf("Responding: %d", i)
|
||||
|
||||
if err := stream.Send(&example.StreamingResponse{
|
||||
Count: int64(i),
|
||||
@ -49,7 +50,7 @@ func (e *Example) PingPong(ctx context.Context, stream server.Streamer) error {
|
||||
if err := stream.Recv(req); err != nil {
|
||||
return err
|
||||
}
|
||||
log.Infof("Got ping %v", req.Stroke)
|
||||
log.Printf("Got ping %v", req.Stroke)
|
||||
if err := stream.Send(&example.Pong{Stroke: req.Stroke}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -1,7 +1,8 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
log "github.com/golang/glog"
|
||||
"log"
|
||||
|
||||
"github.com/micro/go-micro/cmd"
|
||||
"github.com/micro/go-micro/examples/server/handler"
|
||||
"github.com/micro/go-micro/examples/server/subscriber"
|
||||
|
@ -1,7 +1,8 @@
|
||||
package subscriber
|
||||
|
||||
import (
|
||||
log "github.com/golang/glog"
|
||||
"log"
|
||||
|
||||
example "github.com/micro/go-micro/examples/server/proto/example"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
@ -9,11 +10,11 @@ import (
|
||||
type Example struct{}
|
||||
|
||||
func (e *Example) Handle(ctx context.Context, msg *example.Message) error {
|
||||
log.Info("Handler Received message: ", msg.Say)
|
||||
log.Print("Handler Received message: ", msg.Say)
|
||||
return nil
|
||||
}
|
||||
|
||||
func Handler(ctx context.Context, msg *example.Message) error {
|
||||
log.Info("Function Received message: ", msg.Say)
|
||||
log.Print("Function Received message: ", msg.Say)
|
||||
return nil
|
||||
}
|
||||
|
@ -1,7 +1,8 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
log "github.com/golang/glog"
|
||||
"log"
|
||||
|
||||
"github.com/micro/go-micro/cmd"
|
||||
"github.com/micro/go-micro/examples/server/handler"
|
||||
"github.com/micro/go-micro/examples/server/subscriber"
|
||||
@ -11,18 +12,18 @@ import (
|
||||
|
||||
func logWrapper(fn server.HandlerFunc) server.HandlerFunc {
|
||||
return func(ctx context.Context, req server.Request, rsp interface{}) error {
|
||||
log.Infof("[Log Wrapper] Before serving request method: %v", req.Method())
|
||||
log.Printf("[Log Wrapper] Before serving request method: %v", req.Method())
|
||||
err := fn(ctx, req, rsp)
|
||||
log.Infof("[Log Wrapper] After serving request")
|
||||
log.Printf("[Log Wrapper] After serving request")
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
func logSubWrapper(fn server.SubscriberFunc) server.SubscriberFunc {
|
||||
return func(ctx context.Context, req server.Publication) error {
|
||||
log.Infof("[Log Sub Wrapper] Before serving publication topic: %v", req.Topic())
|
||||
log.Printf("[Log Sub Wrapper] Before serving publication topic: %v", req.Topic())
|
||||
err := fn(ctx, req)
|
||||
log.Infof("[Log Sub Wrapper] After serving publication")
|
||||
log.Printf("[Log Sub Wrapper] After serving publication")
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package server
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"runtime/debug"
|
||||
"strconv"
|
||||
"strings"
|
||||
@ -13,8 +14,6 @@ import (
|
||||
"github.com/micro/go-micro/registry"
|
||||
"github.com/micro/go-micro/transport"
|
||||
|
||||
log "github.com/golang/glog"
|
||||
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
@ -48,7 +47,7 @@ func newRpcServer(opts ...Option) Server {
|
||||
func (s *rpcServer) accept(sock transport.Socket) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
log.Error(r, string(debug.Stack()))
|
||||
log.Print(r, string(debug.Stack()))
|
||||
sock.Close()
|
||||
}
|
||||
}()
|
||||
@ -85,7 +84,7 @@ func (s *rpcServer) accept(sock transport.Socket) {
|
||||
|
||||
// TODO: needs better error handling
|
||||
if err := s.rpc.serveRequest(ctx, codec, ct); err != nil {
|
||||
log.Errorf("Unexpected error serving request, closing socket: %v", err)
|
||||
log.Printf("Unexpected error serving request, closing socket: %v", err)
|
||||
sock.Close()
|
||||
}
|
||||
}
|
||||
@ -235,7 +234,7 @@ func (s *rpcServer) Register() error {
|
||||
s.Unlock()
|
||||
|
||||
if !registered {
|
||||
log.Infof("Registering node: %s", node.Id)
|
||||
log.Printf("Registering node: %s", node.Id)
|
||||
}
|
||||
|
||||
// create registry options
|
||||
@ -310,7 +309,7 @@ func (s *rpcServer) Deregister() error {
|
||||
Nodes: []*registry.Node{node},
|
||||
}
|
||||
|
||||
log.Infof("Deregistering node: %s", node.Id)
|
||||
log.Printf("Deregistering node: %s", node.Id)
|
||||
if err := config.Registry.Deregister(service); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -326,7 +325,7 @@ func (s *rpcServer) Deregister() error {
|
||||
|
||||
for sb, subs := range s.subscribers {
|
||||
for _, sub := range subs {
|
||||
log.Infof("Unsubscribing from topic: %s", sub.Topic())
|
||||
log.Printf("Unsubscribing from topic: %s", sub.Topic())
|
||||
sub.Unsubscribe()
|
||||
}
|
||||
s.subscribers[sb] = nil
|
||||
@ -345,7 +344,7 @@ func (s *rpcServer) Start() error {
|
||||
return err
|
||||
}
|
||||
|
||||
log.Infof("Listening on %s", ts.Addr())
|
||||
log.Printf("Listening on %s", ts.Addr())
|
||||
s.Lock()
|
||||
s.opts.Address = ts.Addr()
|
||||
s.Unlock()
|
||||
|
@ -29,11 +29,11 @@ and pub/sub.
|
||||
package server
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
|
||||
log "github.com/golang/glog"
|
||||
"github.com/pborman/uuid"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
@ -167,7 +167,7 @@ func Run() error {
|
||||
|
||||
ch := make(chan os.Signal, 1)
|
||||
signal.Notify(ch, syscall.SIGTERM, syscall.SIGINT, syscall.SIGKILL)
|
||||
log.Infof("Received signal %s", <-ch)
|
||||
log.Printf("Received signal %s", <-ch)
|
||||
|
||||
if err := DefaultServer.Deregister(); err != nil {
|
||||
return err
|
||||
@ -179,13 +179,13 @@ func Run() error {
|
||||
// Starts the default server
|
||||
func Start() error {
|
||||
config := DefaultServer.Options()
|
||||
log.Infof("Starting server %s id %s", config.Name, config.Id)
|
||||
log.Printf("Starting server %s id %s", config.Name, config.Id)
|
||||
return DefaultServer.Start()
|
||||
}
|
||||
|
||||
// Stops the default server
|
||||
func Stop() error {
|
||||
log.Infof("Stopping server")
|
||||
log.Printf("Stopping server")
|
||||
return DefaultServer.Stop()
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user