十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
本篇内容主要讲解“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的接口依赖
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 { //模拟阻塞超时 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
定义业务接口
/** * @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接口调用造成的数据插入重复问题怎么解决”有了更深的了解,不妨来实际操作一番吧!这里是创新互联网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!