@@ -4,12 +4,9 @@ use hyper::{
4
4
Request , Response , Uri ,
5
5
} ;
6
6
use std:: time:: Duration ;
7
- use tower:: { builder:: ServiceBuilder , reconnect:: Reconnect , Service , ServiceExt } ;
8
- use tower_hyper:: {
9
- client:: { Builder , Connect } ,
10
- retry:: { Body , RetryPolicy } ,
11
- util:: Connector ,
12
- } ;
7
+ use tower:: { builder:: ServiceBuilder , Service , ServiceExt } ;
8
+ use tower_hyper:: { client:: Connect , util:: Connector , Body } ;
9
+ use tower_reconnect:: Reconnect ;
13
10
14
11
fn main ( ) {
15
12
let fut = futures:: lazy ( || {
@@ -22,29 +19,24 @@ fn main() {
22
19
23
20
fn request ( ) -> impl Future < Item = Response < hyper:: Body > , Error = ( ) > {
24
21
let connector = Connector :: new ( HttpConnector :: new ( 1 ) ) ;
25
- let hyper = Connect :: new ( connector, Builder :: new ( ) ) ;
22
+ let hyper = Connect :: new ( connector) ;
26
23
27
- // RetryPolicy is a very simple policy that retries `n` times
28
- // if the response has a 500 status code. Here, `n` is 5.
29
- let policy = RetryPolicy :: new ( 5 ) ;
30
24
// We're calling the tower/examples/server.rs.
31
25
let dst = Destination :: try_from_uri ( Uri :: from_static ( "http://127.0.0.1:3000" ) ) . unwrap ( ) ;
32
26
33
27
// Now, to build the service! We use two BufferLayers in order to:
34
28
// - provide backpressure for the RateLimitLayer, and ConcurrencyLimitLayer
35
- // - meet `RetryLayer`'s requirement that our service implement `Service + Clone`
36
29
// - ..and to provide cheap clones on the service.
37
- let maker = ServiceBuilder :: new ( )
30
+ let service = ServiceBuilder :: new ( )
38
31
. buffer ( 5 )
39
32
. rate_limit ( 5 , Duration :: from_secs ( 1 ) )
40
33
. concurrency_limit ( 5 )
41
- . retry ( policy)
42
34
. buffer ( 5 )
43
- . make_service ( hyper) ;
35
+ . service ( hyper) ;
44
36
45
- // `Reconnect` accepts a destination and a MakeService , creating a new service
37
+ // `Reconnect` accepts a destination and a Service , creating a new service
46
38
// any time the connection encounters an error.
47
- let client = Reconnect :: new ( maker , dst) ;
39
+ let client = Reconnect :: new ( service , dst) ;
48
40
49
41
let request = Request :: builder ( )
50
42
. method ( "GET" )
@@ -55,9 +47,5 @@ fn request() -> impl Future<Item = Response<hyper::Body>, Error = ()> {
55
47
client
56
48
. ready ( )
57
49
. map_err ( |e| panic ! ( "Service is not ready: {:?}" , e) )
58
- . and_then ( |mut c| {
59
- c. call ( request)
60
- . map ( |res| res. map ( |b| b. into_inner ( ) ) )
61
- . map_err ( |e| panic ! ( "{:?}" , e) )
62
- } )
50
+ . and_then ( |mut c| c. call ( request) . map_err ( |e| panic ! ( "{:?}" , e) ) )
63
51
}
0 commit comments