一、服务提供方

<?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-provider" />
<!-- 测试环境:register 是否向此注册中心注册服务,如果设为false,将只订阅,不注册 -->
<dubbo:registry protocol="zookeeper" address="zookeeper://xxx.xxx.xxx.xxx:32181" register="false" /> <!-- provider提供方 -->
<!-- 用dubbo协议在20882端口暴露服务 -->
<!-- 服务提供者协议配置,提供方需要指定端口,不同提供方需要使用不同端口,不然会有端口冲突,使用的端口需要在防火墙iptables中配置允许通过 -->
<dubbo:protocol name="dubbo" port="20882" /> <!-- 声明需要暴露的服务接口 -->
<dubbo:service interface="com.xxx.dubboprovider.Ixxx" ref="serviceA" version="1.0.0" timeout="1200000" />
<!-- 和本地bean一样实现服务 -->
<bean id="serviceA" class="com.xxx.dubboprovider.impl.xxxxImpl" /> </beans>

如果是本地连接测试环境的的dubbo,此处可以不用写,永自带的提供方即可;如果是本地开启注册到zookeeper,那么此处就要写上相关信息

上述就转换为:直连提供者只需要在消费端设置 。

二、服务消费方

<?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-admin或dubbo-monitor会显示这个名字,方便识别 -->
<dubbo:application name="dubbo-client" /> <!-- 测试环境:调试直连的话加上这个属性 register="false" -->
<dubbo:registry protocol="zookeeper" address="zookeeper://xxx.xxx.xxx.xxx:32181" register="false" /> <!-- 逾期信息 -->
<dubbo:reference id="dubboProviderService" interface="com.xxx.dubboprovider.Ixxx" check="false" version="1.0.0" url="dubbo://xxx:xxx:xxx:xxx:port"/>
</beans>

三、启动测试程序主入口

package com.xxx.xxx.xxx.dubbo;

import java.text.SimpleDateFormat;
import java.util.Date; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.macula.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; /**
* <p>
* <b>DubboMain</b> is 测试Dubbo主流程使用
* </p >
*
* @since 2019年10月12日 10:49:54
* @author Liuyc
* @version $Id: codetemplates.xml 1145 2019年10月12日 Liuyc $
*/
public class DubboMain { private static final Log log = LogFactory.getLog(DubboMain.class); public static void main(String[] args) {
try {
ClassPathXmlApplicationContext parentContext = new ClassPathXmlApplicationContext(
"classpath:applicationContext-root.xml");
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] {
"classpath:/configs/applicationContext-app.xml",
"classpath:/configs/applicationContext-core.xml" }, parentContext); ApplicationContext.setContainer(context); context.start(); System.out.println(new SimpleDateFormat("[yyyy-MM-dd HH:mm:ss]").format(new Date())
+ " Dubbo service server started!");
} catch (Exception e) {
System.out.println(e);
log.error("== DubboProvider context start error:",e);
}
synchronized (DubboMain.class) {
while (true) {
try {
DubboMain.class.wait();
} catch (InterruptedException e) {
log.error("== synchronized error:",e);
}
}
}
} }

为了方便测试,可以先把API合并到dubbo中,发布之后,再测试本地的接口实现是否正确

四、测试入口

package com.xxx.xxx.xxx.api.impl;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /**
*
* @author Liuyc
*
*/
@RunWith(SpringJUnit4ClassRunner.class) // 使用junit4进行测试
@ContextConfiguration(locations = { "classpath:api-consumer.xml" }) // 加载配置文件:当前的消费者是测试中的消费者,可以拷贝一份过来
public class TestApi { private static final Log log = LogFactory.getLog(TestApi.class); @Autowired
XxxApi xxxApi; // 1. 此处可以测试自己的API是否正确
@Test
public void getMyActivities() {
// to do something
} }

注意:启动的时候可以run,也可以debug,可以任意测试是否正确;如果很有信息,可以使用官网的简易测试  invoke,参考:http://dubbo.apache.org/zh-cn/docs/user/references/telnet.html

