@@ -81,13 +81,14 @@ class _PubSubImpl implements PubSub {
81
81
return _api.projects.subscriptions.modifyPushConfig (request, subscription);
82
82
}
83
83
84
- Future _publish (
85
- String topic, List < int > message, Map <String , String > attributes) {
84
+ Future _publish (String topic, List < int > message,
85
+ Map <String , String > attributes, String ? orderingKey ) {
86
86
var request = pubsub.PublishRequest ()
87
87
..messages = [
88
88
(pubsub.PubsubMessage ()
89
89
..dataAsBytes = message
90
- ..attributes = attributes.isEmpty ? null : attributes)
90
+ ..attributes = attributes.isEmpty ? null : attributes
91
+ ..orderingKey = orderingKey)
91
92
];
92
93
// TODO(sgjesse): Handle PublishResponse containing message ids.
93
94
return _api.projects.topics.publish (request, topic).then ((_) => null );
@@ -227,13 +228,18 @@ class _MessageImpl implements Message {
227
228
@override
228
229
final Map <String , String > attributes;
229
230
231
+ @override
232
+ final String ? orderingKey;
233
+
230
234
_MessageImpl .withString (
231
235
this ._stringMessage, {
232
236
Map <String , String >? attributes,
237
+ this .orderingKey,
233
238
}) : _bytesMessage = null ,
234
239
attributes = attributes ?? < String , String > {};
235
240
236
- _MessageImpl .withBytes (this ._bytesMessage, {Map <String , String >? attributes})
241
+ _MessageImpl .withBytes (this ._bytesMessage,
242
+ {Map <String , String >? attributes, this .orderingKey})
237
243
: _stringMessage = null ,
238
244
attributes = attributes ?? < String , String > {};
239
245
@@ -251,11 +257,14 @@ class _MessageImpl implements Message {
251
257
///
252
258
/// The labels map is lazily created when first accessed.
253
259
class _PullMessage implements Message {
260
+ _PullMessage (this ._message, this .orderingKey);
261
+
254
262
final pubsub.PubsubMessage _message;
255
263
List <int >? _bytes;
256
264
String ? _string;
257
265
258
- _PullMessage (this ._message);
266
+ @override
267
+ String ? orderingKey;
259
268
260
269
@override
261
270
List <int > get asBytes {
@@ -281,11 +290,15 @@ class _PullMessage implements Message {
281
290
///
282
291
/// The labels have been decoded into a Map.
283
292
class _PushMessage implements Message {
284
- final String _base64Message;
293
+ _PushMessage (this ._base64Message, this .attributes, this .orderingKey);
294
+
285
295
@override
286
296
final Map <String , String > attributes;
287
297
288
- _PushMessage (this ._base64Message, this .attributes);
298
+ @override
299
+ final String ? orderingKey;
300
+
301
+ final String _base64Message;
289
302
290
303
@override
291
304
List <int > get asBytes => base64.decode (_base64Message);
@@ -306,13 +319,15 @@ class _PullEventImpl implements PullEvent {
306
319
307
320
/// Low level response received from Pub/Sub.
308
321
final pubsub.PullResponse _response;
322
+
309
323
@override
310
324
final Message message;
311
325
312
326
_PullEventImpl (
313
327
this ._api, this ._subscriptionName, pubsub.PullResponse response)
314
328
: _response = response,
315
- message = _PullMessage (response.receivedMessages! [0 ].message! );
329
+ message = _PullMessage (response.receivedMessages! [0 ].message! ,
330
+ response.receivedMessages! [0 ].message? .orderingKey);
316
331
317
332
@override
318
333
Future acknowledge () {
@@ -346,13 +361,15 @@ class _PushEventImpl implements PushEvent {
346
361
var value = l['strValue' ] ?? l['numValue' ];
347
362
labels[key] = value.toString ();
348
363
}
364
+ var orderingKey = body['orderingKey' ] as String ? ;
349
365
var subscription = body['subscription' ] as String ;
350
366
// TODO(#1): Remove this when the push event subscription name is prefixed
351
367
// with '/subscriptions/'.
352
368
if (! subscription.startsWith (_prefix)) {
353
369
subscription = _prefix + subscription;
354
370
}
355
- return _PushEventImpl (_PushMessage (data, labels), subscription);
371
+ return _PushEventImpl (
372
+ _PushMessage (data, labels, orderingKey), subscription);
356
373
}
357
374
}
358
375
@@ -379,22 +396,26 @@ class _TopicImpl implements Topic {
379
396
380
397
@override
381
398
Future publish (Message message) {
382
- return _api._publish (_topic.name! , message.asBytes, message.attributes);
399
+ return _api._publish (
400
+ _topic.name! , message.asBytes, message.attributes, message.orderingKey);
383
401
}
384
402
385
403
@override
386
404
Future delete () => _api._deleteTopic (_topic.name! );
387
405
388
406
@override
389
- Future publishString (String message, {Map <String , String >? attributes}) {
407
+ Future publishString (String message,
408
+ {Map <String , String >? attributes, String ? orderingKey}) {
390
409
attributes ?? = < String , String > {};
391
- return _api._publish (_topic.name! , utf8.encode (message), attributes);
410
+ return _api._publish (
411
+ _topic.name! , utf8.encode (message), attributes, orderingKey);
392
412
}
393
413
394
414
@override
395
- Future publishBytes (List <int > message, {Map <String , String >? attributes}) {
415
+ Future publishBytes (List <int > message,
416
+ {Map <String , String >? attributes, String ? orderingKey}) {
396
417
attributes ?? = < String , String > {};
397
- return _api._publish (_topic.name! , message, attributes);
418
+ return _api._publish (_topic.name! , message, attributes, orderingKey );
398
419
}
399
420
}
400
421
0 commit comments