Moving mercury example to plugins
This commit is contained in:
parent
51d2ce2b4f
commit
1cbe06413e
@ -1,7 +0,0 @@
|
|||||||
# Mercury
|
|
||||||
|
|
||||||
An **experimental** integration for [mondo/mercury](https://github.com/mondough/mercury)
|
|
||||||
|
|
||||||
mercury/{client,server} are standard mercury implementations for compatibility testing sake.
|
|
||||||
|
|
||||||
micro/{client,server} are micro implementations of mercury's request/response system.
|
|
@ -1,30 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
hello "github.com/micro/micro/examples/greeter/server/proto/hello"
|
|
||||||
"github.com/mondough/mercury"
|
|
||||||
tmsg "github.com/mondough/typhon/message"
|
|
||||||
"github.com/mondough/typhon/rabbit"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
req := mercury.NewRequest()
|
|
||||||
req.SetService("foo")
|
|
||||||
req.SetEndpoint("Say.Hello")
|
|
||||||
req.SetBody(&hello.Request{
|
|
||||||
Name: "John",
|
|
||||||
})
|
|
||||||
tmsg.ProtoMarshaler().MarshalBody(req)
|
|
||||||
trans := rabbit.NewTransport()
|
|
||||||
rsp, err := trans.Send(req, time.Second)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
tmsg.ProtoUnmarshaler(new(hello.Response)).UnmarshalPayload(rsp)
|
|
||||||
|
|
||||||
fmt.Println(rsp.Body())
|
|
||||||
}
|
|
@ -1,34 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/mondough/mercury"
|
|
||||||
"github.com/mondough/mercury/server"
|
|
||||||
"github.com/mondough/mercury/service"
|
|
||||||
"github.com/mondough/typhon/rabbit"
|
|
||||||
|
|
||||||
hello "github.com/micro/micro/examples/greeter/server/proto/hello"
|
|
||||||
)
|
|
||||||
|
|
||||||
func handler(req mercury.Request) (mercury.Response, error) {
|
|
||||||
request := req.Body().(*hello.Request)
|
|
||||||
rsp := req.Response(&hello.Response{
|
|
||||||
Msg: "Hey " + request.Name,
|
|
||||||
})
|
|
||||||
return rsp, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
s := service.Init(service.Config{
|
|
||||||
Name: "foo",
|
|
||||||
Transport: rabbit.NewTransport(),
|
|
||||||
})
|
|
||||||
|
|
||||||
s.Server().AddEndpoints(server.Endpoint{
|
|
||||||
Name: "Say.Hello",
|
|
||||||
Handler: handler,
|
|
||||||
Request: new(hello.Request),
|
|
||||||
Response: new(hello.Response),
|
|
||||||
})
|
|
||||||
|
|
||||||
s.Run()
|
|
||||||
}
|
|
@ -1,37 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/micro/go-micro/client"
|
|
||||||
mcodec "github.com/micro/go-plugins/codec/mercury"
|
|
||||||
"github.com/micro/go-plugins/selector/mercury"
|
|
||||||
"github.com/micro/go-plugins/transport/rabbitmq"
|
|
||||||
hello "github.com/micro/micro/examples/greeter/server/proto/hello"
|
|
||||||
|
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
|
||||||
|
|
||||||
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)
|
|
||||||
}
|
|
@ -1,38 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"flag"
|
|
||||||
"github.com/micro/go-micro/server"
|
|
||||||
mcodec "github.com/micro/go-plugins/codec/mercury"
|
|
||||||
"github.com/micro/go-plugins/transport/rabbitmq"
|
|
||||||
hello "github.com/micro/micro/examples/greeter/server/proto/hello"
|
|
||||||
|
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Say struct{}
|
|
||||||
|
|
||||||
func (s *Say) Hello(ctx context.Context, req *hello.Request, rsp *hello.Response) error {
|
|
||||||
rsp.Msg = "Hey " + req.Name
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
flag.Parse()
|
|
||||||
rabbitmq.DefaultExchange = "b2a"
|
|
||||||
rabbitmq.DefaultRabbitURL = "amqp://localhost:5672"
|
|
||||||
|
|
||||||
s := server.NewServer(
|
|
||||||
server.Name("foo"),
|
|
||||||
server.Id("foo"),
|
|
||||||
server.Address("foo"),
|
|
||||||
server.Transport(rabbitmq.NewTransport([]string{})),
|
|
||||||
server.Codec("application/x-protobuf", mcodec.NewCodec),
|
|
||||||
)
|
|
||||||
s.Handle(
|
|
||||||
s.NewHandler(&Say{}),
|
|
||||||
)
|
|
||||||
|
|
||||||
s.Start()
|
|
||||||
select {}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user