【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


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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/417430.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

js 获取某iframe中document,浏览器兼容

/// <summary>/// 获取iframe中document&#xff0c;浏览器兼容/// 王洪岐/// id:iframe的ID/// </summary>function getIFrameDOM(id) {return document.getElementById(id).contentDocument || document.frames[id].document; }

c# mysql executenonquery_C#中ExecuteNonQuery()返回值注意点分析

本文实例讲述了C#中ExecuteNonQuery()返回值注意点。对于C#数据库程序设计有一定的借鉴价值。分享给大家供大家参考之用。具体分析如下&#xff1a;首先&#xff0c;在查询某个表中是否有数据的时候&#xff0c;我们通常用ExecuteNonQuery()&#xff0c;并通过判断值是否大于0来…

前端学习(2237):react实现疫情数据

import React from react; import ReactDOM from react-dom; import jsonData from ./code.jsonconsole.log(jsonData) let provinceObj {}/* let provinceObj{"广东省":{confirm:0,suspect:0,heal:0,deal:0}} */ jsonData.data.list.forEach((item, i) > {if (p…

数据库 数据库SQL语句五

集合运算union 并集&#xff08;两个集合如果有重复部分&#xff0c;那么只显示一次重复部分&#xff09; union all 并集&#xff08;两个集合如果有重复部分&#xff0c;那么重复部分显示两次&#xff09; intersect 交集 minus 差集--查询部门号是10和20号的员工信息 select…

SQLServer windows身份验证连接字符串

server.;databaseTest;Integrated SecurityTrue;

jdbc mysql 存储过程查询数据_JDBC连接(MySql)数据库步骤,以及查询、插入、删除、更新等十一个处理数据库信息的功能。...

主要内容&#xff1a;JDBC连接数据库步骤。一个简单详细的查询数据的例子。封装连接数据库&#xff0c;释放数据库连接方法。实现查询&#xff0c;插入&#xff0c;删除&#xff0c;更新等十一个处理数据库信息的功能。(包括事务处理&#xff0c;批量更新等)把十一个功能都放在…

vue-router之路由属性配置说明

minix 是个什么东西&#xff0c; 就是混合&#xff0c;把你混合给我 浅显表述就是 你说 &#xff1a; ‘我叫李四’&#xff0c; 我说 &#xff1a; ‘我叫张三’&#xff0c; 然后把你 混合给我&#xff0c; 就成了 我说 &#xff1a; ‘我叫张三我叫李四’&#xff0c; 所…

linux shell 用sed命令在文本的行尾或行首添加字符

from&#xff1a;http://www.cnblogs.com/aaronwxb/archive/2011/08/19/2145364.html 昨天写一个脚本花了一天的2/3的时间&#xff0c;而且大部分时间都耗在了sed命令上&#xff0c;今天不总结一下都对不起昨天流逝的时间啊~~~ 用sed命令在行首或行尾添加字符的命令有以下几种&…

lambda写法(多参数)

Lambda 表达式基本形式(input parameters) > expression< XMLNAMESPACE PREFIX "[default]" httpmsdnmicrosoftcommtps NS "http://msdn2.microsoft.com/mtps" />只有在 Lambda 有一个输入参数时&#xff0c;括号才是可选的&#xff1b;否则括号是…

linux 自动安装mysql_linux安装mysql教程

1.系统约定安装文件下载目录&#xff1a;/data/softwareMysql目录安装位置&#xff1a;/usr/local/mysql数据库保存位置&#xff1a;/data/mysql日志保存位置&#xff1a;/data/log/mysql执行如下命名&#xff1a;#mkdir /data/software#cd /data/software--下载安装包--建议&a…

C# Repeater绑定显示数组

此处绑定的对象拥有string[] Contents属性&#xff0c;绑定时将Contents[0]和Contents[1]分别绑定<asp:Repeater runat"server" ID"rptDatabase"><ItemTemplate><li><a href"Database.aspx?id<%#Eval("Contents[0]&quo…

spring使用JdbcTemplate和jdbcDaosupport及具名参数使用

关于jdbctemplate: 个人感觉比Java链接mysql那一套方便好维护多了&#xff0c;只需在配置文件维护即可 需要的包&#xff1a; com.springsource.net.sf.cglib-2.2.0.jarcom.springsource.org.aopalliance-1.0.0.jarcom.springsource.org.aspectj.weaver-1.6.8.RELEASE.jarcommo…

IIS添加直接下载的文件类型

扩展名 .dataMIME类型 application/octet-stream

密钥

【AES】 一种对称加密算法&#xff0c;DES的取代者。 加密相关文章见&#xff1a;Java 加密解密 对称加密算法 非对称加密算法 MD5 BASE64 AES RSA 【代码】 代码比较多&#xff0c;有一部分非本文章内容代码&#xff0c;具体自己看吧。 [java] view plaincopy print?package…

mysql复制安全性_从MySQL复制功能中得到一举三得实惠

在MySQL数据库中&#xff0c;支持单项、异步复制。在复制过程中&#xff0c;一个服务器充当主服务器&#xff0c;而另外一台服务器充当从服务器。如下图所示。此时主服务器会将更新信息写入到一个特定的二进制文件中。并会维护文件的一个索引用来跟踪日志循环。这个日志可以记录…

WhqDatabase 我自己用C#开发的列式数据库

项目地址&#xff1a;https://github.com/wanghongqi/WhqDatabase WhqDatabase 作者&#xff1a;王洪岐 本项目为一个C#实现的列式数据库&#xff0c;欢迎大家提出指正意见。项目中包含对Kernel完整的测试。 项目列表&#xff1a;Kernel 内核Test 对内核的测试Service 可视的…