Create REST Connected Services

Slightly contrived example, we have two services, vadal-users and vadal-posts. Vadal-posts contains a list of posts for users identified by their user id. Vadal-posts makes a REST call to vadal-users to find the name of the user based on the user id. This allows Kiali to gather tracing and traffic details.

Add vadal-users and vadal-posts spring-boot java services. See source code here https://gitlab.com/lightphos/spring/vadal.

In essence vpost calls vuser (we have added two posts):

@GetMapping(value = "/posts")
    public Iterable<Post> getPosts(HttpServletRequest request) {
        log.info(LocalDateTime.now() + ", " + request.getRequestURL());
        Iterable<Post> posts = postRepo.findAll();
        posts.forEach(post -> {
            ResponseEntity<User> userResponse = restTemplate.getForEntity(userService + "/u/" + post.getUserId(), User.class);
            log.info("User returned {}", userResponse.getBody().getName());
            post.setUser(userResponse.getBody().getName());
        });

        return posts;
    }

In vadal-posts in the application.yml we define the following:

spring.application.name: Vadal Posts
freds.id: ${FREDS.ID:3}
wilmas.id: ${WILMAS.ID:4}

user.service: ${USER.SERVICE:http://localhost:7777}

As usual build the docker image using build pack.

mvn spring-boot:build-image for both.

#kiali #programming #istio #kubernetes #spring-boot

Observability With Istio, Kiali, and Grafana in Kubernetes and Spring
2.80 GEEK