Add pub/sub to client/server and make broker more low level
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
log "github.com/golang/glog"
|
||||
"github.com/myodc/go-micro/cmd"
|
||||
"github.com/myodc/go-micro/examples/server/handler"
|
||||
"github.com/myodc/go-micro/examples/server/subscriber"
|
||||
"github.com/myodc/go-micro/server"
|
||||
)
|
||||
|
||||
@@ -23,6 +24,21 @@ func main() {
|
||||
),
|
||||
)
|
||||
|
||||
// Register Subscribers
|
||||
server.Subscribe(
|
||||
server.NewSubscriber(
|
||||
"topic.go.micro.srv.example",
|
||||
new(subscriber.Example),
|
||||
),
|
||||
)
|
||||
|
||||
server.Subscribe(
|
||||
server.NewSubscriber(
|
||||
"topic.go.micro.srv.example",
|
||||
subscriber.Handler,
|
||||
),
|
||||
)
|
||||
|
||||
// Run server
|
||||
if err := server.Run(); err != nil {
|
||||
log.Fatal(err)
|
||||
|
@@ -9,6 +9,7 @@ It is generated from these files:
|
||||
go-micro/examples/server/proto/example/example.proto
|
||||
|
||||
It has these top-level messages:
|
||||
Message
|
||||
Request
|
||||
Response
|
||||
StreamingRequest
|
||||
@@ -21,6 +22,14 @@ import proto "github.com/golang/protobuf/proto"
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
var _ = proto.Marshal
|
||||
|
||||
type Message struct {
|
||||
Say string `protobuf:"bytes,1,opt,name=say" json:"say,omitempty"`
|
||||
}
|
||||
|
||||
func (m *Message) Reset() { *m = Message{} }
|
||||
func (m *Message) String() string { return proto.CompactTextString(m) }
|
||||
func (*Message) ProtoMessage() {}
|
||||
|
||||
type Request struct {
|
||||
Name string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"`
|
||||
}
|
||||
|
@@ -1,5 +1,9 @@
|
||||
syntax = "proto3";
|
||||
|
||||
message Message {
|
||||
string say = 1;
|
||||
}
|
||||
|
||||
message Request {
|
||||
string name = 1;
|
||||
}
|
||||
|
18
examples/server/subscriber/subscriber.go
Normal file
18
examples/server/subscriber/subscriber.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package subscriber
|
||||
|
||||
import (
|
||||
log "github.com/golang/glog"
|
||||
example "github.com/myodc/go-micro/examples/server/proto/example"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
type Example struct{}
|
||||
|
||||
func (e *Example) Handle(ctx context.Context, msg *example.Message) error {
|
||||
log.Info("Handler Received message: ", msg.Say)
|
||||
return nil
|
||||
}
|
||||
|
||||
func Handler(msg *example.Message) {
|
||||
log.Info("Function Received message: ", msg.Say)
|
||||
}
|
Reference in New Issue
Block a user