Skip to content

Commit 48ccaab

Browse files
authored
Merge pull request #175 from eldermoraes/master
General fixes
2 parents 92f1676 + ca471ca commit 48ccaab

File tree

2 files changed

+86
-52
lines changed

2 files changed

+86
-52
lines changed

documentation/modules/ROOT/pages/08_rest-client.adoc

Lines changed: 62 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,71 @@
22

33
A typical scenario in a Microservices architecture is the remote invocation of remote REST HTTP endpoints. Quarkus provides a typed REST client that follows the https://github.com/eclipse/microprofile-rest-client[MicroProfile REST Client, window=_blank] specification.
44
5-
Let's create a REST client that accesses https://swapi.dev[window=_blank] to get additional information about Movies. The endpoint we're interested in is this one:
5+
Let's create a REST client that accesses https://swapi.info[window=_blank] to get additional information about Movies. The endpoint we're interested in is this one:
66
7-
* `api/films/?search=\{title\}`, which returns specific info about the given movie.
7+
* `api/films/\{id\}`, which returns specific info about the given movie.
88
99
[.console-output]
1010
[source, json]
1111
----
1212
{
13-
"count": 1,
14-
"next": null,
15-
"previous": null,
16-
"results": [
17-
{
18-
"title": "The Empire Strikes Back",
19-
"episode_id": 5,
20-
"opening_crawl": "It is a dark time for the\r\nRebellion. Although the Death\r\nStar has been destroyed,\r\nImperial troops have driven the\r\nRebel forces from their hidden\r\nbase and pursued them across\r\nthe galaxy.\r\n\r\nEvading the dreaded Imperial\r\nStarfleet, a group of freedom\r\nfighters led by Luke Skywalker\r\nhas established a new secret\r\nbase on the remote ice world\r\nof Hoth.\r\n\r\nThe evil lord Darth Vader,\r\nobsessed with finding young\r\nSkywalker, has dispatched\r\nthousands of remote probes into\r\nthe far reaches of space....",
21-
"director": "Irvin Kershner",
22-
"producer": "Gary Kurtz, Rick McCallum",
23-
"release_date": "1980-05-17",
24-
"created": "2014-12-12T11:26:24.656000Z",
25-
"edited": "2014-12-15T13:07:53.386000Z",
26-
"url": "https://swapi.dev/api/films/2/"
27-
}
28-
]
13+
"title": "A New Hope",
14+
"episode_id": 4,
15+
"opening_crawl": "It is a period of civil war.\r\nRebel spaceships, striking\r\nfrom a hidden base, have won\r\ntheir first victory against\r\nthe evil Galactic Empire.\r\n\r\nDuring the battle, Rebel\r\nspies managed to steal secret\r\nplans to the Empire's\r\nultimate weapon, the DEATH\r\nSTAR, an armored space\r\nstation with enough power\r\nto destroy an entire planet.\r\n\r\nPursued by the Empire's\r\nsinister agents, Princess\r\nLeia races home aboard her\r\nstarship, custodian of the\r\nstolen plans that can save her\r\npeople and restore\r\nfreedom to the galaxy....",
16+
"director": "George Lucas",
17+
"producer": "Gary Kurtz, Rick McCallum",
18+
"release_date": "1977-05-25",
19+
"characters": [
20+
"https://swapi.info/api/people/1",
21+
"https://swapi.info/api/people/2",
22+
"https://swapi.info/api/people/3",
23+
"https://swapi.info/api/people/4",
24+
"https://swapi.info/api/people/5",
25+
"https://swapi.info/api/people/6",
26+
"https://swapi.info/api/people/7",
27+
"https://swapi.info/api/people/8",
28+
"https://swapi.info/api/people/9",
29+
"https://swapi.info/api/people/10",
30+
"https://swapi.info/api/people/12",
31+
"https://swapi.info/api/people/13",
32+
"https://swapi.info/api/people/14",
33+
"https://swapi.info/api/people/15",
34+
"https://swapi.info/api/people/16",
35+
"https://swapi.info/api/people/18",
36+
"https://swapi.info/api/people/19",
37+
"https://swapi.info/api/people/81"
38+
],
39+
"planets": [
40+
"https://swapi.info/api/planets/1",
41+
"https://swapi.info/api/planets/2",
42+
"https://swapi.info/api/planets/3"
43+
],
44+
"starships": [
45+
"https://swapi.info/api/starships/2",
46+
"https://swapi.info/api/starships/3",
47+
"https://swapi.info/api/starships/5",
48+
"https://swapi.info/api/starships/9",
49+
"https://swapi.info/api/starships/10",
50+
"https://swapi.info/api/starships/11",
51+
"https://swapi.info/api/starships/12",
52+
"https://swapi.info/api/starships/13"
53+
],
54+
"vehicles": [
55+
"https://swapi.info/api/vehicles/4",
56+
"https://swapi.info/api/vehicles/6",
57+
"https://swapi.info/api/vehicles/7",
58+
"https://swapi.info/api/vehicles/8"
59+
],
60+
"species": [
61+
"https://swapi.info/api/species/1",
62+
"https://swapi.info/api/species/2",
63+
"https://swapi.info/api/species/3",
64+
"https://swapi.info/api/species/4",
65+
"https://swapi.info/api/species/5"
66+
],
67+
"created": "2014-12-10T14:23:31.880000Z",
68+
"edited": "2014-12-20T19:49:45.256000Z",
69+
"url": "https://swapi.info/api/films/1"
2970
}
3071
----
3172
@@ -363,10 +404,10 @@ curl -w '\n' localhost:8080/movie?year=1980
363404
{
364405
"title": "The Empire Strikes Back",
365406
"releaseDate": "1980-05-17",
366-
"episodeId": 0,
367-
"producer": "Gary Kurtz, Rick McCallum",
407+
"episode_id": 5,
408+
"opening_crawl": "It is a dark time for the\r\nRebellion. Although the Death\r\nStar has been destroyed,\r\nImperial troops have driven the\r\nRebel forces from their hidden\r\nbase and pursued them across\r\nthe galaxy.\r\n\r\nEvading the dreaded Imperial\r\nStarfleet, a group of freedom\r\nfighters led by Luke Skywalker\r\nhas established a new secret\r\nbase on the remote ice world\r\nof Hoth.\r\n\r\nThe evil lord Darth Vader,\r\nobsessed with finding young\r\nSkywalker, has dispatched\r\nthousands of remote probes into\r\nthe far reaches of space....",
368409
"director": "Irvin Kershner",
369-
"opening_crawl": "It is a dark time for the\r\nRebellion. Although the Death\r\nStar has been destroyed,\r\nImperial troops have driven the\r\nRebel forces from their hidden\r\nbase and pursued them across\r\nthe galaxy.\r\n\r\nEvading the dreaded Imperial\r\nStarfleet, a group of freedom\r\nfighters led by Luke Skywalker\r\nhas established a new secret\r\nbase on the remote ice world\r\nof Hoth.\r\n\r\nThe evil lord Darth Vader,\r\nobsessed with finding young\r\nSkywalker, has dispatched\r\nthousands of remote probes into\r\nthe far reaches of space...."
410+
"producer": "Gary Kurtz, Rick McCallum"
370411
}
371412
]
372413
----

