1
0
mirror of https://github.com/go-micro/go-micro.git synced 2024-11-24 08:02:32 +02:00

server: subscribe to topic with own name if router not nil (#1295)

* server: subscribe to topic with own name if router not nil

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Vasiliy Tolstov 2020-03-05 10:29:50 +03:00 committed by GitHub
parent 67c26c71b6
commit ce2ba71002
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -630,6 +630,8 @@ func (s *rpcServer) Register() error {
// set what we're advertising
s.opts.Advertise = addr
// router can exchange messages
if s.opts.Router != nil {
// subscribe to the topic with own name
sub, err := s.opts.Broker.Subscribe(config.Name, s.HandleEvent)
if err != nil {
@ -638,6 +640,7 @@ func (s *rpcServer) Register() error {
// save the subscriber
s.subscriber = sub
}
// subscribe for all of the subscribers
for sb := range s.subscribers {
@ -654,11 +657,11 @@ func (s *rpcServer) Register() error {
opts = append(opts, broker.DisableAutoAck())
}
log.Infof("Subscribing to topic: %s", sub.Topic())
sub, err := config.Broker.Subscribe(sb.Topic(), s.HandleEvent, opts...)
if err != nil {
return err
}
log.Infof("Subscribing to topic: %s", sub.Topic())
s.subscribers[sb] = []broker.Subscriber{sub}
}