0

I am using Spring Boot for my API. I am rewriting my API, to adopt the microservices architecture.

I have 2 classes:

1) Product

2) Ingredient

My Code:

Here is my Product class:

    public class Product{
       private String name;
       @ElementCollection
       private List<Long> productIngredients = new ArrayList<>(); //Ingredient
       private Double quantity = 0.0;
       private Double productCost = 0.0;
}

Here is my Ingredient class:

public class Ingredient{    
     private String name;
     private String unit;
     private Double quantity = 0.0;
}

In the Product microservice, I am doing an API call to the Ingredient microservice:

// Making a call to the Ingredients microservice from the product microservice

WebClient myWebClient = WebClient.create("http://localhost:8090/api");

@GetMapping("/ingredients/get")
public Flux<Product> getIngredients(){
   
        return myWebClient
                .get()
                .uri("/ingredients/ingredient/list")
                .retrieve()
                .bodyToFlux(Product.class);
}

However, the above getIngredients() method is not working.

My Question:

I want to fetch data from the Ingredient microservice, however, I get the following error:

"error": "Internal Server Error", "trace": "org.springframework.web.reactive.function.client.WebClientRequestException: Connection refused: no further information: localhost/127.0.0.1:80; nested exception is io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection refused: no further information: localhost/127.0.0.1:80\r\n\tat org.springframework.web.reactive.function.client.ExchangeFunctions$DefaultExchangeFunction.lambda$wrapException$9(ExchangeFunctions.java:141)\r\n\tSuppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException: \nError has been observed at the following site(s):\n\t|_ checkpoint ⇢ Request to GET http://localhost/api/components/component/list [DefaultWebClient]\nStack trace:\r\n\t\tat org.springframework.web.reactive.function.client.

0

1 Answer 1

0

Connection refused: no further information: localhost/127.0.0.1:80, exception says that:

  1. there's nothing listening on port 80 on your local machine
  2. you're making a request to localhost:80 not localhost:8090, are you sure myWebClient instance is the one that is configured with the correct URL?
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.