一.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

转载于:https://www.cnblogs.com/grape1211/p/6259270.html

【dubbo】消费者Consumer搭建相关推荐

  1. Dubbo(七)使用SpringBoot搭建dubbo消费者工程

    本章将创建一个dubbo 消费者工程并实现远程调用消费者示例.环境:springboot + dubbo + zookeeper, 工程目录如下: 主要步骤: 创建maven工程添加pom依赖 创建S ...

  2. php dubbo 接口测试工具,dubbo服务自动化测试搭建

    java实现dubbo的消费者服务编写:ruby实现消费者服务的接口测试:通过消费者间接测试dubbo服务接口的逻辑 内容包括:dubbo服务本地调用环境搭建,dubbo服务启动,消费者部署,脚本编写 ...

  3. springboot+dubbo+zookeeper详细搭建

    springboot+dubbo+zookeeper框架搭建 环境搭建 启动zookeeper 启动dubbo-addmin-2.6.0监控平台(可省) 服务提供者 引包 配置参数 启动类 demo ...

  4. 【Dubbo】入门搭建

    文章目录 快速入门 配置Nacos注册中心 Dubbo-Spring-Cloud 概述 快速使用 dubbo-cloud-provider-api 依赖含义 参考链接 快速入门 场景:提供provid ...

  5. dubbo消费者与提供者之间的tcp长连接

    摘要 dubbo消费者同提供者之间的tcp连接是长连接形式,连接由消费方建立随机端口主动向提供者的dubbo端口发起连接请求,一旦连接建立,除非服务停止.网络异常,否则双方不会主动关闭tcp连接.也就 ...

  6. dubbo(provider,consumer)点到点直连配置

    2019独角兽企业重金招聘Python工程师标准>>> dubbo(provider,consumer)点到点直连配置 博客分类: dubbo 1.服务端接口配置(providr样例 ...

  7. springboot+dubbo+zookeeper+maven搭建微服务详细教程

    前言: 本文将使用springboot+dubbo+zookeeper+maven搭建一套微服务. 需要提前在本地配置的环境: maven环境 zookeeper环境(在我本地zookeeper在21 ...

  8. Kafka学习(十)--Kafka消费者Consumer消费消息配置实战

    一. Kafka消费者Consumer消费消息配置实战 配置: public static Properties getProperties() {Properties props = new Pro ...

  9. dubbo消费者请求不到生产者

    com.alibaba.dubbo.rpc.RpcException: Invoke remote method timeout. method: 将dubbo服务器.dubbo提供者.dubbo消费 ...

最新文章

  1. 'ascii' codec can't decode byte 0xe6 in position 0: ordinal not in range(128)
  2. hdfs/hbase 程序利用Kerberos认证超过ticket_lifetime期限后异常
  3. java接口测试工具_接口测试基础了解篇
  4. docker部署项目 入门版
  5. 【C#】三维立体验证码 (3DCaptcha)
  6. 独家专访 | 红布林(Plum​)庞博:万亿元二手时尚交易蓝海的生存法则
  7. powershell自动化操作AD域、Exchange邮箱系列(4)—批量导入邮箱/域账号(文件)
  8. ajax请求会阻塞dom,Jquery ajax 同步阻塞引起的UI线程阻塞问题_jquery
  9. Java中的【锁】事 - 极客大学架构师训练营 架构师 Albert 分享
  10. sql填充空值_如何在SQL中使用先前的非空值填充稀疏数据
  11. 免费申请ssl证书并部署
  12. 实现用户行为监测之webfunny
  13. PC发卡机器人 v1.0
  14. 87.3 laravel中常见问题以及解决方案
  15. 解决MacBook Pro Touch ID失灵不起作用的方法
  16. JavaScript通过键盘方向键控制盒子移动
  17. 怎样传文件到虚拟服务器,Vmware虚拟机教程之本机如何传文件到VMware 中
  18. 月均数据_【分析案例】python分析医院销售数据
  19. 关于Go语言的发展前景
  20. ElasticSearch学习总结(一)

热门文章

  1. vue+element实现树状表格的增删改查;使用el-table树形数据与懒加载实现树状表格增删改查
  2. 前端vscode插件合集
  3. Taro+react开发(83):taro路由配置
  4. 前端学习(3073):vue+element今日头条管理-删除文章失败(配合axios使用)
  5. 前端学习(3036):vue+element今日头条管理-复习
  6. 工作374-前端margin:0 auto为什么会失效
  7. [css] 说下background-color:transparent和opacity:0的区别是什么?
  8. 工作177:时间戳转换
  9. 工作160:总结VUE几种页面刷新方法
  10. 前端学习(2511):组件注册