@@ -50,8 +50,6 @@ type Subscription struct {
5050
5151 mu sync.Mutex
5252 receiveActive bool
53-
54- enableOrdering bool
5553}
5654
5755// Subscription creates a reference to a subscription.
@@ -1238,8 +1236,6 @@ func (s *Subscription) Receive(ctx context.Context, f func(context.Context, *Mes
12381236 s .mu .Unlock ()
12391237 defer func () { s .mu .Lock (); s .receiveActive = false ; s .mu .Unlock () }()
12401238
1241- s .checkOrdering (ctx )
1242-
12431239 // TODO(hongalex): move settings check to a helper function to make it more testable
12441240 maxCount := s .ReceiveSettings .MaxOutstandingMessages
12451241 if maxCount == 0 {
@@ -1392,11 +1388,14 @@ func (s *Subscription) Receive(ctx context.Context, f func(context.Context, *Mes
13921388 iter .eoMu .RUnlock ()
13931389
13941390 wg .Add (1 )
1395- // Make sure the subscription has ordering enabled before adding to scheduler.
1391+ // Only schedule messages in order if an ordering key is present and the subscriber client
1392+ // received the ordering flag from a Streaming Pull response.
13961393 var key string
1397- if s .enableOrdering {
1394+ iter .orderingMu .RLock ()
1395+ if iter .enableOrdering {
13981396 key = msg .OrderingKey
13991397 }
1398+ iter .orderingMu .RUnlock ()
14001399 msgLen := len (msg .Data )
14011400 if err := sched .Add (key , msg , func (msg interface {}) {
14021401 defer wg .Done ()
@@ -1436,20 +1435,6 @@ func (s *Subscription) Receive(ctx context.Context, f func(context.Context, *Mes
14361435 return group .Wait ()
14371436}
14381437
1439- // checkOrdering calls Config to check theEnableMessageOrdering field.
1440- // If this call fails (e.g. because the service account doesn't have
1441- // the roles/viewer or roles/pubsub.viewer role) we will assume
1442- // EnableMessageOrdering to be true.
1443- // See: https://github.com/googleapis/google-cloud-go/issues/3884
1444- func (s * Subscription ) checkOrdering (ctx context.Context ) {
1445- cfg , err := s .Config (ctx )
1446- if err != nil {
1447- s .enableOrdering = true
1448- } else {
1449- s .enableOrdering = cfg .EnableMessageOrdering
1450- }
1451- }
1452-
14531438type pullOptions struct {
14541439 maxExtension time.Duration // the maximum time to extend a message's ack deadline in total
14551440 maxExtensionPeriod time.Duration // the maximum time to extend a message's ack deadline per modack rpc
0 commit comments