documentation/modules/ROOT/pages/09_fault-tolerance.adoc

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ import jakarta.ws.rs.core.MediaType;
5454
5555
import com.redhat.developers.Swapi.Results;
5656
57-
@Path("/api")
5857
@RegisterRestClient
5958
public interface SwapiService {
6059
@GET
@@ -115,35 +114,24 @@ Change the `SwapiService` Java interface in `src/main/java` in the `com.redhat.d
115114
----
116115
package com.redhat.developers;
117116
118-
import java.util.List;
119-
120-
import org.eclipse.microprofile.faulttolerance.ExecutionContext;
121-
import org.eclipse.microprofile.faulttolerance.Fallback;
122-
import org.eclipse.microprofile.faulttolerance.FallbackHandler;
123-
import org.eclipse.microprofile.faulttolerance.Retry;
117+
import jakarta.ws.rs.*;
118+
import org.eclipse.microprofile.faulttolerance.*;
124119
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;
125-
126-
import jakarta.ws.rs.GET;
127-
import jakarta.ws.rs.Path;
128-
import jakarta.ws.rs.Produces;
129-
import jakarta.ws.rs.QueryParam;
130120
import jakarta.ws.rs.core.MediaType;
131121
132-
import com.redhat.developers.Swapi.Results;
133-
134-
@Path("/api")
135122
@RegisterRestClient
136123
public interface SwapiService {
124+
137125
@GET
138-
@Path("/films/")
126+
@Path("/films/{id}")
139127
@Produces(MediaType.APPLICATION_JSON)
140-
@Retry(maxRetries = 3, delay = 2000)
128+
@Timeout(value = 2000L)
141129
@Fallback(SwapiFallback.class)
142130
public Swapi getFilmById(@PathParam("id") String id);
143131
144132
public static class SwapiFallback implements FallbackHandler<Swapi> {
145133
146-
private static final Swapi EMPTY_SWAPI = new Swapi(List.of(new Results(0,"","","")));
134+
private static final Swapi EMPTY_SWAPI = new Swapi("",0,"","","");
147135
@Override
148136
public Swapi handle(ExecutionContext context) {
149137
return EMPTY_SWAPI;
@@ -198,30 +186,35 @@ Change the `SwapiService` Java interface in `src/main/java` in the `com.redhat.d
198186
----
199187
package com.redhat.developers;
200188
201-
import org.eclipse.microprofile.faulttolerance.CircuitBreaker;
202-
import org.eclipse.microprofile.faulttolerance.Retry;
189+
import jakarta.ws.rs.*;
190+
import org.eclipse.microprofile.faulttolerance.*;
203191
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;
204-
205-
import jakarta.ws.rs.GET;
206-
import jakarta.ws.rs.Path;
207-
import jakarta.ws.rs.Produces;
208-
import jakarta.ws.rs.QueryParam;
209192
import jakarta.ws.rs.core.MediaType;
210193
211-
@Path("/api")
212194
@RegisterRestClient
213195
public interface SwapiService {
214196
@GET
215-
@Path("/films/")
197+
@Path("/films/{id}")
216198
@Produces(MediaType.APPLICATION_JSON)
217-
@Retry(maxRetries = 3, delay = 2000)
199+
@Timeout(value = 2000L)
200+
@Fallback(SwapiFallback.class)
218201
@CircuitBreaker(
219-
requestVolumeThreshold=4,
220-
failureRatio=0.75,
221-
delay=5000
202+
requestVolumeThreshold = 4,
203+
failureRatio = .5,
204+
delay = 5000L,
205+
successThreshold = 2
222206
)
223207
public Swapi getFilmById(@PathParam("id") String id);
224208
209+
public static class SwapiFallback implements FallbackHandler<Swapi> {
210+
211+
private static final Swapi EMPTY_SWAPI = new Swapi("",0,"","","");
212+
@Override
213+
public Swapi handle(ExecutionContext context) {
214+
return EMPTY_SWAPI;
215+
}
216+
217+
}
225218
}
226219
227220
----

0 commit comments

Comments
 (0)