@@ -92,6 +92,7 @@ type InnerConsumer interface {
9292 GetModel () string
9393 GetWhere () string
9494 ResetOffset (topic string , table map [primitive.MessageQueue ]int64 )
95+ GetConsumerStatus (topic string ) * ConsumerStatus
9596}
9697
9798func DefaultClientOptions () ClientOptions {
@@ -377,6 +378,32 @@ func GetOrNewRocketMQClient(option ClientOptions, callbackCh chan interface{}) R
377378 res .Code = ResSuccess
378379 return res
379380 })
381+
382+ client .remoteClient .RegisterRequestFunc (ReqGetConsumerStatsFromClient , func (req * remote.RemotingCommand , addr net.Addr ) * remote.RemotingCommand {
383+ rlog .Info ("receive get consumer status from client request..." , map [string ]interface {}{
384+ rlog .LogKeyBroker : addr .String (),
385+ rlog .LogKeyTopic : req .ExtFields ["topic" ],
386+ rlog .LogKeyConsumerGroup : req .ExtFields ["group" ],
387+ })
388+
389+ header := new (GetConsumerStatusRequestHeader )
390+ header .Decode (req .ExtFields )
391+ res := remote .NewRemotingCommand (ResError , nil , nil )
392+
393+ consumerStatus := client .getConsumerStatus (header .topic , header .group )
394+ if consumerStatus != nil {
395+ res .Code = ResSuccess
396+ data , err := consumerStatus .Encode ()
397+ if err != nil {
398+ res .Remark = fmt .Sprintf ("Failed to encode consumer status: %s" , err .Error ())
399+ } else {
400+ res .Body = data
401+ }
402+ } else {
403+ res .Remark = "there is unexpected error when get consumer status, please check log"
404+ }
405+ return res
406+ })
380407 }
381408 return client
382409}
@@ -905,6 +932,15 @@ func (c *rmqClient) resetOffset(topic string, group string, offsetTable map[prim
905932 consumer .(InnerConsumer ).ResetOffset (topic , offsetTable )
906933}
907934
935+ func (c * rmqClient ) getConsumerStatus (topic string , group string ) * ConsumerStatus {
936+ consumer , exist := c .consumerMap .Load (group )
937+ if ! exist {
938+ rlog .Warning ("group " + group + " do not exists" , nil )
939+ return nil
940+ }
941+ return consumer .(InnerConsumer ).GetConsumerStatus (topic )
942+ }
943+
908944func (c * rmqClient ) getConsumerRunningInfo (group string , stack bool ) * ConsumerRunningInfo {
909945 consumer , exist := c .consumerMap .Load (group )
910946 if ! exist {
0 commit comments