Hystrix to Resilience4J - hystrix

I've been working with Hystrix but now I want to change one project from Hystrix to Resilience4J but I don't not how!
My code is as follow:
#FeignClient(name = "customer-service", fallback = CustomerHystrixFallbackFactory.class)
public interface CustomerClient {
#GetMapping(value = "/customers/{id}")
public ResponseEntity<Customer> getCustomer(#PathVariable("id") long id);
}
And my CustomerHystrixFallbackFactory as follow:
#Component
public class CustomerHystrixFallbackFactory implements CustomerClient{
#Override
public ResponseEntity<Customer> getCustomer(long id) {
Customer customer = Customer.builder()
.firstName("none")
.lastName("none")
.email("none")
.photoUrl("none").build();
return ResponseEntity.ok(customer);
}
}
The thing is when customer-service is down, it returns none, but not a 500 Error message.
So, how can I convert what I have to apply Resilience4J?
Thanks in advance!

Related

ABPFramwork - Remove api from layer application in swagger

I have created a project using abpframwork. When running swagger, swagger receives the function in the application layer is a api. I don't want that. Can you guys tell me how to remove it in swagger
Code in Application Layer
public class UserService : AdminSSOAppService, ITransientDependency, IValidationEnabled, IUserService
{
IUserRepository _userRepository;
private readonly ILogger<UserService> _log;
public UserService(IUserRepository userRepository,
ILogger<UserService> log
)
{
_userRepository = userRepository;
_log = log;
}
public async Task<List<UserDto>> GetList()
{
var list = await _userRepository.GetListAsync();
return ObjectMapper.Map<List<User>, List<UserDto>>(list);
}
public async Task<UserDto> GetUserById(int Id)
{
var user = await _userRepository.GetAsync(c=>c.Id == Id);
return ObjectMapper.Map<User, UserDto>(user);
}
}
Code in HttpApi Layer
[Area(AdminSSORemoteServiceConsts.ModuleName)]
[RemoteService(Name = AdminSSORemoteServiceConsts.RemoteServiceName)]
[Route("api/user/user-profile")]
public class UserController : ControllerBase, IUserService
{
private readonly IUserService _userAppService;
public UserController(IUserService userAppService)
{
_userAppService = userAppService;
}
[HttpGet]
[Route("get-list-httpapi")]
public Task<List<UserDto>> GetList()
{
return _userAppService.GetList();
}
[HttpGet]
[Route("get-by-id-httpapi")]
public Task<UserDto> GetUserById(int Id)
{
return _userAppService.GetUserById(Id);
}
}
I can suggest a workaround as to enable only the APIs you need to appear on swagger (though the ones that don't appear anymore will still be available for consumption).
I would suggest you add a configuration part in your *.Http.Api project module inside your ConfigureSwaggerServices, like so:
context.Services.AddSwaggerGen(options =>
{
options.DocInclusionPredicate(
(_, apiDesc) =>
apiDesc
.CustomAttributes()
.OfType<IncludeInSwaggerDocAttribute>()
.Any());
});
And for the attribute, it would be very simple, like so:
[AttributeUsage(AttributeTargets.Class)]
public class IncludeInSwaggerDocAttribute : Attribute
{
}
This will let you achieve what you want, however I still recommend reading the doc carefully to be able to implement DDD.

React Js and Spring boot faster xml jackson databin

Hello when i try to get all values with this path : localhost:8080/aspsort/all
i get error :
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:166) ~[jackson-databind-2.10.3.jar:2.10.3]
the method is :
#GetMapping("/all")
public Iterable<Rfpobject> getallRFP()
{
return rfprepo.findAll();
}
instead of Iterable try changing it to List as return type .
and in rfprepo interface add this
#Override
List<Data> findAll();
example
#Autowired
RfpRepository rfprepo;
#GetMapping("/all")
public Iterable<Rfpobject> getallRFP()
{
return rfprepo.findAll();
}
public interface RfpRepository extends CrudRepository<Rfpobject, Long> {
#Override
List<Rfpobject> findAll();
}
let me know if this solved your issue.

Spring AOP by annotation pointcut annotation not retrieve

I'm using Spring AOP for intercept annoted methods by #MyAnnotation. The intercepting is ok. but, unfortunately, i'm not arrive to have my annotation instance.
My Annotation :
#Retention(RetentionPolicy.RUNTIME)
#Target(ElementType.METHOD)
public #interface MyAnnotation {
String[] description();
}
My Configuration Aspect
#Aspect
public class OAuthAspect {
#Pointcut(value = "execution(public * *(..))")
public void anyPublicMethod() {
}
#Pointcut(value = "#annotation(annotation)", argNames = "annotation")
public void anyAnnotationMethod(MyAnnotation annotation) {
}
#Around(value = "anyPublicMethod() && anyAnnotationMethod(annotation)")
public Object authorization(ProceedingJoinPoint pjp, MyAnnotation annotation) throws Throwable {
//annotation is null
}
}
Example pointcut :
#Service
public class ContextService {
#MyAnnotation(description = {"de1", "des2"})
public String getAll() {
}
}
I don't understand why I can't retrieve the instance of the annotation.
if someone have an idea?
pc : edited
For me the class ContextService does not even compile because of a typo in your annotation: String[] descrition(); (note the missing "p") should really be String[] description();, then it compiles and I can also print the annotation instance.

