【dubbo】消费者Consumer搭建
一.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搭建的更多相关文章
- SpringBoot与Dubbo整合-项目搭建
本章节建立生产者和消费者来演示dubbo的demo 生产者:springboot-dubbo-provider 和 消费者:springboot-dubbo-consumer 工程配置详解 Apach ...
- zookeeper和dubbo安装与搭建
Zookeeper+Dubbo安装与搭建 (原创:黑小子-余) 本文有借鉴:https://www.cnblogs.com/UncleYong/p/10737119.html (一)zookeeper ...
- 【2020-03-21】Dubbo本地环境搭建-实现服务注册和消费
前言 本周主题:加班工作.本周内忙于CRUD不能自拔,基本每天都是九点半下班,下周上线,明天还要加班推进进度.今天是休息日,于是重拾起了dubbo,打算近期深入了解一下其使用和原理.之所以说是重拾,是 ...
- 【转载】Maven+druid+MyBatis+Spring+Oracle+Dubbo开发环境搭建
原地址:http://blog.csdn.net/wp1603710463/article/details/48247817#t16 Maven+druid+MyBatis+spring+Oracle ...
- Dubbo服务的搭建
dubbo框架主要作用是基于RPC的远程调用服务管理,但是注册中心是用的zookeeper,搭建dubbo,首先要安装zookeeper,配置zookeeper... 实现功能如图所示:(存在2个系统 ...
- zookeeper和dubbo安装与搭建(2)
Zookeeper+Dubbo安装与搭建(2) (原创:黑小子-余) 一.环境配置:zookeeper3.6.0 + dubbo3.5.4 + maven3.6.1 + jdk1.8 + tomcat ...
- RPC服务框架dubbo(六):Consumer搭建过程
1.在pom.xml中除了ssm的依赖添加dubbo相关3个依赖(接口,dubbo.jar,zkClient) 2.web.xml中修改<init-value>applicationCon ...
- dubbo服务简单搭建
一.初识dubbo: 架构图: Provider: 暴露服务的服务提供方. Consumer: 调用远程服务的服务消费方. Registry: 服务注册与发现的注册中心. Monitor: 统计服务的 ...
- Dubbo+zookeeper+SpringMVC搭建最简单的分布式项目
Dubbo 是什么 一款分布式服务框架 高性能和透明化的RPC远程服务调用方案 SOA服务治理方案 Dubbo 架构流程图 Provider:服务提供方 Consumer:服务消费者 Registry ...
随机推荐
- WizNote for linux installation
源一:没有用处 官网链接http://www.wiznote.com/download-wiznote-for-Linux. 源二:提供了源及安装方法 Fedora 中文社区软件源,具体位置在这里. ...
- js常用
window.navigator.userAgent.toLowerCase().indexOf("msie") != -1 是否是IE浏览器
- The Zero
TOday is just a alpha, but there isnot 欧米伽. 编程,是你选的,是你学的,也是你喜欢的,更是你追求的.为什么要放弃塔!. 加油! 为自己. #include&l ...
- python之socket 网络编程
提到网络通信不得不复习下osi七层模型: 七层模型,亦称OSI(Open System Interconnection)参考模型,是参考模型是国际标准化组织(ISO)制定的一个用于计算机或通信系统间互 ...
- JS浮点数的加减乘除运算
文章来源地址:http://blog.csdn.net/lyd518/article/details/7236464 转载请注明出处,尊重作者劳动成果,谢谢!问题这样的: 37.5*5.5=206.0 ...
- [刘阳Java]_MyBatis_常规标签的用法_第6讲
一般MyBatis最基本标签,或者说初学者上手最快的标签就是增删改查 1.<insert>标签,在MyBatis中完成数据添加操作 <insert id="addMyUse ...
- AppScan 测试需要输入用户名密码的网站
Cisco有专门的网页版的AppScan,使用前需要向有关的team申请account和权限. account和权限申请成功后,登录AppScan网站,创建自己的文件夹目录,然后在自己的目录下新建sc ...
- linux driver编译环境搭建和命令
首先将ubuntu14.04的内核升级到内核3.18.12. 其次,Ubuntu14.04上驱动编译命令 $ sudo make -C ~/linux-3.18.12/ M=`pwd` modules ...
- 【redis】redis 在 windows 下安装使用
1.安装 windows 下 redis 可用客户端 : http://redisdesktop.com/download ; 或在 github 上下载 redis zip 包,解压包到某个目录并在 ...
- ajax 如何提交数据到后台jsp页面,以及提交完跳转到jsp页面
我logincheck.jsp页面取传参数代码: String user=request.getParameter("user1"); String pwd=request.get ...