1
0
mirror of https://github.com/go-micro/go-micro.git synced 2025-11-23 21:44:41 +02:00

Subscribe error handling (#2785)

* [fix] etcd config source prefix issue (#2389)

* http transport data race issue (#2436)

* [fix] #2431 http transport data race issue

* [feature] Ability to close connection while receiving.
Ability to send messages while receiving.
Icreased r channel limit to 100 to more fluently communication.
Do not dropp sent request if r channel is full.

* [feature] always subscribes to all topics and if there is an error in one of them, the unsuccessful topics will be subscribed to again

---------

Co-authored-by: Johnson C <chengqiaosheng@gmail.com>
This commit is contained in:
Ak-Army
2025-06-04 09:55:17 +02:00
committed by GitHub
parent 0e45edf439
commit 88f38eaef6
2 changed files with 30 additions and 25 deletions

View File

@@ -101,7 +101,7 @@ func (s *rpcServer) Subscribe(sb Subscriber) error {
// subscribeServer will subscribe the server to the topic with its own name.
func (s *rpcServer) subscribeServer(config Options) error {
if s.opts.Router != nil {
if s.opts.Router != nil && s.subscriber == nil {
sub, err := s.opts.Broker.Subscribe(config.Name, s.HandleEvent)
if err != nil {
return err
@@ -115,8 +115,11 @@ func (s *rpcServer) subscribeServer(config Options) error {
}
// reSubscribe itterates over subscribers and re-subscribes then.
func (s *rpcServer) reSubscribe(config Options) error {
func (s *rpcServer) reSubscribe(config Options) {
for sb := range s.subscribers {
if s.subscribers[sb] != nil {
continue
}
var opts []broker.SubscribeOption
if queue := sb.Options().Queue; len(queue) > 0 {
opts = append(opts, broker.Queue(queue))
@@ -133,12 +136,15 @@ func (s *rpcServer) reSubscribe(config Options) error {
config.Logger.Logf(log.InfoLevel, "Subscribing to topic: %s", sb.Topic())
sub, err := config.Broker.Subscribe(sb.Topic(), s.HandleEvent, opts...)
if err != nil {
return err
config.Logger.Logf(log.WarnLevel, "Unable to subscribing to topic: %s, error: %s", sb.Topic(), err)
continue
}
err = s.router.Subscribe(sb)
if err != nil {
config.Logger.Logf(log.WarnLevel, "Unable to subscribing to topic: %s, error: %s", sb.Topic(), err)
sub.Unsubscribe()
continue
}
s.subscribers[sb] = []broker.Subscriber{sub}
s.router.Subscribe(sb)
}
return nil
}