Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

188
Vistas
Spring reintentar encontrar el último reintento

Estoy usando Spring-retry-1.2.0 , Retry funciona bien, pero en mi método quiero averiguar si el nuevo juicio es el último intento o no. ¿Hay algún método disponible para obtener el número de intentos o el último intento en primavera? -¿rever?

Nuevo juicio.java

 public class Offers extends SimpleRetryPolicy { @Async @Retryable(maxAttemptsExpression = "#{retrial.times}", backoff = @Backoff(delayExpression = "#{retrial.delay}")) public void handleOfferes(Data data) { AlwaysRetryPolicy policy = new AlwaysRetryPolicy(); RetryContext context = policy.open(null); System.out.println("context.getRetryCount()::"+context.getRetryCount()); //Always logs 0 even if it retries 2 to 3 times... System.out.println("Can retry::"+canRetry(context)); //Always true //Business Logic //Get the last count and update the DB ...retrial is ends with failure } @Override public boolean canRetry(RetryContext context) { System.out.println("context.getRetryCount()::"+context.getRetryCount()); System.out.println("getMaxAttempts::"+getMaxAttempts()); return context.getRetryCount() < getMaxAttempts(); } }

Cambios realizados después de los comentarios de Artem Bilan

ReintentarConfiguración

 @Configuration public class RetryConfiguration { @Value("${retrial.times}") private Long delayExpression; @Value("${retrial.delay}") private int maxAttempts; @Bean @ConditionalOnMissingBean(name = "retryInterceptor") public RetryOperationsInterceptor retryInterceptor() { return RetryInterceptorBuilder .stateless() .backOffOptions(0L, 0.0D, delayExpression) .maxAttempts(maxAttempts).build(); } }

ofertas.java

 @Service public class Offers { @Async @Retryable(interceptor = "retryInterceptor") public void handleDeviceStatus(Data data) { //Here how shall i get the retrial count... }

Cualquier ayuda sería apreciable.

about 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

Creo que lo que necesita se llama @Recover ( RecoveryCallback si no tiene anotaciones):

 @Retryable(RemoteAccessException.class) public void service() { // ... do something } @Recover public void recover(RemoteAccessException e) { // ... panic }

Consulte el mismo LÉAME y el caso de prueba al respecto.

about 4 years ago · Santiago Trujillo Denunciar

0

Si está creando/usando manualmente RetryTemplate, puede obtener el recuento actual de reintentos de RetryContext de la siguiente manera:

 public String callWithRetry() { return retryTemplate.execute(new RetryCallback<String, RuntimeException>() { @Override public String doWithRetry(RetryContext context) { LOG.info("Retry count: {}", context.getRetryCount()); return theService.perform(); } }); }
about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda