maven dubbo zookeeper 项目搭建(有效)jar包非war测试
zookeeper安装以及dubbo-admin.war(管理端)配置启动,本章省略,参考其他内容
这里主要说服务提供者和消费者
项目结构:
1)服务端
DemoServer.java
package com.mor.server.dubbo.service;
public interface DemoServer {
String sayHello(String str);
}
DemoServerImpl.java
package com.mor.server.dubbo.service;
public class DemoServerImpl implements DemoServer {
public String sayHello(String str) {
str = "Hello " + str ;
System.err.println("server:" + str);
return str;
}
}
Main.java
package com.mor.server.main;
import java.io.IOException;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class Main {
public static void main(String[] args) throws IOException {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] { "applicationProvider.xml" });
context.start();
System.out.println("按任意键退出");
System.in.read();
}
}
applicationProvider.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="hello-world-app" />
<!-- 测试 -->
<dubbo:registry protocol="zookeeper" address="192.168.40.172:2181" />
<dubbo:protocol name="dubbo" port="20880" />
<dubbo:service interface="com.mor.server.dubbo.service.DemoServer"
ref="demoService" /> <!-- 和本地bean一样实现服务 -->
<bean id="demoService" class="com.mor.server.dubbo.service.DemoServerImpl" />
</beans>
log4j.properties
log4j.appender.Stdout=org.apache.log4j.ConsoleAppender
log4j.appender.Stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.Stdout.layout.conversionPattern=%-5p - %-26.26c{1} - %m\n
log4j.rootLogger=INFO,Stdout
log4j.logger.org.apache.wicket=INFO
log4j.logger.org.apache.wicket.protocol.http.HttpSessionStore=INFO
log4j.logger.org.apache.wicket.version=INFO
log4j.logger.org.apache.wicket.RequestCycle=INFO
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mor.maven</groupId>
<artifactId>dubboserver</artifactId>
<version>0.0.1</version>
<packaging>jar</packaging>
<name>dubboserver</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring.version>3.1.4.RELEASE</spring.version>
<slf4j.version>1.6.6</slf4j.version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!-- Spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-asm</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-expression</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- spring end -->
<!-- log -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${slf4j.version}</version>
</dependency>
<!-- dubbo -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
<version>2.5.3</version>
</dependency>
<!-- zkclient -->
<dependency>
<groupId>com.github.sgroschupf</groupId>
<artifactId>zkclient</artifactId>
<version>0.1</version>
</dependency>
<!-- zookeeper -->
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>3.3.6</version>
</dependency>
</dependencies>
<build>
<finalName>dubbo-demo</finalName>
<plugins>
<!-- 非多个资源配置 start-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.1</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
<encoding>UTF-8</encoding>
<failOnError>false</failOnError>
</configuration>
</plugin>
<!-- 非多个资源配置 end-->
</plugins>
</build>
</project>
2)消费端
ChatAction.java
package com.mor.client.dubbo.action;
import java.util.Date;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.mor.server.dubbo.service.DemoServer;
public class ChatAction {
public void SayHello(){
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] { "applicationConsumer.xml" });
context.start();
DemoServer demoServer = (DemoServer) context.getBean("demoService");
System.out.println("client:"+demoServer.sayHello("sun:"+new Date()));
}
}
Main.java
package com.mor.client.dubbo.main;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.mor.client.dubbo.action.ChatAction;
import com.mor.server.dubbo.service.DemoServer;
public class Main {
public static void main(String[] args) throws InterruptedException {
/* ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] { "applicationConsumer.xml" });
context.start();
DemoServer demoServer = (DemoServer) context.getBean("demoService");
demoServer.sayHello("sun");*/
int i=0;
while(i++<100){
System.out.println("hello");
ChatAction act = new ChatAction();
act.SayHello();
Thread.sleep(3000);
}
}
}
applicationConsumer.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="consumer-of-helloworld-app" /> <!-- 使用multicast广播注册中心暴露发现服务地址 -->
<dubbo:registry protocol="zookeeper" address="192.168.40.172:2181" /> <!-- 生成远程服务代理,可以和本地bean一样使用demoService -->
<dubbo:reference id="demoService" interface="com.mor.server.dubbo.service.DemoServer" />
</beans>
log4j.properties
log4j.appender.Stdout=org.apache.log4j.ConsoleAppender
log4j.appender.Stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.Stdout.layout.conversionPattern=%-5p - %-26.26c{1} - %m\n
log4j.rootLogger=INFO,Stdout
log4j.logger.org.apache.wicket=INFO
log4j.logger.org.apache.wicket.protocol.http.HttpSessionStore=INFO
log4j.logger.org.apache.wicket.version=INFO
log4j.logger.org.apache.wicket.RequestCycle=INFO
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>demo-dubbo</groupId>
<artifactId>dubboclient</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>dubboclient</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring.version>3.1.4.RELEASE</spring.version>
<slf4j.version>1.6.6</slf4j.version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!-- Spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-asm</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-expression</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- spring end -->
<!-- log -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${slf4j.version}</version>
</dependency>
<!-- dubbo -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
<version>2.5.3</version>
</dependency>
<!-- zkclient -->
<dependency>
<groupId>com.github.sgroschupf</groupId>
<artifactId>zkclient</artifactId>
<version>0.1</version>
</dependency>
<!-- zookeeper -->
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>3.3.6</version>
</dependency>
</dependencies>
<build>
<finalName>dubbo-demo</finalName>
<plugins>
<!-- 非多个资源配置 start-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.1</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
<encoding>UTF-8</encoding>
<failOnError>false</failOnError>
</configuration>
</plugin>
<!-- 非多个资源配置 end-->
</plugins>
</build>
</project>
注意:服务端与客户端之间的zookeeper用到的版本号一致,否则会出现连接上服务端但是操作不了远程接口的问题
服务端启动成功:
消费端启动:
消费端调用远程接口完成之后,dubbo的管理端这边的消费者内容就会清空掉(所以在跑完消费端之后再看dubbo admin管理端这边的消费者为空时不要惊讶!)
maven dubbo zookeeper 项目搭建(有效)jar包非war测试的更多相关文章
- 【Maven】从Maven中导出项目依赖的Jar包
从SVN上下载源代码 svn export https://10.200.1.201/xxxx/PLATFORM code/ --force --username xxx --password xxx ...
- idea打包SpringBoot项目打包成jar包和war
- 打包成jar包 1. <groupId>com.squpt.springboot</groupId> <artifactId>springbootdemo< ...
- maven buid 导出项目依赖的jar包问题
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-dependency-plugin:2.8:copy-dependencie ...
- 【spring boot】idea下springboot打包成jar包和war包,并且可以在外部tomcat下运行访问到(转)
转自:https://www.cnblogs.com/sxdcgaq8080/p/7727249.html 接着上一章走呗:http://www.cnblogs.com/sxdcgaq8080/p ...
- 【spring boot】6.idea下springboot打包成jar包和war包,并且可以在外部tomcat下运行访问到
接着上一章走呗:http://www.cnblogs.com/sxdcgaq8080/p/7712874.html 然后声明一点,下面打包的过程中,scope一直都是使用默认的范围 <!--用于 ...
- idea下springboot打包成jar包和war包,并且可以在外部tomcat下运行访问到
接着上一章走呗:http://www.cnblogs.com/sxdcgaq8080/p/7712874.html 然后声明一点,下面打包的过程中,scope一直都是使用默认的范围 <!--用于 ...
- 使用Sonatype Nexus搭建Maven私服后,如何添加第三方JAR包
使用Sonatype Nexus搭建Maven私服后如何添加第三方JAR包 步骤如下 1.打开nexus地址,进行登录 2.登录Nexus后,点击右侧的“Repositories”,显示当前Nexus ...
- 【转】maven导出项目依赖的jar包
本文转自:http://my.oschina.net/cloudcoder/blog/212648 一.导出到默认目录 targed/dependency 从Maven项目中导出项目依赖的jar包:进 ...
- eclipse导入maven项目后依赖jar包更新问题->update project按钮
eclipse导入maven项目后依赖jar包更新问题 1.eclipse有专门的导入maven项目按钮,file-import-maven project,eclipse会自动查找指定路径下的pom ...
随机推荐
- Windows命令行中pip install jieba,但没有安装到anaconda3中
系统混淆了python3环境下的pip和anaconda3环境下的pip. 找到Anaconda3的Scripts目录,我这里是C:\Users\Diane\Anaconda3\Scripts 将该目 ...
- Python面向对象之常用的特殊方法(5)
Python面向对象里面有很多特殊方法,例如__init__(构造方法),__del__(析构方法),这些方法对于面向对象编程非常重要,下面列出一些常用的特殊方法 (1)__call__ class ...
- 第二篇:python基础_2
本篇内容 数字 字符串 元祖 字典 列表 集合 for循环 二进制 字符编码 文件处理 一.数字 1.int(整型) 在32位机器上,整数的位数为32位,取值范围为-2**31-2**31-1,即-2 ...
- PHP网站提交表单如何实现验证码验证功能
很多小伙伴在原生网站时候都会遇到很多意料之外的情况发生,也有不少小伙伴在初学程序代码的时候可能会因为一个小小的逗号隐藏在几百行,几千行的代码中出错常见的在提交表单中很多事需要验证码验证,那么如何来实现 ...
- Posix线程编程指南
Posix线程编程指南 Posix线程编程指南... 1 一线程创建与取消... 2 线程创建... 2 1.线程与进程... 2 2. 创建线程... 2 3. 线程创建属性... 2 4. 创建的 ...
- bzoj 4196 树链剖分 模板
[Noi2015]软件包管理器 Time Limit: 10 Sec Memory Limit: 512 MBSubmit: 2135 Solved: 1232[Submit][Status][D ...
- 深入比较选择 Angular 还是 React
我应该选择 Angular 还是 React?现在JS框架两强的格局让许多开发者选择起来很纠结.无论你是一个正在思考如何入门的新手,还是一个为下个项目挑选框架的设计者,或是一个架构师为公司做长远的规划 ...
- hdu 3535 背包综合题
/* 有n组背包,每组都有限制 0.至少选一项 1.最多选一项 2.任意选 */ #include <iostream> #include <cstdio> #include ...
- linux之参数实用讲解
<1>linux文件参数 在Windows下是使用 %1 %2 %3 而在Linux下是使用 $1 $2 $3 ------------------- 如: 1.某bat文件 cd ...
- HDU3001 Travelling
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission( ...