Distributed application

  • In the distributed system, the combination of ZooKeeper and Dubbo is commonly used
  • SpringBoot recommends using the full stack Spring,SpringBoot+SpringCloud

    Zookeeper+Dubbo

    Zookeeper

  • ZooKeeper :(registry)

    • Is a distributed, open source distributed application coordination service
    • Software that provides consistent services for distributed applications:

      • Configuration maintenance
      • Domain name service
      • Distributed synchronization
      • Set of services

        Dubbo

  • Dubbo is an open source distributed framework of Alibaba

    • The most important feature is that the architecture is structured in a layered way, using this way to decouple the layers (with maximum loose coupling).
    • From a service model perspective,Dubbo adopts a simple model: either the provider provides the service, or the consumer consumes the service
    • Two roles, Provider and Consumer, are abstracted

      Provider: 1. Introduces the dubbo-spring-boot-starter dependency 2. Introduce ZooKeeper's client tool, ZkClient Dependency 3. Configure the properties of DuBoo in Application.properties: dubbo.application.name=provider-ticket dubbo.regestry.address=zookeeper://localhost:2181 dubbo.scan.base-packages=com.web.ticket.service 4. On the implementation class @ Service annotations (com. Alibaba. Dubbo. Config. The annotation), will be launched out. And add the class to the container @Component Consumer: 1. Introduce the dubbo-spring-boot-starter dependency 2. Introduce ZooKeeper's client tool, ZkClient Dependency 3. Configure the properties of DuBoo in Application.properties: dubbo.application.name=provider-ticket dubbo.regestry.address=zookeeper://localhost:2181 4. Create and the Provider is exactly the same interface directory structure: com. Web. Ticket. Service. TicketService 5. Create a Service class and introduce TicketService in the Service class with the @Reference annotation

      SpringBoot+SpringCloud

      SpringCloud

  • SpringCloud:

    • SpringCloud is a distributed holistic solution framework
    • SpringCloud provides tools to quickly build in distributed systems:

      • Configuration management
      • Service discovery
      • fusing
      • routing
      • The micro broker
      • Control bus
      • One-time token
      • Global lock
      • Leader election
      • Distributed session
      • State of the cluster
    • SpringCloud can quickly start services or build applications, and at the same time can quickly connect with cloud platform resources
  • SpringCloud Distributed Development Component:

    • Service discovery: Eureka
    • Client Load Balancing: Ribbon
    • Circuit breaker: Hystrix
    • Service gateway: Zuul
    • Distributed configuration: SpringCloud Config

      Cloud Discovery-Eureka Server 2 Configuration file :server.port=8761 eureka.instance.hostname=eureka-server eureka.client.registry-with-eureka=false(do not register yourself with eureka) Eureka.client.fetch-registry =false(do not get service registration information from eureka) eureka.client.service-url.defaultZone=http://localhost:8761/eureka/ 3. Mark @EnableEurekaserver annotation on the main registry class to start the Eureka registration service Provider(the same application can register more than one in the registry) 1. Create provider CloudDiscovery-Eureka Discovery 2. Create a service method and create the Controller layer to communicate with HTTP service requests (SpringCloud integrated microservices communicate with lightweight HTTP) 3. Configuration file :server.port=8001 spring.application.name=provide-ticket eureka.instance.prefer-ip-address=true(use the service's IP address when registering the service) eureka.instance.eureka.client.service-url.defaultZone=http://localhost:8761/eureka/ 4. Annotation @EnableEurekAclient on the main class registers the Service Provider service in the registry Consumer 1. Create consumer CloudDiscovery-Eureka Discovery 2. Create the Controller layer to communicate through HTTP service requests 3. Configuration file :spring.application.name=consumer-user server-port=8200 eureka.instance.prefer-ip-address=true(use IP address of service when registering service) eureka.instance.eureka.client.service-url.defaultZone=http://localhost:8761/eureka/ 4. Annotate the main class with @EnableEurekAclient (@EnableDiscoveryClient) annotation to enable discovery service 5. Create RestTemplate and annotate @Bean add method to create HTTP service for communication, annotate @LoadBalanced annotation to enable load balancing mechanism