本篇內(nèi)容主要講解“dubbo接口調(diào)用造成的數(shù)據(jù)插入重復(fù)問題怎么解決”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實(shí)用性強(qiáng)。下面就讓小編來帶大家學(xué)習(xí)“dubbo接口調(diào)用造成的數(shù)據(jù)插入重復(fù)問題怎么解決”吧!
紅河網(wǎng)站建設(shè)公司創(chuàng)新互聯(lián)公司,紅河網(wǎng)站設(shè)計(jì)制作,有大型網(wǎng)站制作公司豐富經(jīng)驗(yàn)。已為紅河成百上千家提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\外貿(mào)網(wǎng)站建設(shè)要多少錢,請(qǐng)找那個(gè)售后服務(wù)好的紅河做網(wǎng)站的公司定做!
簡單搭建一下dubbo環(huán)境 dubbo-service dubbo-service-sdk dubbo-service-web 1、新建module dubbo-service-sdk 定義服務(wù)接口
/** * @author v_liuwen * @date 2019-07-24 */ public interface AsoService { void saveAso(AsoInfoDto asoInfoDto) throws InterruptedException; }
/** * @author v_liuwen * @date 2019-07-24 */ @Data public class AsoInfoDto implements Serializable { private static final long serialVersionUID = 1L; private Long asoId; private String asoNo; private String linkOrderNo; private Date createTime; }
2、新建module dubbo-service 實(shí)現(xiàn)sdk的接口依賴
top.qrainly dubbo-service-sdk 0.0.1-SNAPSHOT com.alibaba.boot dubbo-spring-boot-starter 0.2.0 org.apache.zookeeper zookeeper 3.4.13
/** * @author v_liuwen * @date 2019-07-24 */ @Service(version = "1.0", interfaceClass = AsoService.class) @Component @Slf4j public class AsoServiceImpl implements AsoService { @Override public void saveAso(AsoInfoDto asoInfoDto) throws InterruptedException { //模擬阻塞超時(shí) Thread.sleep(5000); log.info("插入售后單信息-->{}", JSONObject.toJSONString(asoInfoDto)); } }
3、新建module dubbo-service-web依賴
top.qrainly dubbo-service-sdk 0.0.1-SNAPSHOT com.alibaba.boot dubbo-spring-boot-starter 0.2.0 org.apache.zookeeper zookeeper 3.4.13
定義業(yè)務(wù)接口
/** * @author v_liuwen * @date 2019-07-24 */ public interface CreateAsoService { void saveAso(); }
定義業(yè)務(wù)實(shí)現(xiàn)
/** * @author v_liuwen * @date 2019-07-24 */ @Service @Slf4j public class CreateAsoServiceImpl implements CreateAsoService { @Reference(version = "1.0",check = false) private AsoService asoService; @Override public void saveAso() { AsoInfoDto mock = JMockData.mock(AsoInfoDto.class); try { asoService.saveAso(mock); } catch (InterruptedException e) { log.error("異常-->{}",e.getMessage()); } } }
測試類
@RunWith(SpringRunner.class) @SpringBootTest public class DubboWebApplicationTests { @Autowired private CreateAsoService createAsoService; @Test public void contextLoads() { createAsoService.saveAso(); } }
啟動(dòng)dubbo-service 運(yùn)行測試方法 控制臺(tái)輸出
2019-07-25 21:03:24.655 INFO 6720 --- [:20880-thread-5] t.q.dubboservice.impl.AsoServiceImpl : 插入售后單信息-->{"asoId":8248,"asoNo":"aQg","createTime":2995060930132,"linkOrderNo":"zDv2"} 2019-07-25 21:03:27.603 INFO 6720 --- [:20880-thread-6] t.q.dubboservice.impl.AsoServiceImpl : 插入售后單信息-->{"asoId":8248,"asoNo":"aQg","createTime":2995060930132,"linkOrderNo":"zDv2"} 2019-07-25 21:03:30.616 INFO 6720 --- [:20880-thread-7] t.q.dubboservice.impl.AsoServiceImpl : 插入售后單信息-->{"asoId":8248,"asoNo":"aQg","createTime":2995060930132,"linkOrderNo":"zDv2"}
完美復(fù)現(xiàn)問題 剛開始就懷疑是不是重試配置導(dǎo)致的,但是看了一下@Reference的retries默認(rèn)也是0,也就是說不配置的話默認(rèn)重試0次,也就是不重試。 那為啥還調(diào)了三次。于是嘗試配置了重試次數(shù)為-1
@Reference(version = "1.0",retries = -1,check = false)
再次操作 控制臺(tái)輸出
到此,相信大家對(duì)“dubbo接口調(diào)用造成的數(shù)據(jù)插入重復(fù)問題怎么解決”有了更深的了解,不妨來實(shí)際操作一番吧!這里是創(chuàng)新互聯(lián)網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!