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

What is the idempotency of java

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

This article introduces the relevant knowledge of "what is the idempotency of java". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

What is idempotency?

In general, when a service is invoked, if the call to the read service fails, it will automatically transfer the request to another service according to the number of times configured. On the other hand, the write service cannot repeat the request. If the called service does not return a successful response due to timeout or network failure, the service caller will consider it a failure, but it is very likely that it has been successful. if you continue to repeat requests for writing services, such as money transfer services, it may cause serious consequences. Therefore, the failure to write a service cannot be designed to continue to send repeated requests, and the called service should also be idempotent, even if the request is repeated, it will not affect.

Knowing the background above, idempotency is the same parameter, and if you request the same service repeatedly, you must get the same result.

Idempotent design

Take a payment scenario and request a third-party payment API to initiate the payment function. The same order number and the same amount information all return success. The same order number, different amount information, returns a duplicate order number. This is the idempotent design, the third-party payment validates that the request parameters are consistent with the information of the existing database and directly returns the existing successful data, and if the data is inconsistent and the order number is repeated, directly report the order number repeat. If you do not do the idempotent design, the same order number, the same amount information, repeated payment, may cause the amount to accumulate. In order to serve friendliness, it is also unfriendly for the same order number and the same amount information to return the order number to repeat.

Some services are inherently idempotent, such as changing a user's mailbox, gender, etc., no matter how many times you repeat the request, the result will be the same.

Therefore, the key point of service idempotent design is to verify the validity of request parameters and compare the existing data. If the same request parameters have been processed, do not repeat the processing, return directly, this is the idempotent core point.

The following picture has formally illustrated the importance of idempotence.

This is the end of "what is the idempotency of java". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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