资讯专栏INFORMATION COLUMN

dubbo zookeeper spring整合之helloworld

sugarmo / 3066人阅读

摘要:是目前非常流行的分布式服务技术,很多公司都在用。空闲之余,搭了个,分享给大家。本文下载下载是服务的注册中心,下载后进入到安装目录。双击即可启动注册中心服务。

dubbo是目前非常流行的分布式服务技术,很多公司都在用。空闲之余,搭了个helloworld,分享给大家。
本文demo下载
1.下载 zookeeper
zookeeper是服务的注册中心,下载后进入到安装目录G:bakCenterzookeeper-3.3.6bin。
双击zkServer.cmd即可启动注册中心服务。
zkServer.sh【Linux】或zkServer.cmd【Windows】
Zookeeper的配置文件在 conf 目录下,这个目录下有 zoo_sample.cfg 和 log4j.properties,需要将zoo_sample.cfg 改名为 zoo.cfg,Zookeeper在启动时会找这个文件作为默认配置文件

# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial 
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between 
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
dataDir=/tmp/zookeeper
# the port at which the clients will connect
clientPort=2181

配置说明可以参考这里
2.服务提供者
定义服务接口:

package com.hy.service;
public interface DemoService {
    String sayHello(String name);
}

实现服务接口:

package com.hy.service.impl;

import com.hy.service.DemoService;
public class DemoServiceImpl implements DemoService {
    public String sayHello(String name) {
        System.out.println("init : " + name);
        return "hello " + name;
    }
}

在Spring配置中注册服务。



    
    
    
    
    
     
    

    
    

执行服务提供方主方法启用服务:

package main;

import java.io.IOException;

import org.springframework.context.support.ClassPathXmlApplicationContext;

public class ProviderMain {

    public static void main(String[] args) throws IOException {

        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( new String[] { "applicationProvider.xml" });
        context.start();

        System.out.println("服务注册成功..");
        System.in.read();
        context.close();
    }
}

3.dubbo监控中心查看服务下载地址
下载后,将dubbo-admin-2.5.4-SNAPSHOT.war包放置tomcat服务器的webapps目录,启动tomcat服务器,打开下面链接即可查看可用的服务及其状态 http://localhost:8080/dubbo-a...
用户名和密码配置在C:Program FilesApache Software FoundationTomcat 7.0webappsdubbo-admin-2.5.4-SNAPSHOTWEB-INFdubbo.properties文件中

dubbo.registry.address=zookeeper://127.0.0.1:2181
dubbo.admin.root.password=root
dubbo.admin.guest.password=guest

4.服务消费者
通过Spring配置订阅服务提供方暴露的服务



    

    

    
    
 

执行服务消费方主方法启用服务:

package main;

import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.hy.service.DemoService;

public class ConsumerMain {
    public static void main(String[] args) {
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
                new String[] { "applicationConsumer.xml" });
        context.start();
        DemoService service = (DemoService) context.getBean("demoService");
        System.out.println(service.sayHello("world"));
        context.close();
    }
}

在控制台即可见服务提供方方法的调用结果。

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/67115.html

相关文章

  • Spring Cloud与Dubbo的完美融合手「Spring Cloud Alibaba」

    摘要:构建服务接口创建一个简单的项目,并在下面定义一个抽象接口,比如构建服务接口提供方第一步创建一个项目,在中引入第一步中构建的包以及对和的依赖,比如第一步中构建的包这里需要注意两点必须包含包,不然启动会报错。 很早以前,在刚开始搞Spring Cloud基础教程的时候,写过这样一篇文章:《微服务架构的基础框架选择:Spring Cloud还是Dubbo?》,可能不少读者也都看过。之后也就一...

    wpw 评论0 收藏0
  • Dubbo Cloud Native 实践与思考

    摘要:可简单地认为它是的扩展,负载均衡自然成为不可或缺的特性。类似的特性在项目也有体现,它是另一种高性能代理的方案,提供服务发现健康和负载均衡。 Dubbo Cloud Native 实践与思考 分享简介 Cloud Native 应用架构随着云技术的发展受到业界特别重视和关注,尤其是 CNCF(Cloud Native Computing Foundation)项目蓬勃发展之际。Dubbo...

    邱勇 评论0 收藏0
  • 超详细,新手都能看懂 !使用SpringBoot+Dubbo 搭建一个简单的分布式服务

    Github 地址:https://github.com/Snailclimb/springboot-integration-examples ,欢迎各位 Star。 目录: 使用 SpringBoot+Dubbo 搭建一个简单分布式服务 实战之前,先来看几个重要的概念 什么是分布式? 什么是 Duboo? Dubbo 架构 什么是 RPC? 为什么要用 Dubbo? 开始实战 1 ...

    chengtao1633 评论0 收藏0
  • Dubbo Cloud Native 路的实践与思考

    摘要:可简单地认为它是的扩展,负载均衡自然成为不可或缺的特性。是基于开发的服务代理组件,在使用场景中,它与和整合,打造具备服务动态更新和负载均衡能力的服务网关。类似的特性在项目也有体现,它是另一种高性能代理的方案,提供服务发现健康和负载均衡。 摘要: Cloud Native 应用架构随着云技术的发展受到业界特别重视和关注,尤其是 CNCF(Cloud Native Computing Fo...

    niceforbear 评论0 收藏0

发表评论

0条评论

最新活动
阅读需要支付1元查看
<