Home  >  Article  >  Java  >  How to integrate Dubbo zookeeper in SpringBoot

How to integrate Dubbo zookeeper in SpringBoot

WBOY
WBOYforward
2023-05-17 14:16:061402browse

docker pull zookeeper

docker run --name zk01 -p 2181:2181 --restart always -d 2e30cac00aca

SpringBoot中如何整合Dubbo zookeeper

indicates that zookeeper has been started successfully

Zookeeper and Dubbo• ZooKeeperZooKeeper is a distributed, open source distributed application coordination service. It is a software that provides consistent services for distributed applications. The functions provided include: configuration maintenance, domain name services, distributed synchronization, group services, etc.

DubboDubbo is Alibaba's open source distributed service framework. Its biggest feature is that it is structured in a layered manner. This method can decouple (or maximize loose coupling) between each layer.

From the perspective of the service model, Dubbo adopts a very simple model, either the provider provides services, or the consumer consumes services, so based on this, the service provider can be abstracted ( Provider) and service consumer (Consumer) two roles.

SpringBoot中如何整合Dubbo zookeeper

SpringBoot中如何整合Dubbo zookeeper

##Client (consumer) configuration:

Startup class

@SpringBootApplication
public class ConsumerManagerApplication {

  public static void main(String[] args) {
   SpringApplication.run(ConsumerManagerApplication.class, args);
  }

}
controller

@RestController
public class ManagerController {
  
  @Reference
  ManagerService managerService;

  @RequestMapping("/hello")
  public String hello() {
    return managerService.hello();
  }

}
service (it only needs to be consistent with the interface of the service class, and the package name must be consistent)

public interface ManagerService {
  public String hello();
}
application.properties

dubbo.application.name=consumer-manager
dubbo.registry.address=zookeeper://192.168.0.106:2181
server.port=8081
Server (provider) configuration:

Startup class

@SpringBootApplication
public class ProviderManagerApplication {

  public static void main(String[] args) {
   SpringApplication.run(ProviderManagerApplication.class, args);
  }

}
Service interface and implementation class

public interface ManagerService {
  public String hello();
}

@Service
public class ManagerServiceImpl implements ManagerService {
  
  @Override
  public String hello() {
    System.out.println("客户端请求进来了!");
    return "xixi success !!!";
  }
}
application.properties

dubbo.application.name=provider-manager
dubbo.registry.address=zookeeper://192.168.0.106:2181
dubbo.scan.base-packages=com.hourui
Browser access:

SpringBoot中如何整合Dubbo zookeeper

The above is the detailed content of How to integrate Dubbo zookeeper in SpringBoot. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete