Distributed application

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

Zookeeper+Dubbo

Zookeeper

  • Zookeeper:(Registry)
    • Is a distributed, open source distributed application coordination service
    • For distributed applicationsConsistency serviceThe software:
      • Configuration maintenance
      • Domain name service
      • Distributed synchronization
      • Set of services

Dubbo

  • DubboIs Alibaba open source distributed framework
    • The most important feature is that the architecture is structured in a hierarchical way, using this way to decouple the layers (as loosely coupled as possible)
    • From a service model perspective,Dubbo follows a simple model: either the provider provides the service, or the consumer consumes the service
    • The roles of Provider and Consumer are abstracted
Use Dubbo: Provider: 1. Introduce dubbo-spring-boot-starter dependency 2. Introduce the ZooKeeper client tool zkClient dependency 3. Configure the duboo properties 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 the ZooKeeper client tool zkClient dependency 3. Configure the duboo properties 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 with the @Reference annotation in the Service classCopy the code

SpringBoot+SpringCloud

SpringCloud

  • SpringCloud:
    • SpringCloud is a distributed overall solution framework
    • SpringCloud is provided in a distributed systemA quick build tool:
      • 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 connect with cloud platform resources
  • SpringCloud distributed development components:
    • Service discovery: Eureka
    • Client load balancing: Ribbon
    • Circuit breaker: Hystrix
    • Service gateway: Zuul
    • Distributed configuration: SpringCloud Config
Eureka-server: 1. Create the Eureka registration center Cloud Discovery-Eureka Server 2. Hostname =eureka-server eureka.client.registry-with-eureka=false(do not register yourself to eureka) Eureka.client. fetch- Registry =false(do not fetch service registration information from Eureka) eureka.client.service-url.defaultZone=http://localhost:8761/eureka/ 3. Note the @enableEurekaserver annotation on the main class of the registry to start the Eureka registration service Provider(one application can be registered in multiple registries) 1. Create the provider CloudDiscovery-Eureka Discovery 2. Create the service method and create the controller layer to communicate over Http service requests (SpringCloud integrated microservices are used for lightweight Http service communication) 3. Configuration file :server.port=8001 spring.application.name=provide-ticket eureka.instance.prefer-ip-address=true(use the IP address of the service when registering the service) eureka.instance.eureka.client.service-url.defaultZone=http://localhost:8761/eureka/ 4. The @enableeurekaclient annotation on the main class registers the Provider service with the Consumer 1 registry. Create consumer CloudDiscovery-Eureka Discovery 2. Create the Controller layer to communicate over Http service requests 3. Spring.application. name=consumer-user server-port=8200 eureka.instance.prefer-ip-address=true(use the IP address of the service when you register it) eureka.instance.eureka.client.service-url.defaultZone=http://localhost:8761/eureka/ 4. Annotate @enableEurekaclient (@enableDiscoveryClient) in the main class. Enable the discovery function. 5. Create the RestTemplate and annotate the @Bean method to create Http services for communication, and annotate the @loadBalanced annotation to enable load balancingCopy the code