0% found this document useful (0 votes)
7 views1 page

Consumerapp 1

The document contains a Java Spring Boot controller class named ConsumerControllerApp that handles HTTP GET requests at the endpoint '/data'. It uses a DiscoveryClient to find instances of a service called 'PRODUCERAPP' and retrieves data from it using RestTemplate. The response from the producer service is printed to the console and returned to the client.

Uploaded by

Suresh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views1 page

Consumerapp 1

The document contains a Java Spring Boot controller class named ConsumerControllerApp that handles HTTP GET requests at the endpoint '/data'. It uses a DiscoveryClient to find instances of a service called 'PRODUCERAPP' and retrieves data from it using RestTemplate. The response from the producer service is printed to the console and returned to the client.

Uploaded by

Suresh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

package com.ict.

controller;
import java.util.List;
import java.util.ArrayList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
@RestController
public class ConsumerControllerApp { //localhost:8083/data
@Autowired
DiscoveryClient discoveryClient;

@Autowired
RestTemplate restTemplate;

@GetMapping("/data")
public String getProduct() {
List<ServiceInstance> siList = discoveryClient.getInstances("PRODUCERAPP");
ServiceInstance si = siList.get(0);
String url = si.getUri() +"/producer";

String response = restTemplate.getForObject(url, String.class);


System.out.println("using discovery client"+ response);
return response;
}

You might also like