一.consumer搭建(可以web/jar)

1.新建Maven项目,groupId:com.dubbo.consumer.demo artifactId:demo projectName:dubboo-consumer-demo

2.新建class :com.dubbo.consumer.demo.DemoAction

package com.dubbo.consumer.demo;

import java.text.SimpleDateFormat;
import java.util.Date;
import com.dubbo.api.demo.*;
/**
* Created by Administrator on 17-1-7.
*/
public class DemoAction {
private static DemoService demoService;
public void setDemoService(DemoService demoService) {
this.demoService = demoService;
} public void start() throws Exception {
for (int i = 0; i < Integer.MAX_VALUE; i ++) {
try {
String hello = demoService.sayHello("world" + i);
System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] " + hello);
} catch (Exception e) {
e.printStackTrace();
}
Thread.sleep(2000);
}
}
}

3.添加配置文件spring-dubbo-consumer.xml

<?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:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<dubbo:application name="dubbo-consumer-demo" ></dubbo:application>
<dubbo:registry address="zookeeper://127.0.0.1:2181" protocol="zookeeper"></dubbo:registry>
<dubbo:reference id="demoService" interface="com.dubbo.api.demo.DemoService" ></dubbo:reference> </beans>

4.修改maven配置文件pom.xml,添加spring、dubbo、dubbo-api

<dependencies>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
<version>2.4.10</version>
</dependency>
<dependency>
<groupId>com.github.sgroschupf</groupId>
<artifactId>zkclient</artifactId>
<version>0.1</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.2.16.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.2.16.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>3.2.16.RELEASE</version>
</dependency>
<dependency>
<groupId>com.dubbo.api.demo</groupId>
<artifactId>dubbo-interface</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>

5.添加消费者Class DemoConsumer

package Consumer;/*
* Copyright 1999-2011 Alibaba Group.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/ import com.dubbo.api.demo.*;
import org.springframework.context.support.ClassPathXmlApplicationContext; public class DemoConsumer { public static void main(String[] args) { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("META-INFO/spring-dubbo-consumer.xml"); ctx.start(); DemoService demoService = (DemoService) ctx.getBean("demoService"); String hello = demoService.sayHello("world" + 1);
System.out.println("[" + hello); ctx.close();
}
}

二、总结

1.web或jar包形式发布消费者都可以

2.工程中涉及主要配置

A.consumer.xml 中引入API(interface)

B.pom.xml中引入API(Interface)jar包

C.接口实现在provider中完成,本地引入接口定义jar即可

D.java中import api package

												

【dubbo】消费者Consumer搭建的更多相关文章

  1. SpringBoot与Dubbo整合-项目搭建

    本章节建立生产者和消费者来演示dubbo的demo 生产者:springboot-dubbo-provider 和 消费者:springboot-dubbo-consumer 工程配置详解 Apach ...

  2. zookeeper和dubbo安装与搭建

    Zookeeper+Dubbo安装与搭建 (原创:黑小子-余) 本文有借鉴:https://www.cnblogs.com/UncleYong/p/10737119.html (一)zookeeper ...

  3. 【2020-03-21】Dubbo本地环境搭建-实现服务注册和消费

    前言 本周主题:加班工作.本周内忙于CRUD不能自拔,基本每天都是九点半下班,下周上线,明天还要加班推进进度.今天是休息日,于是重拾起了dubbo,打算近期深入了解一下其使用和原理.之所以说是重拾,是 ...

  4. 【转载】Maven+druid+MyBatis+Spring+Oracle+Dubbo开发环境搭建

    原地址:http://blog.csdn.net/wp1603710463/article/details/48247817#t16 Maven+druid+MyBatis+spring+Oracle ...

  5. Dubbo服务的搭建

    dubbo框架主要作用是基于RPC的远程调用服务管理,但是注册中心是用的zookeeper,搭建dubbo,首先要安装zookeeper,配置zookeeper... 实现功能如图所示:(存在2个系统 ...

  6. zookeeper和dubbo安装与搭建(2)

    Zookeeper+Dubbo安装与搭建(2) (原创:黑小子-余) 一.环境配置:zookeeper3.6.0 + dubbo3.5.4 + maven3.6.1 + jdk1.8 + tomcat ...

  7. RPC服务框架dubbo(六):Consumer搭建过程

    1.在pom.xml中除了ssm的依赖添加dubbo相关3个依赖(接口,dubbo.jar,zkClient) 2.web.xml中修改<init-value>applicationCon ...

  8. dubbo服务简单搭建

    一.初识dubbo: 架构图: Provider: 暴露服务的服务提供方. Consumer: 调用远程服务的服务消费方. Registry: 服务注册与发现的注册中心. Monitor: 统计服务的 ...

  9. Dubbo+zookeeper+SpringMVC搭建最简单的分布式项目

    Dubbo 是什么 一款分布式服务框架 高性能和透明化的RPC远程服务调用方案 SOA服务治理方案 Dubbo 架构流程图 Provider:服务提供方 Consumer:服务消费者 Registry ...

随机推荐

  1. 理解View与Model分离

    说实话MV*架构中,Model与View分离已经听人谈了好久,但是以前始终没太弄懂什么意思,最近终于稍微懂了一些,虽然不一定很对,暂且先记录下来. 谈Model与View分离,首先要弄懂页面在前端渲染 ...

  2. C++对象模型

    1.类布局 1.1简单类对象的内存布局 class A { public: void f(); private: int i; char c; static int s; }; 简单对象的内存布局:非 ...

  3. B. Shaass and Bookshelf DP

    http://codeforces.com/contest/294/problem/B 据说是贪心,我用了一个复杂度是2e8的dp水过去了. 其实这题就是给你n个数,每个数有两个权值,分成两组,使得第 ...

  4. python random

    import randoma = random.randrange(0,5)print(a)本来很正常的一段代码,用pycharm就报错,控制台就可以运行,原来random 和自带的random 同名 ...

  5. Git学习(四)——分支管理

    一.创建与合并分支 1.创建分支 一开始的时候,master分支是一条线,Git用master指向最新的提交,再用HEAD指向master,就能确定当前分支,以及当前分支的提交点.每次提交 ,mast ...

  6. 同时打开两个excel工作窗口

    先打开你想要同时打开的两个excel文件,有两个方法可以同时打开两个窗口:首先选取任意一个文件,1. 点击“窗口”菜单==>"重排窗口"==>选择你想同时打开的样式== ...

  7. wcf 由 http 更改为 https 返回404,没有终结点在侦听可以接受消息的

    首先wcf项目在使用http时是没问题的. WCF有http更改为https之后,返回 没有终结点在侦听可以接受消息 需要修改wcf服务端及客户端 服务端更改代码 <binding maxRec ...

  8. mongkeyrunner实现循环随机输入值的方法

    from com.android.monkeyrunner import MonkeyRunner,MonkeyDevice,MonkeyImagedevice= MonkeyRunner.waitF ...

  9. requirejs+cdn

    当requirejs加上cdn.cdn固然可以在requirejs里面配置.但是在a.html里面却不能通过给自己引用的requirejs文件添加版本戳. 最重要的是requirejs不能引进css当 ...

  10. ExtJs 获取Dom对象

    对象指页面上的某一部分,如:Input等.我觉得在EXT JS中会有三类基本对象,htmlelement , EXT.Element和CompositeElement .分别解释一下: htmlele ...