728x90
1. 어플리케이션 클래스에 등록
@EnableFeignClients
@SpringBootApplication
@ComponentScan(basePackages = "com.osm.erp"
public class OsmApplication {
public static void main(String[] args) {
SpringApplication.run(OsmApplication.class, args);
}
}
2. config.yml 에 등록
feignclient:
url:
apigw: http://dev-apigw-init.sm.com:7880
apikey:
pay: xxx-xxx-xxx
payreceive: yyy-yyy-yyy
3. FeignConfig.java
import feign.RequestInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class FeignConfig {
@Bean
public RequestInterCeptor requestInterceptor() {
return requestTemplate -> {
requestTemplate.header("Contetnt-Type", "application/json");
requestTemplate.header("Accept", "application/json");
};
}
}
4. 애플리케이션 서버 -> API Gateway
[API Gateway]
*정의: 분산 시스템 또는 마이크로서비스 아키텍처에서 클라이언트와 백엔드 서비스 간의 통신을 관리하는 엔트리 포인트입니다. 클라이언트의 요청을 받아 적절한 서비스로 라우팅하고, 응답을 클라이언트로 전달하는 주요 역할을 수행
*여러 마이크로 서비스를 단일 진입점으로 묶어 클라이언트가 각 서비스에 직접 접근할 필요가 없도록 한다.
import com.sm.erp.config.Feignconfig;
import org.json.simple.JSONObject;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequstBody;
import org.springframework.web.bind.annotation.ResponseBody;
@FeignClient(
name = "approvalClient",
url = "${feignclient.url.apiwgw},
configuration = FeignConfig.class)
public interface ApprocalClient {
@ResponseBody
@PostMapping(
value = "/gateway/approv_pay/api/recReq.dev",
headers = "s-Gateway-APIKey=${feignclient.apikey.pay}",
produces = MediaType.APPLICATION_JSON_VALUE,
consumes = MEDIAType.APPLICATION_JSON_VALUE)
String sendApprove(@RequestBody JSONObject requset);
}
728x90