SpringCloud Netflix, which can also be deployed in a standalone host environment, is the most pedigreed, and is referred to in the following articles. While some components are no longer maintained, the good news is that they are hot-pluggable (unless you’ve already been robbed).

SpringCloud is just a bunch of specifications in which components are replaceable. Personally, if you use the SpringCloud stack, you have to build your own SpringCloud. Depending on the technology preference and functionality, you may choose to integrate different components from N companies, and most of your work is really on service governance.

It would have been nice to have a replacement starter, but cloud vendors don’t think so. Aws, by the way, has created its own SpringCloud, which integrates its own services and sells well. So Azure and so on, also made a set, but can only run on their own cloud. If you use it, you’ll know how much these dads love you if you ever want to switch consoles. Since there is this effect, an oligarch of the East itching, but also to follow the trend of The Times.

Because monopoly is the lifelong pursuit of all commercial companies.

These crappy projects aren’t even worth writing a SpringCloud tutorial.

Just do it. It’s like a family barrel.

Let’s take a look at the steps required to implement a SpringCloud.

Implementing a parent

Look professional. Just be a parent. Similarly, if you’re doing gay scaffolding, you can do the same.

Of course, there are also effects. Using parent to control versions and dependencies is a common tool. Parent is often combined with a BOM, a function provided by Maven, to define a set of compatible JAR package versions, defined in the POM tag, dependencyManagement.

You only need to rely on the BOM file to use the required dependent JAR package without specifying the version number. BOM maintainers are responsible for version upgrades and for ensuring compatibility between the VERSIONS of JAR packages defined in the BOM. Something like this:

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Copy the code

BOM is a way to organize many open source software, especially in the case of many components and versions, to provide a unified environment for users.

For us, we need to package commonly used components and maintain them in a BOM file. First, the function should be complete; Second, the version should be compatible. Put it together and you have a microservices framework.

Implement some starter

As anyone who has used Starter knows, you can get rich functionality simply by importing the appropriate JAR package and configuring a few parameters in the YML file. All this magic is done by SpringBoot Starter.

Similar to Java’s SPI mechanism, SpringBoot automatically loads the information configured in SRC /main/resources/ meta-INF/spring.Factories for initialization.

Next, we implement a feature that automatically prints a line of log for methods decorated with Owl annotations.

Join the rely on

pom.xml

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-autoconfigure</artifactId>
    <optional>true</optional>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-aop</artifactId>
    <optional>true</optional>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-configuration-processor</artifactId>
    <optional>true</optional>
</dependency>
Copy the code

Write a note

Owl.java

import java.lang.annotation.*;

@Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface Owl {
    String operationName() default "";
}
Copy the code

Writing automatic configuration

OwlAutoConfiguration.java

@Configuration
@Slf4j
public class OwlAutoConfiguration {
    static final String TAG_COMPONENT = "java";

    @Bean
    public OwlAspect owlTracingAspect() {
        return new OwlAspect();
    }

    @Aspect
    class OwlAspect {
        @Around("@annotation(com.sayhiai.arch.trace.annotation.OwlTrace)")
        public Object owlTraceProcess(ProceedingJoinPoint pjp) throws Throwable {
            final String cls = pjp.getTarget().getClass().getName();
            final String mName = pjp.getSignature().getName();
            log.debug("cls:" + cls + ",method:" + mName);

            returnpjp.proceed(); }}}Copy the code

Load the configuration

src/main/resources/META-INF/spring.factories

org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.sayhiai.core.owl.OwlAutoConfiguration
Copy the code

Next, package your code as a JAR and import it into the project as needed.

Assemble key components

In fact, if you look closely, there are only a few key components of SpringCloud. Since they are components, they can be replaced at will, and the Netflix version does that.

So I think if you really want to be honest with the community, you just need to maintain the components independently. Make it all your own. That’s not what you want.

One component, plus a starter, a perfect and elegant combination, culminating in a sublime and joyous movement, just like Consul.

Without further ado, we’ve covered a lot of functionality around microservices in our article, Not all of it, just a subset of a specific domain. Here, let’s take a quick look at the key parts of SpringCloud.

1. Remote call RPC 2. Registry 3

Remote Calling RPC

SpringCloud is powered by Feign and the Ribbon by default, providing remote invocation requests and parsing, as well as load balancing. To be fair, if you don’t use these two components, it’s going to look a lot less like SpringCloud, so you can’t replace them.

RPC makes a lot of use of dynamic proxies, turning your strings or configurations (because of the ease of network transport) into dynamic interfaces.

You can also write an RPC for integration, and there are many tutorials that teach you how to do this manually.

