您好,登錄后才能下訂單哦!
本篇內容主要講解“dubbo接口調用造成的數據插入重復問題怎么解決”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學習“dubbo接口調用造成的數據插入重復問題怎么解決”吧!
簡單搭建一下dubbo環境 dubbo-service dubbo-service-sdk dubbo-service-web 1、新建module dubbo-service-sdk 定義服務接口
/** * @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 實現sdk的接口 依賴
<dependency> <groupId>top.qrainly</groupId> <artifactId>dubbo-service-sdk</artifactId> <version>0.0.1-SNAPSHOT</version> </dependency> <dependency> <groupId>com.alibaba.boot</groupId> <artifactId>dubbo-spring-boot-starter</artifactId> <version>0.2.0</version> </dependency> <dependency> <groupId>org.apache.zookeeper</groupId> <artifactId>zookeeper</artifactId> <version>3.4.13</version> </dependency>
/** * @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 { //模擬阻塞超時 Thread.sleep(5000); log.info("插入售后單信息-->{}", JSONObject.toJSONString(asoInfoDto)); } }
3、新建module dubbo-service-web 依賴
<dependency> <groupId>top.qrainly</groupId> <artifactId>dubbo-service-sdk</artifactId> <version>0.0.1-SNAPSHOT</version> </dependency> <dependency> <groupId>com.alibaba.boot</groupId> <artifactId>dubbo-spring-boot-starter</artifactId> <version>0.2.0</version> </dependency> <dependency> <groupId>org.apache.zookeeper</groupId> <artifactId>zookeeper</artifactId> <version>3.4.13</version> </dependency>
定義業務接口
/** * @author v_liuwen * @date 2019-07-24 */ public interface CreateAsoService { void saveAso(); }
定義業務實現
/** * @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(); } }
啟動dubbo-service 運行測試方法 控制臺輸出
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"}
完美復現問題 剛開始就懷疑是不是重試配置導致的,但是看了一下@Reference的retries默認也是0,也就是說不配置的話默認重試0次,也就是不重試。 那為啥還調了三次。于是嘗試配置了重試次數為-1
@Reference(version = "1.0",retries = -1,check = false)
再次操作 控制臺輸出
到此,相信大家對“dubbo接口調用造成的數據插入重復問題怎么解決”有了更深的了解,不妨來實際操作一番吧!這里是億速云網站,更多相關內容可以進入相關頻道進行查詢,關注我們,繼續學習!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。