[Original] importance of interface specifications and importance of interface specifications

Source: Internet
Author: User

[Original] importance of interface specifications and importance of interface specifications

 
After a single project is split into a SOA distributed architecture, the interface layer definition specification is particularly important. Today I will summarize the problems caused by an nonstandard interface definition. # First, my current project architecture is roughly like this:

Master technology Stack: dubbo + spring boot. The internal wap, app, and pc have similar services, such as user-service.

    

  

# Problem Origin

The product provides an urgent requirement for fixing a previous verification vulnerability. After checking the code, the interface I defined is:

Int queryUserIsOpen (String cardId );

So after I make the transformation, I will see the following:

Result queryUserIsOpen (String cardid, int userType );

After the PC-side test is OK, it is directly lost to production. As a result, the next day, an exception occurred to a service on the wap side and app side. If an error occurs during log troubleshooting, the returned type is incorrect. Later I remembered that other terminals also called this method. Because I changed the parameter type returned by the interface and then published it online, the previous service has been overwritten by my version, at this time, other terminals still use the old code. Once they are remotely called, they still use int to receive the returned Result.

So I first upgrade the wap and app versions, and then synchronize the code on both sides before sending it to production to solve this problem.

# Why is this common problem in SOA architecture:

Library version maintenance and code coupling between business lines:

Business Line A upgrades user. so from version 1 to version 2. If it is not compatible with the Code of Business Line B, business B may encounter problems;

If business line A notifies business line B of the upgrade, business line B will perform some "independent business" upgrades without reason, which is very depressing. Of course, this problem does not exist if all business lines copy a copy of the code.

 

# How to avoid this problem

I have seen the necessity of interface specifications a long time ago, but sometimes I ignore the need of other departments to call this service together. Through the above example, it is not difficult to find that this problem can be avoided by defining interface specifications at the beginning. If the bean returned is defined as Result at the beginning and the input parameter is Vo at the same time, when a change occurs in the downstream, the returned Result is set to Result, this avoids the problem I encountered in the article at the beginning and reduces the cost of online maintenance.

The Result code is as follows:

  

Public class Result <T> implements Serializable {private static final long serialVersionUID = 1L;/** return code */private String code = "200 "; /** return error message prompt */private String message;/** return the requested token */private String token if a signature is required; /** return the client signature */private String sign;/** return Result */private T t; public Result () {super ();}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.