@@ -196,7 +196,7 @@ impl ErrorResponse {
196196}
197197
198198/// Data structure representing error response params.
199- #[ derive( Debug , Clone , PartialEq , Eq , Serialize , Deserialize ) ]
199+ #[ derive( Debug , Clone , Hash , PartialEq , Eq , Serialize , Deserialize ) ]
200200pub struct ErrorData {
201201 /// Error code.
202202 pub code : i32 ,
@@ -215,7 +215,9 @@ pub enum SubscriptionError {
215215 SubscriberLimitExceeded ,
216216}
217217
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.
219221#[ derive( Debug , Clone , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
220222pub struct Subscribe {
221223 /// The topic to subscribe to.
@@ -244,15 +246,36 @@ impl ServiceRequest for Subscribe {
244246 }
245247}
246248
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+
247274/// Data structure representing unsubscribe request params.
248275#[ derive( Debug , Clone , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
249276pub struct Unsubscribe {
250277 /// The topic to unsubscribe from.
251278 pub topic : Topic ,
252-
253- /// The id of the subscription to unsubscribe from.
254- #[ serde( rename = "id" ) ]
255- pub subscription_id : SubscriptionId ,
256279}
257280
258281impl ServiceRequest for Unsubscribe {
@@ -317,7 +340,9 @@ pub struct FetchResponse {
317340 pub has_more : bool ,
318341}
319342
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.
321346#[ derive( Debug , Clone , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
322347pub struct BatchSubscribe {
323348 /// The topics to subscribe to.
@@ -329,12 +354,9 @@ pub struct BatchSubscribe {
329354 pub block : bool ,
330355}
331356
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 ( ) ;
338360
339361 if batch_size == 0 {
340362 return Err ( PayloadError :: BatchEmpty ) ;
@@ -344,18 +366,55 @@ impl ServiceRequest for BatchSubscribe {
344366 return Err ( PayloadError :: BatchLimitExceeded ) ;
345367 }
346368
347- for topic in & self . topics {
369+ for topic in topics {
348370 topic. decode ( ) . map_err ( |_| PayloadError :: InvalidTopic ) ?;
349371 }
350372
351373 Ok ( ( ) )
352374 }
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+ }
353384
354385 fn into_params ( self ) -> Params {
355386 Params :: BatchSubscribe ( self )
356387 }
357388}
358389
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+
359418/// Multi-topic unsubscription request parameters.
360419#[ derive( Debug , Clone , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
361420pub struct BatchUnsubscribe {
@@ -696,6 +755,10 @@ pub enum Params {
696755 #[ serde( rename = "irn_subscribe" , alias = "iridium_subscribe" ) ]
697756 Subscribe ( Subscribe ) ,
698757
758+ /// Parameters to blocking subscribe.
759+ #[ serde( rename = "irn_subscribeBlocking" , alias = "iridium_subscribeBlocking" ) ]
760+ SubscribeBlocking ( SubscribeBlocking ) ,
761+
699762 /// Parameters to unsubscribe.
700763 #[ serde( rename = "irn_unsubscribe" , alias = "iridium_unsubscribe" ) ]
701764 Unsubscribe ( Unsubscribe ) ,
@@ -708,6 +771,13 @@ pub enum Params {
708771 #[ serde( rename = "irn_batchSubscribe" , alias = "iridium_batchSubscribe" ) ]
709772 BatchSubscribe ( BatchSubscribe ) ,
710773
774+ /// Parameters to blocking batch subscribe.
775+ #[ serde(
776+ rename = "irn_batchSubscribeBlocking" ,
777+ alias = "iridium_batchSubscribeBlocking"
778+ ) ]
779+ BatchSubscribeBlocking ( BatchSubscribeBlocking ) ,
780+
711781 /// Parameters to batch unsubscribe.
712782 #[ serde( rename = "irn_batchUnsubscribe" , alias = "iridium_batchUnsubscribe" ) ]
713783 BatchUnsubscribe ( BatchUnsubscribe ) ,
@@ -779,9 +849,11 @@ impl Request {
779849
780850 match & self . params {
781851 Params :: Subscribe ( params) => params. validate ( ) ,
852+ Params :: SubscribeBlocking ( params) => params. validate ( ) ,
782853 Params :: Unsubscribe ( params) => params. validate ( ) ,
783854 Params :: FetchMessages ( params) => params. validate ( ) ,
784855 Params :: BatchSubscribe ( params) => params. validate ( ) ,
856+ Params :: BatchSubscribeBlocking ( params) => params. validate ( ) ,
785857 Params :: BatchUnsubscribe ( params) => params. validate ( ) ,
786858 Params :: BatchFetchMessages ( params) => params. validate ( ) ,
787859 Params :: Publish ( params) => params. validate ( ) ,
0 commit comments