xujianhai666 commented on a change in pull request #97: fix remote timeout unit
and add shutdown method
URL: https://github.com/apache/rocketmq-client-go/pull/97#discussion_r300927067
##########
File path: internal/kernel/client.go
##########
@@ -124,45 +127,70 @@ func (c *RMQClient) Start() {
go func() {
// delay
time.Sleep(50 * time.Millisecond)
+ c.UpdateTopicRouteInfo()
for {
- c.UpdateTopicRouteInfo()
- time.Sleep(_PullNameServerInterval)
+ select {
+ case <-ctx.Done():
+ return
+ case <-time.Tick(_PullNameServerInterval):
+ c.UpdateTopicRouteInfo()
+ }
}
}()
// TODO cleanOfflineBroker & sendHeartbeatToAllBrokerWithLock
go func() {
+ cleanOfflineBroker()
+ c.SendHeartbeatToAllBrokerWithLock()
for {
- cleanOfflineBroker()
- c.SendHeartbeatToAllBrokerWithLock()
- time.Sleep(_HeartbeatBrokerInterval)
+ select {
+ case <-ctx.Done():
+ return
+ case <-time.Tick(_HeartbeatBrokerInterval):
+ cleanOfflineBroker()
+ c.SendHeartbeatToAllBrokerWithLock()
+ }
}
}()
// schedule persist offset
go func() {
- //time.Sleep(10 * time.Second)
+ c.consumerMap.Range(func(key, value interface{}) bool {
+ consumer := value.(InnerConsumer)
+ consumer.PersistConsumerOffset()
+ return true
+ })
for {
- c.consumerMap.Range(func(key, value
interface{}) bool {
- consumer := value.(InnerConsumer)
- consumer.PersistConsumerOffset()
- return true
- })
- time.Sleep(_PersistOffset)
+ select {
+ case <-ctx.Done():
+ return
+ case <-time.Tick(_PersistOffset):
+ c.consumerMap.Range(func(key, value
interface{}) bool {
+ consumer :=
value.(InnerConsumer)
+ consumer.PersistConsumerOffset()
+ return true
+ })
+ }
}
}()
go func() {
+ c.RebalanceImmediately()
for {
- c.RebalanceImmediately()
- time.Sleep(_RebalanceInterval)
+ select {
+ case <-ctx.Done():
+ return
+ case <-time.Tick(_RebalanceInterval):
+ c.RebalanceImmediately()
+ }
}
}()
})
}
func (c *RMQClient) Shutdown() {
- // TODO
Review comment:
it seems that if I shutdown the RMQClient, I remain send message by
RMQClient.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services