【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 ...
随机推荐
- order_by_、group_by_、having的用法区别
写于 2012-11-20 22:14 doc文档上. Having 这个是用在聚合函数的用法.当我们在用聚合函数的时候,一般都要用到GROUP BY 先进行分组,然后再进行聚合函数的运算.运算完后 ...
- map集合键值对存储,键值不重复,值可以重复
import java.util.HashMap; import java.util.Hashtable; import java.util.Iterator; import java.util.Li ...
- SpringMVC的controller方法上若需要参数 如User
Bean: public class User { private String name; private String password; public String getN ...
- css中clip-path属性的运用
今天看到一位同学的需求,要在一个div中加一个小尖尖,对话时发的图片,旁边这个三角是怎么实现与图片的颜色一致,效果如下: 当然,解决这个问题有各种奇淫巧技,现在我们来看一个css属性clip-path ...
- nginx日志轮巡切割
通过编辑脚本的方式来实现日志每日以及每天的切割纪录.可以通过计划任务的方式实现每天执行脚本,具体情况需要更加实际情况 vim /root/cut_nginx_log.sh #!bin/sh Datef ...
- C#设置字体(FontDIalog)、颜色(ColorDialog)对话框控件
设置字体控件为FontDialog,设置颜色的控件为ColorDialog.这两个控件的使用和OpenFileDialog(打开文件)及FolderBroswerDialog(打开文件夹)的使用类似. ...
- C# SHA1散列算法
C# SHA1散列算法 /// <summary> /// C# SHA1散列算法 /// </summary> /// <param name="str&qu ...
- 解决libcurl7.50.3在windows XP SP3 VC++ 6.0下编译报错 unresolved external symbol __imp__IdnToAscii@20 unresolved external symbol __imp__IdnToUnicode@20
错误重现: --------------------Configuration: curl - Win32 LIB Debug DLL Windows SSPI DLL WinIDN--------- ...
- ubuntu新建用户无法登陆
使用sudo adduser 创建用户,不存在无法登陆问题,如果使用useradd创建用户xx,需要在新建home目录下建立用户目录. 同时,需要修改用户目录的属主,命令:chown xx:xx ...
- inotify resources exhausted
inotify resources exhausted tail -f /var/log/kubelet.log tail: inotify resources exhausted tail: ino ...