@@ -196,7 +196,7 @@ impl ErrorResponse {
196
196
}
197
197
198
198
/// Data structure representing error response params.
199
- #[ derive( Debug , Clone , PartialEq , Eq , Serialize , Deserialize ) ]
199
+ #[ derive( Debug , Clone , Hash , PartialEq , Eq , Serialize , Deserialize ) ]
200
200
pub struct ErrorData {
201
201
/// Error code.
202
202
pub code : i32 ,
@@ -215,7 +215,9 @@ pub enum SubscriptionError {
215
215
SubscriberLimitExceeded ,
216
216
}
217
217
218
- /// Data structure representing subscribe request params.
218
+ /// Subscription request parameters. This request does not require the
219
+ /// subscription to be fully processed, and returns as soon as the server
220
+ /// receives it.
219
221
#[ derive( Debug , Clone , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
220
222
pub struct Subscribe {
221
223
/// The topic to subscribe to.
@@ -244,15 +246,36 @@ impl ServiceRequest for Subscribe {
244
246
}
245
247
}
246
248
249
+ /// Subscription request parameters. This request awaits the subscription to be
250
+ /// fully processed and returns possible errors.
251
+ #[ derive( Debug , Clone , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
252
+ pub struct SubscribeBlocking {
253
+ /// The topic to subscribe to.
254
+ pub topic : Topic ,
255
+ }
256
+
257
+ impl ServiceRequest for SubscribeBlocking {
258
+ type Error = SubscriptionError ;
259
+ type Response = SubscriptionId ;
260
+
261
+ fn validate ( & self ) -> Result < ( ) , PayloadError > {
262
+ self . topic
263
+ . decode ( )
264
+ . map_err ( |_| PayloadError :: InvalidTopic ) ?;
265
+
266
+ Ok ( ( ) )
267
+ }
268
+
269
+ fn into_params ( self ) -> Params {
270
+ Params :: SubscribeBlocking ( self )
271
+ }
272
+ }
273
+
247
274
/// Data structure representing unsubscribe request params.
248
275
#[ derive( Debug , Clone , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
249
276
pub struct Unsubscribe {
250
277
/// The topic to unsubscribe from.
251
278
pub topic : Topic ,
252
-
253
- /// The id of the subscription to unsubscribe from.
254
- #[ serde( rename = "id" ) ]
255
- pub subscription_id : SubscriptionId ,
256
279
}
257
280
258
281
impl ServiceRequest for Unsubscribe {
@@ -317,7 +340,9 @@ pub struct FetchResponse {
317
340
pub has_more : bool ,
318
341
}
319
342
320
- /// Multi-topic subscription request parameters.
343
+ /// Multi-topic subscription request parameters. This request does not require
344
+ /// all subscriptions to be fully processed, and returns as soon as the server
345
+ /// receives it.
321
346
#[ derive( Debug , Clone , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
322
347
pub struct BatchSubscribe {
323
348
/// The topics to subscribe to.
@@ -329,12 +354,9 @@ pub struct BatchSubscribe {
329
354
pub block : bool ,
330
355
}
331
356
332
- impl ServiceRequest for BatchSubscribe {
333
- type Error = SubscriptionError ;
334
- type Response = Vec < SubscriptionId > ;
335
-
336
- fn validate ( & self ) -> Result < ( ) , PayloadError > {
337
- let batch_size = self . topics . len ( ) ;
357
+ impl BatchSubscribe {
358
+ fn validate_topics ( topics : & [ Topic ] ) -> Result < ( ) , PayloadError > {
359
+ let batch_size = topics. len ( ) ;
338
360
339
361
if batch_size == 0 {
340
362
return Err ( PayloadError :: BatchEmpty ) ;
@@ -344,18 +366,55 @@ impl ServiceRequest for BatchSubscribe {
344
366
return Err ( PayloadError :: BatchLimitExceeded ) ;
345
367
}
346
368
347
- for topic in & self . topics {
369
+ for topic in topics {
348
370
topic. decode ( ) . map_err ( |_| PayloadError :: InvalidTopic ) ?;
349
371
}
350
372
351
373
Ok ( ( ) )
352
374
}
375
+ }
376
+
377
+ impl ServiceRequest for BatchSubscribe {
378
+ type Error = SubscriptionError ;
379
+ type Response = Vec < SubscriptionId > ;
380
+
381
+ fn validate ( & self ) -> Result < ( ) , PayloadError > {
382
+ Self :: validate_topics ( & self . topics )
383
+ }
353
384
354
385
fn into_params ( self ) -> Params {
355
386
Params :: BatchSubscribe ( self )
356
387
}
357
388
}
358
389
390
+ /// Multi-topic subscription request parameters. This request awaits all
391
+ /// subscriptions to be fully processed and returns possible errors per topic.
392
+ #[ derive( Debug , Clone , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
393
+ pub struct BatchSubscribeBlocking {
394
+ /// The topics to subscribe to.
395
+ pub topics : Vec < Topic > ,
396
+ }
397
+
398
+ #[ derive( Debug , Clone , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
399
+ #[ serde( rename_all = "camelCase" ) ]
400
+ pub enum SubscriptionResult {
401
+ Id ( SubscriptionId ) ,
402
+ Error ( ErrorData ) ,
403
+ }
404
+
405
+ impl ServiceRequest for BatchSubscribeBlocking {
406
+ type Error = SubscriptionError ;
407
+ type Response = Vec < SubscriptionResult > ;
408
+
409
+ fn validate ( & self ) -> Result < ( ) , PayloadError > {
410
+ BatchSubscribe :: validate_topics ( & self . topics )
411
+ }
412
+
413
+ fn into_params ( self ) -> Params {
414
+ Params :: BatchSubscribeBlocking ( self )
415
+ }
416
+ }
417
+
359
418
/// Multi-topic unsubscription request parameters.
360
419
#[ derive( Debug , Clone , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
361
420
pub struct BatchUnsubscribe {
@@ -696,6 +755,10 @@ pub enum Params {
696
755
#[ serde( rename = "irn_subscribe" , alias = "iridium_subscribe" ) ]
697
756
Subscribe ( Subscribe ) ,
698
757
758
+ /// Parameters to blocking subscribe.
759
+ #[ serde( rename = "irn_subscribeBlocking" , alias = "iridium_subscribeBlocking" ) ]
760
+ SubscribeBlocking ( SubscribeBlocking ) ,
761
+
699
762
/// Parameters to unsubscribe.
700
763
#[ serde( rename = "irn_unsubscribe" , alias = "iridium_unsubscribe" ) ]
701
764
Unsubscribe ( Unsubscribe ) ,
@@ -708,6 +771,13 @@ pub enum Params {
708
771
#[ serde( rename = "irn_batchSubscribe" , alias = "iridium_batchSubscribe" ) ]
709
772
BatchSubscribe ( BatchSubscribe ) ,
710
773
774
+ /// Parameters to blocking batch subscribe.
775
+ #[ serde(
776
+ rename = "irn_batchSubscribeBlocking" ,
777
+ alias = "iridium_batchSubscribeBlocking"
778
+ ) ]
779
+ BatchSubscribeBlocking ( BatchSubscribeBlocking ) ,
780
+
711
781
/// Parameters to batch unsubscribe.
712
782
#[ serde( rename = "irn_batchUnsubscribe" , alias = "iridium_batchUnsubscribe" ) ]
713
783
BatchUnsubscribe ( BatchUnsubscribe ) ,
@@ -779,9 +849,11 @@ impl Request {
779
849
780
850
match & self . params {
781
851
Params :: Subscribe ( params) => params. validate ( ) ,
852
+ Params :: SubscribeBlocking ( params) => params. validate ( ) ,
782
853
Params :: Unsubscribe ( params) => params. validate ( ) ,
783
854
Params :: FetchMessages ( params) => params. validate ( ) ,
784
855
Params :: BatchSubscribe ( params) => params. validate ( ) ,
856
+ Params :: BatchSubscribeBlocking ( params) => params. validate ( ) ,
785
857
Params :: BatchUnsubscribe ( params) => params. validate ( ) ,
786
858
Params :: BatchFetchMessages ( params) => params. validate ( ) ,
787
859
Params :: Publish ( params) => params. validate ( ) ,
0 commit comments