@@ -1474,12 +1474,13 @@ public Boolean SendMessageBack(MessageExt msg, Int32 delayLevel = 0, Int32 maxRe
14741474 #region Pop消费模式
14751475 /// <summary>Pop方式拉取消息。5.0新增的轻量消费模式,无需客户端Rebalance</summary>
14761476 /// <param name="brokerName">Broker名称</param>
1477+ /// <param name="queueId">队列编号。-1表示由Broker自动分配</param>
14771478 /// <param name="maxNums">最大拉取数</param>
14781479 /// <param name="invisibleTime">不可见时间(毫秒),消息被拉取后在此时间内不会被其他消费者看到</param>
14791480 /// <param name="pollTime">长轮询等待时间(毫秒)</param>
14801481 /// <param name="cancellationToken">取消通知</param>
14811482 /// <returns>拉取结果</returns>
1482- public async Task < PullResult > PopMessageAsync ( String brokerName , Int32 maxNums = 32 , Int64 invisibleTime = 60_000 , Int32 pollTime = 15_000 , CancellationToken cancellationToken = default )
1483+ public async Task < PullResult > PopMessageAsync ( String brokerName , Int32 queueId = - 1 , Int32 maxNums = 32 , Int64 invisibleTime = 60_000 , Int32 pollTime = 15_000 , CancellationToken cancellationToken = default )
14831484 {
14841485 if ( String . IsNullOrEmpty ( brokerName ) ) throw new ArgumentNullException ( nameof ( brokerName ) ) ;
14851486
@@ -1493,6 +1494,7 @@ public async Task<PullResult> PopMessageAsync(String brokerName, Int32 maxNums =
14931494 {
14941495 consumerGroup = Group ,
14951496 topic = Topic ,
1497+ queueId ,
14961498 maxMsgNums = maxNums ,
14971499 invisibleTime ,
14981500 pollTime ,
@@ -1528,11 +1530,12 @@ public async Task<PullResult> PopMessageAsync(String brokerName, Int32 maxNums =
15281530
15291531 /// <summary>确认Pop消息消费完成</summary>
15301532 /// <param name="brokerName">Broker名称</param>
1531- /// <param name="extraInfo">消息额外信息,Pop拉取时返回</param>
1532- /// <param name="offset">消息偏移</param>
1533+ /// <param name="extraInfo">Pop检查点信息,即消息属性中的POP_CK字段值</param>
1534+ /// <param name="offset">消息在Queue中的偏移量</param>
1535+ /// <param name="queueId">队列编号</param>
15331536 /// <param name="cancellationToken">取消通知</param>
15341537 /// <returns></returns>
1535- public async Task < Boolean > AckMessageAsync ( String brokerName , String extraInfo , Int64 offset , CancellationToken cancellationToken = default )
1538+ public async Task < Boolean > AckMessageAsync ( String brokerName , String extraInfo , Int64 offset , Int32 queueId = - 1 , CancellationToken cancellationToken = default )
15361539 {
15371540 using var span = Tracer ? . NewSpan ( $ "mq:{ Name } :AckMessage", offset ) ;
15381541 try
@@ -1546,6 +1549,7 @@ public async Task<Boolean> AckMessageAsync(String brokerName, String extraInfo,
15461549 topic = Topic ,
15471550 extraInfo ,
15481551 offset ,
1552+ queueId ,
15491553 } ;
15501554
15511555 await bk . InvokeAsync ( RequestCode . ACK_MESSAGE , null , header , true , cancellationToken ) . ConfigureAwait ( false ) ;
@@ -1559,14 +1563,28 @@ public async Task<Boolean> AckMessageAsync(String brokerName, String extraInfo,
15591563 }
15601564 }
15611565
1566+ /// <summary>确认Pop消息消费完成。自动从消息属性中提取Pop检查点信息(POP_CK)</summary>
1567+ /// <param name="brokerName">Broker名称</param>
1568+ /// <param name="msg">通过Pop方式拉取的消息</param>
1569+ /// <param name="cancellationToken">取消通知</param>
1570+ /// <returns></returns>
1571+ public Task < Boolean > AckMessageAsync ( String brokerName , MessageExt msg , CancellationToken cancellationToken = default )
1572+ {
1573+ if ( msg == null ) throw new ArgumentNullException ( nameof ( msg ) ) ;
1574+ if ( String . IsNullOrEmpty ( msg . PopCheckPoint ) ) throw new ArgumentException ( "消息不含Pop检查点信息(POP_CK属性缺失),请确认该消息是通过Pop方式拉取的。" , nameof ( msg ) ) ;
1575+
1576+ return AckMessageAsync ( brokerName , msg . PopCheckPoint , msg . QueueOffset , msg . QueueId , cancellationToken ) ;
1577+ }
1578+
15621579 /// <summary>修改Pop消息不可见时间,延长消费处理窗口</summary>
15631580 /// <param name="brokerName">Broker名称</param>
1564- /// <param name="extraInfo">消息额外信息 </param>
1565- /// <param name="offset">消息偏移 </param>
1581+ /// <param name="extraInfo">Pop检查点信息,即消息属性中的POP_CK字段值 </param>
1582+ /// <param name="offset">消息在Queue中的偏移量 </param>
15661583 /// <param name="invisibleTime">新的不可见时间(毫秒)</param>
1584+ /// <param name="queueId">队列编号</param>
15671585 /// <param name="cancellationToken">取消通知</param>
15681586 /// <returns></returns>
1569- public async Task < Boolean > ChangeInvisibleTimeAsync ( String brokerName , String extraInfo , Int64 offset , Int64 invisibleTime , CancellationToken cancellationToken = default )
1587+ public async Task < Boolean > ChangeInvisibleTimeAsync ( String brokerName , String extraInfo , Int64 offset , Int64 invisibleTime , Int32 queueId = - 1 , CancellationToken cancellationToken = default )
15701588 {
15711589 using var span = Tracer ? . NewSpan ( $ "mq:{ Name } :ChangeInvisibleTime", offset ) ;
15721590 try
@@ -1581,6 +1599,7 @@ public async Task<Boolean> ChangeInvisibleTimeAsync(String brokerName, String ex
15811599 extraInfo ,
15821600 offset ,
15831601 invisibleTime ,
1602+ queueId ,
15841603 } ;
15851604
15861605 await bk . InvokeAsync ( RequestCode . CHANGE_MESSAGE_INVISIBLETIME , null , header , true , cancellationToken ) . ConfigureAwait ( false ) ;
@@ -1594,6 +1613,20 @@ public async Task<Boolean> ChangeInvisibleTimeAsync(String brokerName, String ex
15941613 }
15951614 }
15961615
1616+ /// <summary>修改Pop消息不可见时间,延长消费处理窗口。自动从消息属性中提取Pop检查点信息(POP_CK)</summary>
1617+ /// <param name="brokerName">Broker名称</param>
1618+ /// <param name="msg">通过Pop方式拉取的消息</param>
1619+ /// <param name="invisibleTime">新的不可见时间(毫秒)</param>
1620+ /// <param name="cancellationToken">取消通知</param>
1621+ /// <returns></returns>
1622+ public Task < Boolean > ChangeInvisibleTimeAsync ( String brokerName , MessageExt msg , Int64 invisibleTime , CancellationToken cancellationToken = default )
1623+ {
1624+ if ( msg == null ) throw new ArgumentNullException ( nameof ( msg ) ) ;
1625+ if ( String . IsNullOrEmpty ( msg . PopCheckPoint ) ) throw new ArgumentException ( "消息不含Pop检查点信息(POP_CK属性缺失),请确认该消息是通过Pop方式拉取的。" , nameof ( msg ) ) ;
1626+
1627+ return ChangeInvisibleTimeAsync ( brokerName , msg . PopCheckPoint , msg . QueueOffset , invisibleTime , msg . QueueId , cancellationToken ) ;
1628+ }
1629+
15971630 /// <summary>批量确认Pop消息消费完成</summary>
15981631 /// <param name="brokerName">Broker名称</param>
15991632 /// <param name="ackEntries">批量确认条目列表,每个条目包含extraInfo和offset</param>
0 commit comments