中斷重試機制

2021-10-09 11:28:45 字數 1457 閱讀 6495

原文:

中斷重試**

/**

* 中斷重試機制

*/public

abstract

class

retrytemplate

public retrytemplate setsleeptime

(int sleeptime)

this

.sleeptime = sleeptime;

return

this;}

public

intgetretrytime()

public retrytemplate setretrytime

(int retrytime)

this

.retrytime = retrytime;

return

this;}

/** * 重試的業務執行**

* 失敗時請丟擲乙個異常

* * todo 確定返回的封裝類,根據返回結果的狀態來判定是否需要重試

* * @return

*/protected

abstract object dobiz()

throws exception;

//預留乙個dobiz方法由業務方來實現,在其中書寫需要重試的業務**,然後執行即可

public object execute()

throws interruptedexception

catch

(exception e)

", e)

; thread.

sleep

(sleeptime);}

}return null;

}public object submit

(executorservice executorservice)

future

submit = executorservice.

submit

((callable)()

->

execute()

);return submit;

}

呼叫

/**

* 異常重試

*/object ans =

newretrytemplate()

catch

(exception e)

return returnt.success;}}

.setretrytime

(retryconfig.

getretrytime()

).setsleeptime

(retryconfig.

getsleeptime()

).execute()

;//setretrytime : 重試次數

//setsleeptime :重試時間

Spring重試機制

org.springframework.retrygroupid spring retryartifactid dependency org.springframework.bootgroupid spring boot starter aopartifactid dependency 程式啟動類新...

Polly 重試機制

引用 install package microsoft.extensions.http.polly 在core中的使用 方式一 先配置再執行 注意 執行 executeasync 方法,異常會丟擲 方式二 邊配置邊執行 result await policy handle ex ex.code 4...

ActiveMQ重試機制

1.activemq重試機制是什麼?消費者收到訊息,之後出現異常了,沒有告訴broker確認收到該訊息,broker 會嘗試再將該訊息傳送給消費者。嘗試 n次,如果消費者還是沒有確認收到該訊息,那麼該訊息將被放到死信佇列中,之後 broker 不會再將該訊息傳送給消費者。2.具體哪些情況會引發訊息重...