allow to subscribe/unsubscribe while server running #15

Closed
opened 2020-10-09 14:11:50 +03:00 by vtolstov · 1 comment
vtolstov commented 2020-10-09 14:11:50 +03:00 (Migrated from github.com)

for grpc for ex add to Subscribe func

 handler := g.createSubHandler(sb, config)                                                   
 var opts []broker.SubscribeOption                                                           
 if queue := sb.Options().Queue; len(queue) > 0 {                                            
   opts = append(opts, broker.SubscribeGroup(queue))                                         
 }                                                                                           
                                                                                             
 subCtx := config.Context                                                                    
 if cx := sb.Options().Context; cx != nil {                                                  
   subCtx = cx                                                                               
 }                                                                                           
 opts = append(opts, broker.SubscribeContext(subCtx))                                        
 opts = append(opts, broker.SubscribeAutoAck(sb.Options().AutoAck))                          
                                                                                             
 if config.Logger.V(logger.InfoLevel) {                                                      
   config.Logger.Infof(config.Context, "Subscribing to topic: %s", sb.Topic())               
 }                                                                                           
 sub, err := config.Broker.Subscribe(subCtx, sb.Topic(), handler, opts...)                   
 if err != nil {                                                                             
   return err                                                                                
 }                                                                                           
 g.subscribers[sb] = []broker.Subscriber{sub}                                                

also add Unsubscribe method

for grpc for ex add to Subscribe func ```go handler := g.createSubHandler(sb, config) var opts []broker.SubscribeOption if queue := sb.Options().Queue; len(queue) > 0 { opts = append(opts, broker.SubscribeGroup(queue)) } subCtx := config.Context if cx := sb.Options().Context; cx != nil { subCtx = cx } opts = append(opts, broker.SubscribeContext(subCtx)) opts = append(opts, broker.SubscribeAutoAck(sb.Options().AutoAck)) if config.Logger.V(logger.InfoLevel) { config.Logger.Infof(config.Context, "Subscribing to topic: %s", sb.Topic()) } sub, err := config.Broker.Subscribe(subCtx, sb.Topic(), handler, opts...) if err != nil { return err } g.subscribers[sb] = []broker.Subscriber{sub} ``` also add Unsubscribe method

not needed in micro v4

not needed in micro v4
Sign in to join this conversation.
No description provided.