简体   繁体   English

实现 Spring 批量断路器

[英]Implement Spring batch circuit breaker

I am building a Spring batch job and in the Item processor step I am consuming an external end-point and saving the values to DB.我正在构建一个 Spring 批处理作业,在 Item 处理器步骤中,我正在使用一个外部端点并将值保存到 DB。 The external point at times is very slow and takes more than 60 sec to respond.外部点有时非常慢,需要超过 60 秒才能响应。 So, as a work around I implemented restTemplate timeout(15s) but, how to implement circuit breaker techniques here.因此,作为一种解决方法,我实现restTemplate timeout(15s) 但是,如何在这里实现断路器技术。 As a result of this my transaction is timing out (even after implementing timeout).因此,我的交易超时(即使在实施超时之后)。 Are there any solutions to overcome this out of box in spring-batch.是否有任何解决方案可以在 spring-batch 中解决这个问题。

how to implement circuit breaker techniques here如何在这里实现断路器技术

You can annotate the ItemProcessor#process with @CircuitBreaker (see attributes like maxAttempts , resetTimeout , etc) from the spring-retry library and add a recovery method that you annotate with @Recover .您可以使用spring-retry库中的@CircuitBreaker注释ItemProcessor#process (请参阅maxAttemptsresetTimeout等属性),并添加您使用@Recover注释的恢复方法。

Michael Minella gives a complete sample of this very scenario in his talk: Cloud Native Batch Processing . Michael Minella 在他的演讲中给出了这个场景的完整示例:云原生批处理 And you can find the code example here .您可以在此处找到代码示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM