build.gradle
// feign client
implementation group: 'org.springframework.cloud', name: 'spring-cloud-starter-openfeign', version: '3.1.1'
최상단 Application class
@EnableFeignClients
어노테이션 추가
@EnableFeignClients
public class SampleApplication {
public static void main(String[] args) {
SpringApplication.run(SampleApplication.class, args);
}
}
외부 url 관리를 yml로 설정 (optional)
# Django Converter IP
feign:
secret:
converterIP : <http://www.domain.com:9000>
elasticsearchIP: <http://www.domain2.com:9200>
Client interface
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import java.util.Map;
@FeignClient(name = "elasticsearchClient", url = "${feign.secret.elasticsearchIP}")
public interface ElasticsearchClient {
/**
* 통합검색 > 논문 검색
*/
@RequestMapping(method = RequestMethod.POST, value = "/paper/_search")
Map<String, Object> searchPapers(@RequestBody Map<String, Object> body);
}
client 사용하는 class 예시
Map<String, Object> response = elasticsearchFeignClient.searchPapers(requestBody);