explain....package com.mns.returns.wismr.configs; import feign.Retryer; import…
- User
explain....package com.mns.returns.wismr.configs;
import feign.Retryer; import feign.auth.BasicAuthRequestInterceptor; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Profile;
import java.util.concurrent.TimeUnit;
@Configuration @Profile({"int", "dr", "prod", "vnp", "stg", "qa"}) public class OrderDetailsFeignConfig {
@Value("${feign.client.config.orderdetails-omsapi-consumer.username}") String userName; @Value("${feign.client.config.orderdetails-omsapi-consumer.password}") String password; @Value("${feign.client.config.retryer.period}") String period; @Value("${feign.client.config.retryer.maxPeriod}") String maxPeriod; @Value("${feign.client.config.retryer.maxAttempts}") String maxAttempts; @Bean public BasicAuthRequestInterceptor basicAuthRequestInterceptor() { return new BasicAuthRequestInterceptor(userName, password); } @Bean public Retryer retryer() { return new Retryer.Default(Long.parseLong(period), TimeUnit.SECONDS.toMillis(Long.parseLong(maxPeriod)), Integer.parseInt(maxAttempts)); }}
- Assistant
This code is a configuration class for a Feign client called "OrderDetailsFeignConfig".
The class is annotated with "@Configuration" which indicates that it provides bean definitions for the application context.
It is also annotated with "@Profile" with multiple values, indicating that this configuration should be used in profiles that match any of the listed values ("int", "dr", "prod", "vnp", "stg", "qa").
The class has several fields annotated with "@Value" which are used to inject values from properties files. These properties represent usernames, passwords, and retryer configuration values for the Feign client.
The class has two bean methods:
- "basicAuthRequestInterceptor()": This method creates and returns a new instance of the "BasicAuthRequestInterceptor" class, which is responsible for adding basic authentication headers to the Feign client requests. It uses the injected username and password values.
- "retryer()": This method creates and returns a new instance of the "Retryer.Default" class, which is responsible for handling retries for failed requests made by the Feign client. It uses the injected retryer configuration values for setting the period, maxPeriod, and maxAttempts.