@@ -3,6 +3,7 @@ use std::sync::Arc;
3
3
use thiserror:: Error ;
4
4
5
5
use crate :: {
6
+ backoff:: BackoffConfig ,
6
7
build_info:: DEFAULT_CLIENT_ID ,
7
8
client:: partition:: PartitionClient ,
8
9
connection:: { BrokerConnector , MetadataLookupMode , TlsConfig } ,
@@ -43,6 +44,7 @@ pub struct ClientBuilder {
43
44
max_message_size : usize ,
44
45
socks5_proxy : Option < String > ,
45
46
tls_config : TlsConfig ,
47
+ backoff_config : Arc < BackoffConfig > ,
46
48
}
47
49
48
50
impl ClientBuilder {
@@ -54,6 +56,7 @@ impl ClientBuilder {
54
56
max_message_size : 100 * 1024 * 1024 , // 100MB
55
57
socks5_proxy : None ,
56
58
tls_config : TlsConfig :: default ( ) ,
59
+ backoff_config : Default :: default ( ) ,
57
60
}
58
61
}
59
62
@@ -73,6 +76,12 @@ impl ClientBuilder {
73
76
self
74
77
}
75
78
79
+ /// Set up backoff configuration
80
+ pub fn backoff_config ( mut self , backoff_config : BackoffConfig ) -> Self {
81
+ self . backoff_config = Arc :: from ( backoff_config) ;
82
+ self
83
+ }
84
+
76
85
/// Use SOCKS5 proxy.
77
86
#[ cfg( feature = "transport-socks5" ) ]
78
87
pub fn socks5_proxy ( mut self , proxy : String ) -> Self {
@@ -96,10 +105,14 @@ impl ClientBuilder {
96
105
self . tls_config ,
97
106
self . socks5_proxy ,
98
107
self . max_message_size ,
108
+ Arc :: clone ( & self . backoff_config ) ,
99
109
) ) ;
100
110
brokers. refresh_metadata ( ) . await ?;
101
111
102
- Ok ( Client { brokers } )
112
+ Ok ( Client {
113
+ brokers,
114
+ backoff_config : self . backoff_config ,
115
+ } )
103
116
}
104
117
}
105
118
@@ -118,12 +131,16 @@ impl std::fmt::Debug for ClientBuilder {
118
131
#[ derive( Debug ) ]
119
132
pub struct Client {
120
133
brokers : Arc < BrokerConnector > ,
134
+ backoff_config : Arc < BackoffConfig > ,
121
135
}
122
136
123
137
impl Client {
124
138
/// Returns a client for performing certain cluster-wide operations.
125
139
pub fn controller_client ( & self ) -> Result < ControllerClient > {
126
- Ok ( ControllerClient :: new ( Arc :: clone ( & self . brokers ) ) )
140
+ Ok ( ControllerClient :: new (
141
+ Arc :: clone ( & self . brokers ) ,
142
+ Arc :: clone ( & self . backoff_config ) ,
143
+ ) )
127
144
}
128
145
129
146
/// Returns a client for performing operations on a specific partition
@@ -138,6 +155,7 @@ impl Client {
138
155
partition,
139
156
Arc :: clone ( & self . brokers ) ,
140
157
unknown_topic_handling,
158
+ Arc :: clone ( & self . backoff_config ) ,
141
159
)
142
160
. await
143
161
}
0 commit comments