设为首页 加入收藏

TOP

搭建一个dubbo+zookeeper平台(三)
2019-09-17 19:06:22 】 浏览:198
Tags:搭建 一个 dubbo zookeeper 平台
bsp;3)registry向指定注册中心注册,在多个注册中心时使用,值为<dubbo:registry>的id属性,多个注册中心ID用逗号分隔,如果不想将该服务注册到任何registry,可将值设为N/A

     4)register 默认true ,该协议的服务是否注册到注册中心。

(5)启动项目,然后我们在Dubbo管理页面上显示,已经暴露的服务,但显示还没有消费者,因为我们还没实现消费者服务,如图所示:

  

   第二:我们在开发服务消费者,就是调用服务,我们在新建一个新的消费者项目结构如图所示:

       

   (1)test-maven-server-console的pom.xml引入Dubbo和Zookeeper的jar包、test-maven-api的jar包,因为引入test-maven-api的jar包,我们在项目中调用像在本地调用一样。代码如下:

<dependency>  
    <groupId>cn.test</groupId>  
    <artifactId>test-maven-api</artifactId>  
    <version>0.0.1-SNAPSHOT</version>  
</dependency>  
  
   <dependency>  
         <groupId>com.alibaba</groupId>  
         <artifactId>dubbo</artifactId>  
         <version>2.5.3</version>  
     </dependency>  
       
      <dependency>  
         <groupId>org.apache.zookeeper</groupId>  
<artifactId>zookeeper</artifactId>  
<version>3.4.6</version>  
     </dependency>  
  
   <dependency>  
     <groupId>com.github.sgroschupf</groupId>  
<artifactId>zkclient</artifactId>  
<version>0.1</version>  
   </dependency>  
 

  (2)test-maven-server-console项目的具体实现,代码如下:

@Controller  
public class IndexController {  
      
    @Autowired  
    private TestRegistryService testRegistryService;  
      
    @RequestMapping("/hello")  
    public String index(Model model){  
         String name=testRegistryService.hello("zz");  
         System.out.println("xx=="+name);  
        return "";  
    }  
  
}  

 

  (3)我们要引用的地址,代码如下:
   

<?xml version="1.0" encoding="UTF-8"?>  
<beans xmlns="http://www.springframework.org/schema/beans"  
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   
    xmlns:jee="http://www.springframework.org/schema/jee"  
    xmlns:tx="http://www.springframework.org/schema/tx"  
    <span style="background-color: rgb(255, 255, 255);"><span style="color:#990000;">xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"</span></span>  
    xmlns:context="http://www.springframework.org/schema/context"  
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd  
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd  
    http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.1.xsd  
    <span style="color:#990000;">http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd</span>  
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd"  
    default-lazy-init="false" >  
  
   <dubbo:application name="dubbo_consumer"></dubbo:application>  
   <!-- 使用zookeeper注册中心暴露服务地址 -->    
   <dubbo:registry address="zook
首页 上一页 1 2 3 4 下一页 尾页 3/4/4
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇消息队列二:关于消息队列 下一篇分布式消息队列集群组件设计

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目