How to make an aspect detect a method with multiple annotations

I have a spring application and I want to use aspects to perform some performance logging.
I want to only log methods annotated with #Measured, so I created an annotation as follows :
#Retention(RetentionPolicy.RUNTIME)
#Target(ElementType.METHOD)
public #interface Measured {
boolean logParameters() default true;
boolean logResponse() default true;
boolean measureTime() default true;
}
The aspect is as follows:
#Aspect
#Component
public class MeasuredAspect {
#Pointcut(value = "#annotation(com.waelawada.web.Measured)")
public void isMeasurableEvent(){
}
#Around(value = "isMeasurableEvent() && #annotation(measured)")
public void addEventToMDC(ProceedingJoinPoint joinPoint, Measured measured) throws Throwable{
String methodName = joinPoint.getSignature().getName();
long startTime = System.currentTimeMillis();
joinPoint.proceed(joinPoint.getArgs());
long endTime = System.currentTimeMillis();
if(measured.measureTime()){
MDC.put(methodName,endTime-startTime);
}
}
}
This works just fine for a method like
#Measured
public boolean getUser() {
}
Now I want to annotate a spring mvc controller method that is already annotated with #RequestMapping, but the apsect doesn't seem to detect it.
#Measured
#RequestMapping(value = "/activity", method = GET)
public final String userProfile(#ModelAttribute(USER) User user,
Model model) {
//Do Something
}
How can i make the aspect detect this method? I am using spring aop definded in the context xml file as <aop:aspectj-autoproxy proxy-target-class="false"/>

Apache CXF Client Not getting Invoked

I am new to Apache CXF , so please help .
I dont know why the client is not getting called .
client = (BayerService) factory.create();
I did this way
public class RunBayer implements CallbackHandler
{
RunBayer()
{
init();
}
private static void init()
{
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
WSS4JOutInterceptor out = new WSS4JOutInterceptor();
out.setProperty(WSHandlerConstants.ACTION, WSHandlerConstants.TIMESTAMP + " " + WSHandlerConstants.SIGNATURE);
out.setProperty(WSHandlerConstants.USER, "svi_ws");
out.setProperty(WSHandlerConstants.PASSWORD_TYPE, "PasswordDigest");
factory.getOutInterceptors().add(out);
factory.setServiceClass(BayerService.class);
factory.setAddress(host);
client = (BayerService) factory.create();
}
}
And I have a BayerService interface which is in this format
public interface BayerService
{
public OurServiceResponse OurView(#WebParam(name = "request") ServiceRequest request);
}
I have another class named Bayer.java which actually implements this Interafce
public class Bayer implements BayerService
{
public OurServiceResponse OurView(ServiceRequest request)
{
// code
}
}
Could anybody please tell me why the control is not coming inside when i call this way ??
Thank you very much .
I didn't see the code like below in your RunBayer class.
client.OurView(request);

Resources