background

In the process of project development, it is common to call some three-party interfaces. For example: object storage, enterprise information query, SMS sending and so on.

The problem

Because the interfaces of the three parties usually have multiple products to choose from, for example, object storage service can use OSS of Ali Cloud, OBS of Huawei Cloud, as well as FastDFS and Mineo deployed locally, so sometimes scalability needs to be considered.

Usually, projects using tripartite interfaces are basically determined during development and are rarely replaced in the future, and are difficult to replace (for example, object storage, if it needs to be replaced, also involves the migration of historical data. But SMS service replacement is relatively low migration costs).

Design ideas

Java is an object-oriented language and follows the face – to – face interface development pattern.

Design of the interface

Because the existing tripartite interface needs similar parameters, so we can design the interface of a certain one. For example, the object storage service needs to upload the object, bucket name, object ID, etc.

The specific implementation

Specific implementation of the interface.

Code development approach

  • integration

    • Advantage: No need to create additional JAR package, single application is suitable.
    • Cons: Third-party interfaces may need to import their own JARs, and multiple three-party JARs may need to be imported in Maven, but you can use Scope to set whether to package into a project
  • Break up

    • Advantages: You can develop tripartite implementations independently of the interface, and only need to introduce the required parts in Maven
    • Cons: Extra JAR packages are required, not ideal for monolithic applications

The sample

Because we want to build a common function to serve the micro service, we use the split code development method. github: https://github.com/wenyu7980/… gitee: https://gitee.com/wenyu7980/w…

conclusion

In this paper, I want to show a way to deal with the development of tripartite interface, although it is good to change the tripartite interface in the actual development.