Spring Boot + Dubbo + Dubbo admin UI a complete set of distributed solutions

The native environment

The JDK: 1.8.0 comes with _161

Spring the Boot: 2.1.3. RELEASE

Zookeeper: 3.4.11

Org. Apache. Dubbo: 2.7.0

Node: v8.4.0

Npm: 5.3.0

Begin to build

Dubbo-Api

Provided for external use

Create a Dubo-API for consumer and provider use

Contains only one HelloService

public interface HelloService {
    String sayHello(String name);
}
Copy the code

Dubbo-Provider

Pom depends on

< properties > < Java version > 1.8 < / Java version > < spring - the boot. Version > 2.1.3. RELEASE < / spring - the boot. Version > < dubo. version>2.7.0</ dubo. version> </properties> <dependencyManagement> <dependencies> <! -- Spring Boot --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-dependencies</artifactId> <version>${spring-boot.version}</version> <type>pom</type> <scope>import</scope> </dependency> <! -- Apache Dubbo --> <dependency> <groupId>org.apache.dubbo</groupId> <artifactId>dubbo-dependencies-bom</artifactId> <version>${dubbo.version}</version> <type>pom</type> <scope>import</scope> </dependency> <dependency> <groupId>org.apache.dubbo</groupId> <artifactId>dubbo</artifactId> <version>${dubbo.version}</version> <exclusions> <exclusion> <groupId>org.springframework</groupId> <artifactId>spring</artifactId> </exclusion> <exclusion> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> </exclusion> <exclusion> <groupId>log4j</groupId> <artifactId>log4j</artifactId> </exclusion> </exclusions> </dependency> </dependencies> </dependencyManagement> <dependencies> <! -- Dubbo Spring Boot Starter --> <dependency> <groupId>org.apache.dubbo</groupId> < artifactId > dubbo - spring - the boot - starter < / artifactId > < version > 2.7.0 < / version > < / dependency > < the dependency > <groupId>org.apache.dubbo</groupId> <artifactId>dubbo</artifactId> </dependency> <dependency> <groupId>org.apache.curator</groupId> <artifactId>curator-framework</artifactId> </dependency> <dependency> <groupId>org.apache.curator</groupId> <artifactId>curator-recipes</artifactId> </dependency> <dependency> <groupId>org.apache.zookeeper</groupId> <artifactId>zookeeper</artifactId> <exclusions> <exclusion> <artifactId>log4j</artifactId> <groupId>log4j</groupId> </exclusion> <exclusion> <artifactId>slf4j-log4j12</artifactId> <groupId>org.slf4j</groupId> </exclusion> </exclusions> </dependency> <dependency> <groupId>com.101tec</groupId> <artifactId>zkclient</artifactId> </dependency> </dependencies>Copy the code

All of these dependencies are needed, and the next step is to implement the Service method provided by Dubo-API

import com.skrein.dubbo.api.service.HelloService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

// Specify the version of dubo-Provider
@Service(version = "${demo.service.version}")
@Component
public class HelloServiceImpl implements HelloService {

    @Value("${server.port}")
    String port;

    @Value("${spring.application.name}")
    String appName;

    @Override
    public String sayHello(String name) {
        return appName + ":" + port + "\n hello "+ name; }}Copy the code

@service: This annotation is provided by org.apache.dubbo

BootApplication then sets @enabledubbo to complete the simplest Provider

@SpringBootApplication
@EnableDubbo
public class BootApplication {

    public static void main(String[] args) { SpringApplication.run(BootApplication.class, args); }}Copy the code

Configuration files are configured through Zookeeper as our registry:

application.yml

dubbo:
  registry:
    address: Zookeeper: / / 127.0.0.1:2181 Registry address
  protocol:
    port: - 1 We will have two providers via different ports later, so use random ports
    name: dubbo
  metadata-report:
    address: Zookeeper: / / 127.0.0.1:2181 # dubo-admin requires this configuration to report meta information
demo:
  service:
    version: 0.01.

spring:
  application:
    name: dubbo-provider
  main:
    allow-bean-definition-overriding: true No setting will conflict with Spring Boot
Copy the code

Then we start from the command line

Jar --server.port=9000 $java-jar target/ dubo-provider-0.0.1. jar --server.port=9000Copy the code

Dubbo-Consumer

Pom is configured as a Web service like dubbo-provider and dubbo-consumer

@RestController
public class HelloController {

    @Reference(version = "${demo.service.version}")
    private HelloService helloService;

    @GetMapping("/hello/{name}")
    public String hello(@PathVariable(name = "name") String name) {
        returnhelloService.sayHello(name); }}Copy the code

Start the class with @enabledubbo

application.yml:

dubbo:
  registry:
    address: Zookeeper: / / 127.0.0.1:2181 # Zookeeper registration center address
  protocol:
    port: - 1 # random port
    name: dubbo # dubbo Protocol name


spring:
  main:
    allow-bean-definition-overriding: true No setting will conflict with Spring Boot
  application:
    name: dubbo-consumer
demo:
  service:
    version: 0.01. The consumer version is consistent with the producer version
Copy the code

Pring.main. allow-bean-education-Tpo41 =true: Spring Boot 2.7.0 Environment Beans Conflict in Spring Boot

Command line startup:

$Java - jar target/dubbo - consumer - 0.0.1. JarCopy the code

After startup:

Configuration Dubbo – admin Dubbo – admin – the UI

dubbo-admin-server

The official website address is dubb-admin-ui

Download the project and open it with IDEA

Start dubbo-admin-server. Note that the port number may conflict with dubbo-consumer

Dubo-admin-server: Change the port number to 8888

–server.port=8888

And then just boot it up.

dubbo-admin-ui

The front-end uses Vue, so you need a Node environment

I recommend one node management I often use: NVM

NVM – Windows: github.com/coreybutler…

installed

$NVM install 8.4.0 $NVM use 8.4.0Copy the code

NVM node installation is as follows:

Then switch to the dubo-admin-ui directory:

Perform NPM install

$ npm install
Copy the code

My machine has executed, not executed waiting for installation:

As you will recall, the admin-server port number is 8888, so we need to change the dubo-admin-UI port number to connect to the server as well (default is 8080).

Modify the config/index. Js

Then start dubo-admin-ui:

$ cnpm run dev
Copy the code

Go to http://localhost:8081

You can see that our service has been monitored by Admin.

Click the details, and you can see that our two providers are also under monitoring:


The code has been uploaded to my Github, welcome star, will continue to update, bring you detailed examples of distributed, high concurrency and so on.