0

l am trying to set an API Gateway for Microservices by using zuul api,eureka server, docker and docker compose.

l have a client like that.

@SpringBootApplication
@EnableFeignClients("com.microService.movieServerClient")
@EnableDiscoveryClient
public class MovieServerClientApplication {

    public static void main(String[] args) {
        SpringApplication.run(MovieServerClientApplication.class, args);
    }

}
package com.microService.movieServerClient;

import org.springframework.cloud.netflix.ribbon.RibbonClient;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import com.microService.movieServerClient.models.Movie;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@FeignClient(name="zuul-api-gateway")
@RibbonClient(name="movie-server")
public interface MovieServerClientProxy {

    @GetMapping("/list")
    List<Movie> getAllMovies();
}

This is movie controller.

@RestController
public class MovieController {

  //  @Autowired
   // private DiscoveryClient discoveryClient;
    
    @Autowired
    private MovieServerClientProxy movieServerClientProxy;

    @GetMapping("/")
    public String handleRequest(Model model) {

        List<Movie> result = movieServerClientProxy.getAllMovies();
        model.addAttribute("result", result);

        return "movie";
    }

}

and application.yml like that

server:
  port: 9000
spring:
  application:
    name: client-server
eureka:
  client:
    serviceUrl:
      defaultZone: http://registiration-server:8761/eureka
  instance:
    prefer-ip-address: true

client-server:
  ribbon:
    listOfServers: client-server:9000,movie-server:8081

I want to request movie-server application but taking error like that. I don't know why. Can you help me find that reasons of these exception.

zuul-api-gateway_1      | 2021-01-29 12:14:37.673  INFO 1 --- [nio-8762-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring FrameworkServlet 'dispatcherServlet'
zuul-api-gateway_1      | 2021-01-29 12:14:37.674  INFO 1 --- [nio-8762-exec-1] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization started
zuul-api-gateway_1      | 2021-01-29 12:14:37.732  INFO 1 --- [nio-8762-exec-1] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization completed in 57 ms
zuul-api-gateway_1      | 2021-01-29 12:14:37.832  INFO 1 --- [nio-8762-exec-1] o.s.c.n.zuul.web.ZuulHandlerMapping      : Mapped URL path [/movie-server/**] onto handler of type [class org.springframework.cloud.netflix.zuul.web.ZuulController]
zuul-api-gateway_1      | 2021-01-29 12:14:37.832  INFO 1 --- [nio-8762-exec-1] o.s.c.n.zuul.web.ZuulHandlerMapping      : Mapped URL path [/client-server/**] onto handler of type [class org.springframework.cloud.netflix.zuul.web.ZuulController]
client-server_1         | 2021-01-29 12:14:38.062 ERROR 1 --- [nio-9000-exec-4] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is feign.FeignException: status 404 reading MovieServerClientProxy#getAllMovies(); content:
client-server_1         | {"timestamp":"2021-01-29T12:14:37.927+0000","status":404,"error":"Not Found","message":"No message available","path":"/list"}] with root cause
client-server_1         | 
client-server_1         | feign.FeignException: status 404 reading MovieServerClientProxy#getAllMovies(); content:
client-server_1         | {"timestamp":"2021-01-29T12:14:37.927+0000","status":404,"error":"Not Found","message":"No message available","path":"/list"}
client-server_1         |       at feign.FeignException.errorStatus(FeignException.java:60) ~[feign-core-9.7.0.jar!/:na]
client-server_1         |       at feign.codec.ErrorDecoder$Default.decode(ErrorDecoder.java:89) ~[feign-core-9.7.0.jar!/:na]
client-server_1         |       at feign.SynchronousMethodHandler.executeAndDecode(SynchronousMethodHandler.java:143) ~[feign-core-9.7.0.jar!/:na]

movie-server is like below.

@RestController
@SpringBootApplication
public class MovieController {

    @GetMapping("/list")
    public List<Movie> getAllMovies() {

        List<Movie> movies = new ArrayList<>();

        movies.add(new Movie("Kelebek Etkisi", "2004", "7,7"));
        movies.add(new Movie("Zamanın Ötesinde", "2014", "7,5"));

        return movies;
    }
}

application.properties

server.port=8081
spring.application.name=movie-server
eureka.client.service-url.defaultZone=http://registiration-server:8761/eureka

enter image description here

enter image description here

theBittor
  • 786
  • 1
  • 11
  • 20
almtl
  • 95
  • 5
  • Just double check context-path of application having MovieController end point. – charybr Jan 29 '21 at 17:38
  • Do you mean this part ? I think that part getting trouble to me . movieServerClients MovieController is called well. Problem is calling with ribbon. client-server: ribbon: listOfServers: client-server:9000,movie-server:8081 – almtl Jan 29 '21 at 18:02

1 Answers1

0

l find my solution in my proxy interface and application.yml. l did use @GetMapping("movie-server/list") instead of @GetMapping("/list").

@FeignClient(name="zuul-api-gateway")
@RibbonClient(name="movie-server")
public interface MovieServerClientProxy {

    @GetMapping("movie-server/list")
    List<Movie> getAllMovies();
}

and application.yml must be like below.

server:
  port: 9000
spring:
  application:
    name: client-server
eureka:
  client:
    serviceUrl:
      defaultZone: http://registiration-server:8761/eureka
  instance:
    prefer-ip-address: true

movie-server:
      ribbon:
        listOfServers: http://movie-server:8081
almtl
  • 95
  • 5