In this article I'm planing to explain the way we can implement Feign Client to invoke inter service call.
We have eurekaServer, zuulServer, clientServer, serverServer. Initially, we need to register our all servers with the eurekaServer.
1st of all, we need to add dependency to the application. In this example I'm going to use maven dependency as below.
According to the above end-point, we need to implement the feign-client as below
And also fall-back class below (when calling the service, if something happen, you can handle the situation here).
CustomResponseMessage -> response payload.
BankDTO -> request body
Hope this will helpful.
We have eurekaServer, zuulServer, clientServer, serverServer. Initially, we need to register our all servers with the eurekaServer.
twoService has a end-point as below:zuulServer register as proxyServiceclientServer register as oneServiceserverServer register as twoService
http method: POST url: /api/person/{personId}/bank
1st of all, we need to add dependency to the application. In this example I'm going to use maven dependency as below.
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-feign</artifactId> <version>#{feign.version}</version> </dependency>
According to the above end-point, we need to implement the feign-client as below
@FeignClient(name = "twoservice", path = "/api", fallback = TwoServiceFallBack.class, configuration = DefaultFeignConfig.class) public interface TwoServiceClient { @RequestMapping(path = "/person/{personId}/bank", method = RequestMethod.POST) CustomResponseMessage addBankInfo(@PathVariable("personId") String personId, @RequestBody BankDTO bankDTO); }
And also fall-back class below (when calling the service, if something happen, you can handle the situation here).
@Component public class TwoServiceClientFallBack implements TwoServiceClient { @Override public CustomResponseMessage addBankInfo(String personId, BankDTO bankDTO) { // return null; } }
CustomResponseMessage -> response payload.
BankDTO -> request body
Hope this will helpful.
No comments:
Post a Comment