@@ -14,24 +14,34 @@ implementation to your classpath. Then configure Feign to use the reactive stre
14
14
public interface GitHubReactor {
15
15
16
16
@RequestLine (" GET /repos/{owner}/{repo}/contributors" )
17
- Flux<Contributor > contributors (@Param (" owner" ) String owner , @Param (" repo" ) String repo );
17
+ Flux<Contributor > contributorsFlux (@Param (" owner" ) String owner , @Param (" repo" ) String repo );
18
+
19
+ @RequestLine (" GET /repos/{owner}/{repo}/contributors" )
20
+ Mono<List<Contributor > > contributorsMono (@Param (" owner" ) String owner , @Param (" repo" ) String repo );
18
21
19
22
class Contributor {
20
- String login;
21
-
22
- public Contributor (String login ) {
23
- this . login = login;
24
- }
23
+ String login;
24
+
25
+ public String getLogin () {
26
+ return login;
27
+ }
28
+
29
+ public void setLogin (String login ) {
30
+ this . login = login;
31
+ }
25
32
}
26
33
}
27
34
28
35
public class ExampleReactor {
29
36
public static void main (String args []) {
30
- GitHubReactor gitHub = ReactorFeign . builder()
37
+ GitHubReactor gitHub = ReactorFeign . builder()
38
+ .decoder(new ReactiveDecoder (new JacksonDecoder ()))
31
39
.target(GitHubReactor . class, " https://api.github.com" );
32
40
33
- List<Contributor > contributors = gitHub. contributors(" OpenFeign" , " feign" )
34
- .collect(Collectors . toList())
41
+ List<GitHubReactor . Contributor > contributorsFromFlux = gitHub. contributorsFlux(" OpenFeign" , " feign" )
42
+ .collectList()
43
+ .block();
44
+ List<GitHubReactor . Contributor > contributorsFromMono = gitHub. contributorsMono(" OpenFeign" , " feign" )
35
45
.block();
36
46
}
37
47
}
@@ -79,33 +89,5 @@ the wrapped in the appropriate reactive wrappers.
79
89
### Iterable and Collections responses
80
90
81
91
Due to the Synchronous nature of Feign requests, methods that return ` Iterable ` types must specify the collection
82
- in the ` Publisher ` . For ` Reactor ` types, this limits the use of ` Flux ` as a response type. If you
83
- want to use ` Flux ` , you will need to manually convert the ` Mono ` or ` Iterable ` response types into
84
- ` Flux ` using the ` fromIterable ` method.
85
-
92
+ in the ` Publisher ` . For ` Reactor ` types, this limits the use of ` Flux ` as a response type.
86
93
87
- ``` java
88
- public interface GitHub {
89
-
90
- @RequestLine (" GET /repos/{owner}/{repo}/contributors" )
91
- Mono<List<Contributor > > contributors (@Param (" owner" ) String owner , @Param (" repo" ) String repo );
92
-
93
- class Contributor {
94
- String login;
95
-
96
- public Contributor (String login ) {
97
- this . login = login;
98
- }
99
- }
100
- }
101
-
102
- public class ExampleApplication {
103
- public static void main (String [] args ) {
104
- GitHub gitHub = ReactorFeign . builder()
105
- .target(GitHub . class, " https://api.github.com" );
106
-
107
- Mono<List<Contributor > > contributors = gitHub. contributors(" OpenFeign" , " feign" );
108
- Flux<Contributor > contributorFlux = Flux . fromIterable(contributors. block());
109
- }
110
- }
111
- ```
0 commit comments