Exercise 3 - Deploy Service to OpenShift
Step 1: Change the Endpoint URL
cd ~/cloud-native-starter/reactive/rest-json-quickstart/src/main/java/org/acme/rest/json/
rm ArticlesDataAccess.java
touch ArticlesDataAccess.java
nano ArticlesDataAccess.javapackage org.acme.rest.json;
import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.eclipse.microprofile.rest.client.RestClientBuilder;
import javax.annotation.PostConstruct;
import javax.enterprise.context.ApplicationScoped;
import javax.ws.rs.core.UriBuilder;
import java.net.URI;
import java.util.List;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.TimeUnit;
@ApplicationScoped
public class ArticlesDataAccess {
private static final int MAXIMAL_DURATION = 5000;
// this configuration needs to be used when running the code in OpenShift
private static String urlArticlesServiceLocal = "http://articles-reactive:8080/v2/articles?amount=10";
private ArticlesService articlesService;
@PostConstruct
void initialize() {
URI apiUrl = UriBuilder.fromUri(urlArticlesServiceLocal).build();
articlesService = RestClientBuilder.newBuilder()
.baseUri(apiUrl)
.register(ExceptionMapperArticles.class)
.build(ArticlesService.class);
}
public CompletionStage<List<Article>> getArticlesReactive(int amount) {
return articlesService.getArticlesFromService(amount);
}
}Step 2: Build the Image



Step 3: Deploy and test the Image






Last updated
Was this helpful?