Home > Java > javaTutorial > body text

How to integrate Dubbo zookeeper in SpringBoot

WBOY
Release: 2023-05-17 14:16:06
forward
1446 people have browsed it

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);
  }

}
Copy after login
controller

@RestController
public class ManagerController {
  
  @Reference
  ManagerService managerService;

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

}
Copy after login
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();
}
Copy after login
application.properties

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

Startup class

@SpringBootApplication
public class ProviderManagerApplication {

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

}
Copy after login
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 !!!";
  }
}
Copy after login
application.properties

dubbo.application.name=provider-manager
dubbo.registry.address=zookeeper://192.168.0.106:2181
dubbo.scan.base-packages=com.hourui
Copy after login
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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!