The dad version incorporates a Dubbo, which is RPC. So as soon as you use this thing, some other key components have to be replaced with the whole set, and components are not called components anymore!

The registry

Another required component of microservices is a service registry that coordinates the mutual discovery of service providers and callers. The default registry for SpringCloud is Eureka.

The dad version uses Nacos. The update to Nacos is still fairly active at the moment, but there’s really no need to integrate it into a Cloud. Nacos is best distributed independently and maintained as a starter. Developers can selectively integrate or substitute for their own company’s environment. The cost of integrating a component is low, far less than cutting out a bunch of smug features.

SpringCloud can also choose From Zookeeper, Consul, and even Etcd to set up a registry. For now, Consul should be the first choice after Eureka announced no more maintenance.

Consul comes with Dashboard and ACL to see most of the information you care about. In order to be able to integrate into our company’s system, you may develop some back-end management functions for more control. This part is easy to develop, just need to make an interface, directly read Consul data through the API.

Integrate your own services

If you are a service provider, whether it is PAAS or SAAS, it can be packaged and sold.

For example, if you provide a CDN, package a XXX-CDN-spring-boot-starter. If you want to sell your search service, package an XXX-search-spring-boot-starter.

The starter name is **-spring-boot-starter, we also want to do so, more professional, like an awesome company produced by the way.

Want to get a few more, show their own products rich; Also want to control quantity, avoid learning cost is too high; To bind their own products, so that once users use, they can not get out of the car, forming the so-called stickiness.

Of course, it’s a little difficult to add the suffix -incubator to the incubator. But if you’re big enough, none of that matters.

Fusing and limiting current

This has been hyped up as a must-have component of microservices, but ask yourself, this feature can be a dead end for small to medium sized applications. But we’ll do it anyway, because it’s a selling point.

The default component of SpringCloud is Hystrix, which provides different ways of multithreading and semaphore control. Unfortunately, Hystrix has also announced that it will no longer maintain it, and the official recommended replacement is Resilience4J.

Fusing current limiting function is actually very simple, colleagues spent a week to build enough components. This part is designed to be simple to use, preferably in real time through background configuration.

The dad version, Sentinel, came with a backend, but it didn’t integrate with the registry, making it neither fish nor fish.

I’m gonna use Sentinel. I’ll integrate it myself. Use your big head.

The gateway

Gateway, which can perform unified degradation, traffic limiting, authentication and authorization, security, etc., is another component of microservices. The default for SpringCloud is Zuul, which is available in versions 1 and 2. SpringCloud can also choose Gateway for Gateway control.

Does your company use a gateway? I wonder. I’ve seen a lot of companies go to round C and D, and it’s still simple Nginx simple routing.

Another language-neutral gateway is Openresty based on Nginx, including the more integrated Kong. But this commercialization trend is obvious, deliberately complicated simple things, stability to be studied, very clever.

I mean, gateways are not necessary, and there is no gateway that works. This is a pot calling the kettle black territory.

other

Other important components of microservices, including log collection, call chains, and continuous integration, are not provided by Spring Clouds. That’s right. It’s all developers. We make our own choices.

Instead of integrating important components, it integrates a bunch of non-essential functionality like OSS, ANS, SMS, MQ, and so on, which is sneaky.

promote

Write the example

You can have nothing but documentation and examples. This and coin circle ICO white paper a reason. You see the concept is very cool, but the real use of few.

To fry the concept, grasp the faucet.

Examples need to be able to run, of course, with a little effort from the user. If the user can’t run, it’s not the product, it’s the user’s ability.

marketing

You don’t have much credibility. You just have to show up at a press conference or share event. Leave the rest to the licking dogs. As long as they act in line with our grand strategy, they’re our people.

Be sure to rub against the hot spot, what fire to rely on what. Since the leader spare manpower to let you do an open source project in the name of the company, it is naturally drunk weng’s intention is not wine. It is unjustifiable not to take some extraordinary measures and make some proud achievements.

If you have the funds, that’s great. Of course, finding a team that could buy Flink for hundreds of millions of dollars was just luck. Now, you only need to spend dozens of dollars, you can buy a soft article, KPI high with bonuses but tens of thousands of, this account will not calculate that or don’t mix.

Just pick up the phone at hand and order.

If your framework doesn’t have any special features, you can use well-known open source software, or other good software in your company, for mutual benefit. It doesn’t matter if it’s immature, it’s not like you’re using an open source version. Mud puddle to others, fragrance to their own. It’s an adult world. There’s no need to be so reserved.

#End

Spring is Spring, and Cloud is Cloud.

In terms of verbs, Spring means Spring, and Cloud means rising into the clouds. Overlooking the earth, what a wonderful view, I can not help but tremble.

It’s just, spring is all bullshit.