Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the problem of data insertion duplication caused by dubbo interface call

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "how to solve the problem of data insertion and duplication caused by dubbo interface calls", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to solve the problem of data insertion and duplication caused by dubbo interface calls.

Large pit simulation reproduction

Simply build the dubbo environment dubbo-service dubbo-service-sdk dubbo-service-web 1, and create a new module dubbo-service-sdk definition service interface

/ * @ author v_liuwen * @ date 2019-07-24 * / public interface AsoService {void saveAso (AsoInfoDto asoInfoDto) throws InterruptedException;} / * * @ author v_liuwen * @ date 2019-07-24 * / @ Datapublic class AsoInfoDto implements Serializable {private static final long serialVersionUID = 1L; private Long asoId; private String asoNo; private String linkOrderNo; private Date createTime;}

2. Create a new module dubbo-service to implement the interface dependency of 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@Slf4jpublic class AsoServiceImpl implements AsoService {@ Override public void saveAso (AsoInfoDto asoInfoDto) throws InterruptedException {/ / simulated blocking timeout Thread.sleep (5000) Log.info ("insert after-sales order information-- > {}", JSONObject.toJSONString (asoInfoDto));}}

3. Create a new module dubbo-service-web dependency

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

Define business interface

/ * @ author v_liuwen * @ date 2019-07-24 * / public interface CreateAsoService {void saveAso ();}

Define business implementation

/ * @ author v_liuwen * @ date 2019-07-24 * / @ Service@Slf4jpublic 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 ("exception-- > {}", e.getMessage ());}

Test class

RunWith (SpringRunner.class) @ SpringBootTest public class DubboWebApplicationTests {@ Autowired private CreateAsoService createAsoService; @ Test public void contextLoads () {createAsoService.saveAso ();}}

Start dubbo-service to run the test method console output

2019-07-25 21 21 t.q.dubboservice.impl.AsoServiceImpl: insert after-sales order information-- > {"asoId": 8248, "asoNo": "aQg", "createTime": 2995060930132 "linkOrderNo": "zDv2"} 2019-07-25 21 INFO 27.603 INFO 6720-- [: 20880-thread-6] t.q.dubboservice.impl.AsoServiceImpl: insert after-sales order information-- > {"asoId": 8248, "asoNo": "aQg", "createTime": 2995060930132 "linkOrderNo": "zDv2" 2019-07-25 21 INFO 0315 INFO 6720-- [: 20880-thread-7] t.q.dubboservice.impl.AsoServiceImpl: insert after-sales order information-- > {"asoId": 8248, "asoNo": "aQg", "createTime": 2995060930132, "linkOrderNo": "zDv2"}

At the beginning, it was suspected that the perfect recurrence problem was caused by retrying the configuration, but the default retries of @ Reference is 0, that is, if it is not configured, it will be retried 0 times by default, that is, it will not retry. Then why did you transfer it three times? So try to configure the number of retries to be-1

@ Reference (version = "1. 0", retries =-1 retries check = false)

Operate the console output again

At this point, I believe you have a deeper understanding of "how to solve the problem of data insertion and duplication caused by dubbo interface calls". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report