I'm using ReactiveFeignClient from Playtika I need to use dynamic URL especially for the host part because I want to use the same interface for several services that have the same request and response formats, but different host. The URLs on each service can have different host name and prefix, but all have the same suffix. For example:
- http://localhost:3001/games/purchase
- http://localhost:3002/gadgets/phone/purchase
Actually I don't know whether it has the same behavior as non-reactive feign client. I follow the suggestion on How can I change the feign URL during the runtime?.
Here's the client interface.
@ReactiveFeignClient(
name = "dummy",
configuration = TransactionClient.Configuration.class
)
public interface TransactionClient {
// @PostMapping("/purchase") // Using @PostMapping and @RequestLine both don't work
@RequestLine("POST /purchase")
Mono<PurchaseResponseDto> doPurchase(
URI baseUrl,
@Valid @RequestBody PurchaseRequestDto requestDTO
);
@RequiredArgsConstructor
class Configuration {
@Bean
public ReactiveStatusHandler reactiveStatusHandler() {
return new CustomStatusHandler();
}
}
}
And here's the auto configuration
@Configuration
public class TransactionClientServiceAutoConfiguration {
@Bean
public Contract useFeignAnnotations() {
return new Contract.Default();
}
@Bean
@LoadBalanced
public TransactionClient botRemoteClient() {
return Feign.builder().target(Target.EmptyTarget.create(TransactionClient.class));
}
}
However, I got error indicating that no service with name dummy. It's just a dummy name indeed, because the name parameter is required for @ReactiveFeignClient annotation and I want to use the interface for multiple services.
How to make dynamic url possible for @ReactiveFeignClient
From reactive feign github I found this snippet:
You can change the url by creating a new instance of the client. Found no other way. Also, I added both @PostMapping and @RequestLine("POST") to the feign interface since I couldn't get the contracts option to work. Sharing this for posterity or until a better version comes along.