@@ -31,6 +31,7 @@ internal class NatsJSConsume<TMsg> : NatsSubBase
3131 private readonly Timer _timer ;
3232 private readonly Task _pullTask ;
3333 private readonly NatsJSNotificationChannel ? _notificationChannel ;
34+ private readonly NatsJSConsumer ? _jsConsumer ;
3435
3536 private readonly long _maxMsgs ;
3637 private readonly TimeSpan _expires ;
@@ -61,6 +62,7 @@ public NatsJSConsume(
6162 INatsDeserialize < TMsg > serializer ,
6263 NatsSubOpts ? opts ,
6364 NatsJSPriorityGroupOpts ? priorityGroup ,
65+ NatsJSConsumer ? jsConsumer ,
6466 CancellationToken cancellationToken )
6567 : base ( context . Connection , context . Connection . SubscriptionManager , subject , queueGroup , opts )
6668 {
@@ -72,6 +74,7 @@ public NatsJSConsume(
7274 _consumer = consumer ;
7375 _serializer = serializer ;
7476 _priorityGroup = priorityGroup ;
77+ _jsConsumer = jsConsumer ;
7578
7679 if ( notificationHandler is { } handler )
7780 {
@@ -245,6 +248,8 @@ internal override async ValueTask WriteReconnectCommandsAsync(CommandWriter comm
245248 Group = _priorityGroup ? . Group ,
246249 MinPending = _priorityGroup ? . MinPending ?? 0 ,
247250 MinAckPending = _priorityGroup ? . MinAckPending ?? 0 ,
251+ Priority = _priorityGroup ? . Priority ?? 0 ,
252+ Id = _jsConsumer ? . GetPinId ( ) ,
248253 } ;
249254
250255 await commandWriter . PublishAsync (
@@ -354,6 +359,12 @@ protected override async ValueTask ReceiveInternalAsync(
354359 _notificationChannel ? . Notify ( NatsJSLeadershipChangeNotification . Default ) ;
355360 ResetPending ( ) ;
356361 }
362+ else if ( headers . Code == 423 )
363+ {
364+ _logger . LogDebug ( NatsJSLogEvents . PinIdMismatch , "Pin ID Mismatch" ) ;
365+ NatsJSExtensionsInternal . HandlePinIdMismatch ( _jsConsumer , _notificationChannel ) ;
366+ ResetPending ( ) ;
367+ }
357368 else if ( headers . Code == 503 )
358369 {
359370 _logger . LogDebug ( NatsJSLogEvents . NoResponders , "503 no responders" ) ;
@@ -400,6 +411,8 @@ protected override async ValueTask ReceiveInternalAsync(
400411 _serializer ) ,
401412 _context ) ;
402413
414+ NatsJSExtensionsInternal . TrySetPinIdFromHeaders ( msg . Headers , _jsConsumer ) ;
415+
403416 // Stop feeding the user if we are disposed.
404417 // We need to exit as soon as possible.
405418 if ( Volatile . Read ( ref _disposed ) == 0 )
@@ -479,6 +492,8 @@ private void Pull(string origin, long batch, long maxBytes) => _pullRequests.Wri
479492 Group = _priorityGroup ? . Group ,
480493 MinPending = _priorityGroup ? . MinPending ?? 0 ,
481494 MinAckPending = _priorityGroup ? . MinAckPending ?? 0 ,
495+ Priority = _priorityGroup ? . Priority ?? 0 ,
496+ Id = _jsConsumer ? . GetPinId ( ) ,
482497 } ,
483498 Origin = origin ,
484499 } ) ;
0 commit comments