Dubbo-本地测试直连的更多相关文章

  1. dubbo本地调试直连

    服务: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://ww ...

  2. dubbo本地服务化实现(dubbo三)

    一.dubbo服务化架构包含的内容 对于传统工程而言,分层的依据是按照包来区分.由于在相同的工程中,所以服务的提供和调用可以方便的实现. 但是对于分布式架构而言,服务的提供者负责服务具体的实现和接口规 ...

  3. Dubbo入门到精通学习笔记(十二):Dubbo消费端直连提供者(开发调试)、Dubbo服务只订阅(开发调试)、Dubbo服务只注册

    文章目录 Dubbo消费端直连提供者(开发调试) Dubbo服务只订阅(开发调试) Dubbo服务只注册 Dubbo消费端直连提供者(开发调试) Dubbo 官方文档: 用户指南 >> 示 ...

  4. 本地测试时修改localhost为自己网站的域名的方法(转载)

    做网站的,在本地测试时,所用的地址基本上都是localhost 或者直接用IP地址:127.0.0.1 如果仅仅是用来测试网站内部的程序代码之类的当然没问题,但是如果我们还要测试网站上添加的广告或者统 ...

  5. 用java开发微信公众号:测试公众号与本地测试环境搭建(一)

    本文为原创,原始地址为:http://www.cnblogs.com/fengzheng/p/5023678.html 俗话说,工欲善其事,必先利其器.要做微信公众号开发,两样东西不可少,那就是要有一 ...

  6. 在本地测试一次成功的AJAX请求

    要在本地测试AJAX,首先是环境的搭建,下面以wamp为例. 1.先在wamp的官网下载wamp的安装包,网址 http://www.wampserver.com/. 2.安装wamp.如果安装过程中 ...

  7. 本地测试AJAX请求

    要在本地测试AJAX,首先是环境的搭建,因为XHR对象的open方法中参数url是指文件在服务器上的文件.下面以WampServer为例. 1. 下载wamp的安装包,下载地址为:http://221 ...

  8. win10系统iis下部署搭建https (ssl/tls)本地测试环境

    有时想要把公司的某些XX项目部署成https站点,是为了在传输层加密传输,防止他人嗅探站点重要数据信息,平常我们使用的http方式都是明文方式传输的很不安全,容易被他人窃取.而有些时候要在本地搭建ht ...

  9. win7 windows server 2008R2下 https SSL证书安装的搭配(搭配https ssl本地测试环境)

    原文:http://www.cnblogs.com/naniannayue/archive/2012/11/19/2776948.html 要想成功架设SSL安全站点关键要具备以下几个条件. 1.需要 ...

  10. https,https的本地测试环境搭建,asp.net结合https的代码实现,http网站转换成https网站之后遇到的问题

    一:什么是https SSL(Security   Socket   Layer)全称是加密套接字协议层,它位于HTTP协议层和TCP协议层之间,用于建立用户与服务器之间的加密通信,确保所传递信息的安 ...

随机推荐

  1. TIJ——Chapter Three:Operators

    Operators 本章节比较简单,所以简单的做一些笔记: 几个要点: 1.When the compiler sees a String followed by a "+" fo ...

  2. 【C++】为什么构造函数没有返回值?(转载)

    为什么构造函数没有返回值?   意见(1) 我认为构造函数隐含的返回值就是this,因为构造函数是在类的对象产生时自动调用.构造函数被调用也就意味着产生了一个对象,而this指针是与对象实体相关联的, ...

  3. UVa 825【简单dp,递推】

    UVa 825 题意:给定一个网格图(街道图),其中有一些交叉路口点不能走.问从西北角走到东南角最短走法有多少种.(好像没看到给数据范围...) 简单的递推吧,当然也就是最简单的动归了.显然最短路长度 ...

  4. AbstractExecutorService的submit方法概要介绍

    1.概述 ExecutorService是JDK提供的框架,它简化了异步模式下的任务执行.一般来说,ExecutorService会自动提供一个线程池和API,用于为其分配任务. 2.实例化Execu ...

  5. COGS 775 山海经

    COGS 775 山海经 思路: 求最大连续子段和(不能不选),只查询,无修改.要求输出该子段的起止位置. 线段树经典模型,每个节点记录权值和sum.左起最大前缀和lmax.右起最大后缀和rmax.最 ...

  6. maven修改版本号

    1.修改版本 mvn versions:set -DnewVersion=xxx 2.回滚版本,提交后不能回滚 mvn versions:revert 3.提交版本变更 mvn versions:co ...

  7. Google 各国地址

    google各国域名大全 香港www.google.com.hk 台湾www.google.com.tw 日本www.google.co.jp 中国www.google.cn 韩国www.google ...

  8. MySQL常用函数大全讲解

    MySQL数据库中提供了很丰富的函数.MySQL函数包括数学函数.字符串函数.日期和时间函数.条件判断函数.系统信息函数.加密函数.格式化函数等.通过这些函数,可以简化用户的操作.例如,字符串连接函数 ...

  9. 解决margin塌陷和margin合并

    <!doctype html> <html> <head> <meta charset="UTF-8"> <title> ...

  10. 【t065】最敏捷的机器人

    Time Limit: 1 second Memory Limit: 128 MB [问题描述] [背景] Wind设计了很多机器人.但是它们都认为自己是最强的,于是,一场比赛开始了~ [问题描述] ...