在实际业务场景中,需要通知下游或第三方消息,并且该通知无法快速得到响应结果,且我不需要得到实时响应结果,可以采取异步通知的处理。避免程序阻塞,提高请求响应的速度。
1.自定义通知第三方消息传递接口
public interface RemoteVideoWorkIntegration {
ResultModel<String> uploadDocumentApproval(String claimApplyNo);
}
2.定义异步处理类
import cn.cic.irc.report.domain.report.integration.RemoteVideoWorkIntegration;
import com.alibaba.fastjson.JSON;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.lang.reflect.Method;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
public class AsynchronousTasks<T> {
private static final Logger logger = LoggerFactory.getLogger(AsynchronousTasks.class);
private static volatile ThreadPoolExecutor threadPoolExecutor = null;
private static volatile AsynchronousTasks asynchronousTasks