Retryable

This commit is contained in:
joshen@zcwytd.com
2023-11-29 13:23:19 +08:00
parent ba1a96ce8f
commit a308f1d94e
3 changed files with 18 additions and 2 deletions

View File

@@ -228,7 +228,11 @@
<artifactId>elasticsearch-rest-client</artifactId>
<version>7.9.0</version>
</dependency>
<dependency>
<groupId>org.springframework.retry</groupId>
<artifactId>spring-retry</artifactId>
<version>1.3.1</version>
</dependency>
</dependencies>
<build>
<resources>

View File

@@ -4,6 +4,8 @@ import java.io.File;
import java.io.IOException;
import javax.annotation.PostConstruct;
import org.springframework.retry.annotation.EnableRetry;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@@ -15,6 +17,7 @@ import org.springframework.context.annotation.Configuration;
@SpringBootApplication
@EnableCaching
@EnableAsync
@EnableRetry
public class BoeServerAllApplication {
public static void main(String[] args) {

View File

@@ -6,6 +6,8 @@ import javax.transaction.Transactional;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.retry.annotation.Recover;
import org.springframework.retry.annotation.Retryable;
import org.springframework.stereotype.Service;
import com.xboe.account.dao.AccountDao;
@@ -40,7 +42,8 @@ public class DataUserSyncServiceImpl implements IDataUserSyncService{
@Override
@Transactional
public synchronized void syncUserFull(UserData user) {
@Retryable
public void syncUserFull(UserData user) {
log.info("同步用户【"+user.getId()+","+user.getCode()+"");
//如果删除状态为空,则设置为不删除
if(user.getDeleted()==null) {
@@ -154,4 +157,10 @@ public class DataUserSyncServiceImpl implements IDataUserSyncService{
}
@Recover
private void recover() {
System.out.println("重试3次都失败-----recover-------------recover-------------");
}
}