Add id attribute to ReactiveFeignClient annotation
justJavaProgrammer opened this issue · 4 comments
Add id attribute to ReactiveFeignClient annotation that will be used as ID for this feign client.
in this approach feign id and remote service name will be separated.
Example:
I need to have 2 feign clients that call one service registered in eureka.
@ReactiveFeignClient(name = "authentication-service", configuration = MyConfigFile.java)
interface UserRegistrationClient {
@PostMapping("/auth/register")
Mono<ResponseEntity<Mono<RegistrationResultDto>>> registerUser(RegistrationForm form);
}
Second reactive client:
@ReactiveFeignClient(name = "authentication-service", configuration = MyConfigFile.java)
interface MfaConfirmationLoginClient {
@PutMapping("/auth/settings/change-password")
Mono<ResponseEntity<Mono<MfaConfirmationResultDto>>> verifyMfaLogin(MfaBody mfa);
}
authentication-service used as ID for service lookup in discovery and as ID in BeanFactory and because of that I need to merge this two clients in one. So new approach will be something like:
@ReactiveFeignClient(id = "userRegistrationClient ", name = "authentication-service", configuration = MyConfigFile.java)
interface UserRegistrationClient {
Mono<ResponseEntity<Mono<RegistrationResultDto>>> registerUser(RegistrationForm form);
}
Second reactive client:
@ReactiveFeignClient(id = "mfaConfirmationLoginClient ", name = "authentication-service", configuration = MyConfigFile.java)
interface MfaConfirmationLoginClient {
Mono<ResponseEntity<Mono<MfaConfirmationResultDto>>> verifyMfaLogin(MfaBody mfa);
}
Now ID attribute used as id for the bean in BeanFactory and name used as name for the lookup in discovery.
Or implement it as mentioned here: ContextId of feign
Add id attribute to ReactiveFeignClient annotation that will be used as ID for this feign client. in this approach feign id and remote service name will be separated. Example: I need to have 2 feign clients that call one service registered in eureka.
@ReactiveFeignClient(name = "authentication-service", configuration = MyConfigFile.java) interface UserRegistrationClient { @PostMapping("/auth/register") Mono<ResponseEntity<Mono<RegistrationResultDto>>> registerUser(RegistrationForm form); }Second reactive client:
@ReactiveFeignClient(name = "authentication-service", configuration = MyConfigFile.java) interface MfaConfirmationLoginClient { @PutMapping("/auth/settings/change-password") Mono<ResponseEntity<Mono<MfaConfirmationResultDto>>> verifyMfaLogin(MfaBody mfa); }authentication-service used as ID for service lookup in discovery and as ID in BeanFactory and because of that I need to merge this two clients in one. So new approach will be something like:
@ReactiveFeignClient(id = "userRegistrationClient ", name = "authentication-service", configuration = MyConfigFile.java) interface UserRegistrationClient { Mono<ResponseEntity<Mono<RegistrationResultDto>>> registerUser(RegistrationForm form); }Second reactive client:
@ReactiveFeignClient(id = "mfaConfirmationLoginClient ", name = "authentication-service", configuration = MyConfigFile.java) interface MfaConfirmationLoginClient { Mono<ResponseEntity<Mono<MfaConfirmationResultDto>>> verifyMfaLogin(MfaBody mfa); }Now ID attribute used as id for the bean in BeanFactory and name used as name for the lookup in discovery.
Or implement it as mentioned here: ContextId of feign
how about the qualifier attr?
Qualifier does not work.
With and without qualifier I will get:
***************************
APPLICATION FAILED TO START
***************************
Description:
The bean 'authentication-service.ReactiveFeignClientSpecification' could not be registered. A bean with that name has already been defined and overriding is disabled.
Action:
Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true
Because ReactiveFeignClientsRegistrar.getName(Map) uses this code:
private String getClientName(Map<String, Object> client) {
if (client == null) {
return null;
}
String value = (String) client.get("value");
if (!StringUtils.hasText(value)) {
value = (String) client.get("name");
}
if (!StringUtils.hasText(value)) {
value = (String) client.get("serviceId");
}
if (StringUtils.hasText(value)) {
return value;
}
throw new IllegalStateException("Either 'name' or 'value' must be provided in @"
+ ReactiveFeignClient.class.getSimpleName());
}
@kptfh Sorry for long reply. It works, thanks for fix!