- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
尽管对于其他返回类型,Spring 重试回退机制似乎工作正常,但是当涉及到调用返回类型为 void 的 API 时。恢复方法根本没有被调用,我已经尝试了所有可能的方法参数类型并更改了后备方法的返回类型......有什么方法可以做到这一点吗?我不明白为什么 @CircuitBReaker 注释没有参数来获取作为值传递给它的后备方法名称?
@CircuitBreaker(maxAttempts = 3, openTimeout = 8000, resetTimeout = 15000)
public Void callingXYZ(final Abc abc, final Cdf cdf) {
return retryTemplate.execute(context -> {
log.info("Retry count={} when calling ******", context.getRetryCount());
AbcServiceImpl.this.update*****Settings(OrgId.fromString(abc.getUUID(), cdf.getData());
return null;
});
}
//Recover method that should get invoked
@Recover
public Void fallbackUpdate*****(Throwable e, Abc abc) throws Throwable{
log.info("Inside fallback");
if (e instanceof ClientException) {
log.warn("Fallback method is called when trying to call ******** from ****** because of {}", e.getCause());
//Rollback in the db based on the method attributes
throw SpecificException.forTask(HttpStatus.SERVICE_UNAVAILABLE.value(),
Enum.NAME.getErrorCode(),
Enum.NAME.getMEssage(), true);
}
throw e;
}
最佳答案
您是否曾经使用@Transactional(或例如@Async)注释一个方法但它不起作用?好像它完全被 Spring 忽略了?这是因为像这样的注释不能(至少默认情况下)只放在任何方法上,必须满足以下两个条件才能让 Spring 采取行动:
方法可见性只能是 public。调用必须来自 bean 外部。这是由于 Spring 代理默认的工作方式(使用 CGLIB 代理)造成的。我不会深入讨论细节,因为这个主题足够宽泛,可以写另一篇文章,但一般来说,当您 Autowiring Sample 类型的 bean 时,Spring 实际上并没有为您提供确切的 Sample 实例。相反,它会注入(inject)一个生成的代理类,该代理类扩展了 Sample(这就是为什么您不能将 Spring bean 类设为最终的原因)并重写其公共(public)方法以便能够添加额外的行为(例如事务支持)。
这就是为什么带有@Transactional的方法必须是公共(public)的(这样Spring可以轻松覆盖它们),这也是为什么调用必须来自外部(只有这样它才可以通过代理,Spring不能用代理替换这个引用引用)。
取自 https://codete.com/blog/5-common-spring-transactional-pitfalls/
关于java - @Recover(后备方法)与 @CircuitBreaker 一起使用时,一旦所有重试都用尽,就不会被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60260698/
是否可以重试网络客户端请求?在奇怪的情况下,我的应用程序在尝试连接到 xml Web 服务时会抛出错误,但如果我重试,它就可以正常工作。我希望它在抛出错误之前重试 2 次,除非有人有更好的解决方案:)
我在一本书中找到了这段代码片段: int ival; // read cin and test only for EOF; loop is executed even if there are oth
是否可以使用 for lop 来设置对象的条件。如果该条件未通过测试(if 语句),则更改条件直到它通过测试?这是我的伪代码尝试,但我怀疑它是否有效: for (int i = 0; i < myAr
我有以下问题。我的主要 Activity 由一个 ListView 组成,其中填充了从 Web 服务获得的数据。首次加载主要 Activity 时,以防无法从网络检索数据,我想显示一个带有 2 个按钮
我有微服务应用程序。为了协作,每个服务都使用异步消息传递。我知道,spring data jpa 默认使用乐观锁。但是如果这种锁定不是由用户调用,而是由另一个服务调用的方法(在我的示例中有验证服务,可
我希望能够在 F# 中编写一个计算表达式,如果它抛出异常,它将能够重试操作。现在我的代码看起来像: let x = retry (fun() -> GetResourceX()) let y = re
是否可以在 NServiceBus 版本 3.2.2 中禁用重试? 使用以下配置,可以禁用重试: 但当线程数设置为 20 时则不会。在这种情况下,消息会重试两次: 这看起来很像
我在 failed_jobs 上有多个失败的作业。我尝试重新排队 MaxAttemptsExceededException 但总是失败。如何重试那里的工作类型? 注意:每次我通过 php artisa
下面的 sproc 尝试向表中插入一行并生成一个随机 ID,用于在相应表上进行 PK。与随机生成的 ID 的冲突在 catch 块中处理,在那里再次重试/调用该过程。现在,这需要很长时间并导致死锁,因
我试图实现代码以使用“mocha-retry”重试失败的测试以下是示例。 describe(retries,' retries-',function () { var self = this;
我正在尝试通过 Azure 数据工厂将数据从 Azure 数据湖存储插入到 Azure 表。 Azure Data Lake 文件中的数据与最终 Azure 表接收器的架构相同。 ADF 管道包含从
是http.RoundTripper在 Go 中基于 HTTP 状态代码(例如 429)实现 http GET 请求重试机制的正确位置? 它在某种程度上“感觉正确”( Go Playground )并
使用 spring reactive WebClient,我使用了一个 API,如果响应状态为 500,我需要使用指数退避重试。但是在 Mono 类中,我没有看到任何以 Predicate 作为输入参
我一直在尝试编写 react native 的快速入门指南,但一直收到此错误 There appears to be trouble with your network connection. Ret
我正在尝试使用从我们心爱的堆栈溢出中获取的 Retry Monad: type RetryBuilder(max, sleep : TimeSpan) = member x.Return(
使用 spring reactive WebClient,我使用了一个 API,如果响应状态为 500,我需要使用指数退避重试。但是在 Mono 类中,我没有看到任何以 Predicate 作为输入参
我有一个由 C#.NET 4.0 开发的两层 Windows 窗体应用程序。在这个应用程序中,我读取文件内容并在数据访问层中创建实体列表,并将其返回到 GUI 层以在 GridView 中显示。在我当
如果有人问过这个问题,我深表歉意,但我已经做了很多搜索,但还没有找到与我的问题类似的问题。 在我的应用程序中,我有一个密码更改页面,如果某人是新用户或重置了他/她的密码,该页面就会触发。 问题是,一旦
想知道为什么我的 promise 正在解决但试图重试。 var getResultsStream = url => Rx.Observable.onErrorResumeNext( Rx.O
假设我有以下 Promise 链: var result = Promise.resolve(filename) .then(unpackDataFromFile) .then(tra
我是一名优秀的程序员,十分优秀!