Dubbo_创建Dubbo服务并在ZooKeeper注册,然后通过Jar包执行【转】
来源:互联网 发布:华为交换机 端口详解 编辑:程序博客网 时间:2024/06/06 16:34
原文地址
http://www.cnblogs.com/gossip/p/5945848.html
原文
1、DemoService
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package
dub.service.demo;
import
java.net.InetAddress;
import
java.net.UnknownHostException;
/**
* Created by JamesC on 16-10-8.
*/
public
class
DemoService
implements
IDemoService {
public
String sayHello(String name) {
String msg =
"欢迎您:"
+ name +
" IP地址:"
+ getIP();
System.out.println(msg);
return
msg;
}
private
String getIP() {
InetAddress addr =
null
;
try
{
addr = InetAddress.getLocalHost();
}
catch
(UnknownHostException e) {
e.printStackTrace();
}
String ip = addr.getHostAddress();
//获得本机IP
String address = addr.getHostName();
//获得本机名称
return
ip;
}
}
2、dubbo-provider.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?
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"
xmlns:context
=
"http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://code.alibabatech.com/schema/dubbo
http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<
context:annotation-config
/>
<!-- 配置要扫描的包 -->
<
context:component-scan
base-package
=
"dub.service.demo"
/>
<!-- 提供方应用信息,用于计算依赖关系 -->
<
dubbo:application
name
=
"dubbo-service-demo"
/>
<!-- 使用zookeeper注册中心暴露服务地址 -->
<
dubbo:registry
protocol
=
"zookeeper"
address
=
"zookeeper://192.168.146.130:2181"
/>
<!-- 用dubbo协议在20880端口暴露服务 -->
<
dubbo:protocol
name
=
"dubbo"
port
=
"20880"
/>
<!-- 用户服务接口 -->
<
dubbo:service
interface
=
"dub.service.demo.IDemoService"
ref
=
"demoService"
/>
<
bean
id
=
"demoService"
class
=
"dub.service.demo.DemoService"
/>
</
beans
>
3、pom.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<
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.0http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<
modelVersion
>4.0.0</
modelVersion
>
<
groupId
>dub-service-demo</
groupId
>
<
artifactId
>dub-service-demo</
artifactId
>
<
version
>1.0-SNAPSHOT</
version
>
<
packaging
>jar</
packaging
>
<
name
>dub-service-demo</
name
>
<
url
>http://maven.apache.org</
url
>
<
properties
>
<
project.build.sourceEncoding
>UTF-8</
project.build.sourceEncoding
>
</
properties
>
<
distributionManagement
>
<
repository
>
<
id
>nexus-releases</
id
>
<
name
>Nexus Release Repository</
name
>
<
url
>http://192.168.146.129:8081/nexus/content/repositories/releases/</
url
>
</
repository
>
<
snapshotRepository
>
<
id
>nexus-snapshots</
id
>
<
name
>Nexus Snapshot Repository</
name
>
<
url
>http://192.168.146.129:8081/nexus/content/repositories/snapshots/</
url
>
</
snapshotRepository
>
</
distributionManagement
>
<
dependencies
>
<
dependency
>
<
groupId
>org.springframework</
groupId
>
<
artifactId
>spring-beans</
artifactId
>
<
version
>4.0.6.RELEASE</
version
>
</
dependency
>
<
dependency
>
<
groupId
>org.springframework</
groupId
>
<
artifactId
>spring-core</
artifactId
>
<
version
>4.0.6.RELEASE</
version
>
</
dependency
>
<
dependency
>
<
groupId
>org.springframework</
groupId
>
<
artifactId
>spring-context</
artifactId
>
<
version
>4.0.6.RELEASE</
version
>
</
dependency
>
<
dependency
>
<
groupId
>org.springframework</
groupId
>
<
artifactId
>spring-context-support</
artifactId
>
<
version
>4.0.6.RELEASE</
version
>
</
dependency
>
<
dependency
>
<
groupId
>com.alibaba</
groupId
>
<
artifactId
>dubbo</
artifactId
>
<
version
>2.5.3</
version
>
</
dependency
>
<
dependency
>
<
groupId
>org.apache.zookeeper</
groupId
>
<
artifactId
>zookeeper</
artifactId
>
<
version
>3.4.5</
version
>
</
dependency
>
<
dependency
>
<
groupId
>com.101tec</
groupId
>
<
artifactId
>zkclient</
artifactId
>
<
version
>0.3</
version
>
</
dependency
>
<
dependency
>
<
groupId
>org.slf4j</
groupId
>
<
artifactId
>slf4j-api</
artifactId
>
<
version
>1.7.5</
version
>
</
dependency
>
<
dependency
>
<
groupId
>log4j</
groupId
>
<
artifactId
>log4j</
artifactId
>
<
version
>1.2.17</
version
>
</
dependency
>
<
dependency
>
<
groupId
>org.slf4j</
groupId
>
<
artifactId
>slf4j-log4j12</
artifactId
>
<
version
>1.7.5</
version
>
</
dependency
>
</
dependencies
>
<
build
>
<!--打包生成的jar包文件名-->
<
finalName
>dub-service-demo</
finalName
>
<
resources
>
<
resource
>
<
targetPath
>${project.build.directory}/classes</
targetPath
>
<
directory
>src/main/resources</
directory
>
<
filtering
>true</
filtering
>
<
includes
>
<!--<include>**/*.xml</include>-->
<!--<include>**/*.properties</include>-->
<
include
>**/*.xml</
include
>
</
includes
>
</
resource
>
<!-- 结合com.alibaba.dubbo.container.Main -->
<
resource
>
<!--配置文件拷贝的对象目录-->
<
targetPath
>${project.build.directory}/classes/META-INF/spring</
targetPath
>
<!--配置文件必须放在spring文件夹下,否则dubbo即使显示启动成功,实际上也没有启动成功-->
<
directory
>src/main/resources/spring</
directory
>
<
filtering
>true</
filtering
>
<
includes
>
<!-- <include>spring-context.xml</include>-->
<
include
>**/*.xml</
include
>
</
includes
>
</
resource
>
</
resources
>
<
plugins
>
<!-- 打包jar文件时,配置manifest文件,加入lib包的jar依赖 -->
<
plugin
>
<
groupId
>org.apache.maven.plugins</
groupId
>
<
artifactId
>maven-jar-plugin</
artifactId
>
<
configuration
>
<
classesDirectory
>target/classes/</
classesDirectory
>
<
archive
>
<
manifest
>
<
mainClass
>com.alibaba.dubbo.container.Main</
mainClass
>
<!-- 打包时 MANIFEST.MF文件不记录的时间戳版本 -->
<
useUniqueVersions
>false</
useUniqueVersions
>
<
addClasspath
>true</
addClasspath
>
<
classpathPrefix
>lib/</
classpathPrefix
>
</
manifest
>
<
manifestEntries
>
<
Class-Path
>.</
Class-Path
>
</
manifestEntries
>
</
archive
>
</
configuration
>
</
plugin
>
<
plugin
>
<
groupId
>org.apache.maven.plugins</
groupId
>
<
artifactId
>maven-dependency-plugin</
artifactId
>
<
executions
>
<
execution
>
<!--打包阶段拷贝依赖文件-->
<
id
>copy-dependencies</
id
>
<
phase
>package</
phase
>
<
goals
>
<
goal
>copy-dependencies</
goal
>
</
goals
>
<
configuration
>
<
type
>jar</
type
>
<
includeTypes
>jar</
includeTypes
>
<!-- <useUniqueVersions>false</useUniqueVersions>-->
<!--打包依赖文件的输出路径-->
<
outputDirectory
>
${project.build.directory}/lib
</
outputDirectory
>
</
configuration
>
</
execution
>
</
executions
>
</
plugin
>
</
plugins
>
</
build
>
</
project
>
三、打包Dubbo服务
1、使用maven进行打包,先运行clean 再运行install
四、启动Dubbo服务
1、把jar文件和lib文件夹拷贝到C盘DemoServiceJars目录下
2、命令行定位到C盘DemoServiceJars目录下,执行java -jar dub-service-demo.jar
3、ZooKeeper检测到该服务
4、Linux启动Dubbo的方式也是执行:java -jar dub-service-demo.jar&
五、注意事项
1、配置文件dubbo-provider.xml必须放在resource-->spring文件夹下,否则dubbo就算显示启动成功, 实际上也没有启动
阅读全文
0 0
- Dubbo_创建Dubbo服务并在ZooKeeper注册,然后通过Jar包执行【转】
- 通过Maven将一个dubbo服务打包成可执行的jar包,并向注册中心注册服务
- idea 创建dubbo服务 jar包形式
- 本机搭建dubbo服务并依赖zookeeper注册中心
- dubbo向zookeeper注册服务
- 在linux上部署dubbo服务jar包
- 通过dubbo但是不通过zookeeper注册,本地启动服务,本地调用
- Dubbo 学习2 Dubbo-Admin及服务注册到Zookeeper
- 在Windows下安装zookeeper并启动,因为dubbo推荐使用这个注册中心
- 使用maven构建dubbo服务jar包
- dubbo服务需要的jar包
- maven 导出jar包以及导出dubbo服务jar包
- 通过zookeeper搭建dubbo注册中心遇到的问题
- Zookeeper注册中心安装——dubbo服务需要
- Dubbo无法访问远程Zookeeper已注册服务的问题
- Spring+Dubbo+Zookeeper框架搭建–<三>服务注册示例
- Dubbo注册中心zookeeper
- Dubbo学习笔记:注册到zookeeper并实现远程调用
- Android开发 自定义悬浮可拖动view
- git资料
- vim中寄存器说明
- link_directories, LINK_LIBRARIES, target_link_libraries使用总结
- leetcode 23 Merge k Sorted Lists
- Dubbo_创建Dubbo服务并在ZooKeeper注册,然后通过Jar包执行【转】
- 奋战聊天机器人(一)初识NLTK库
- mac mail设置登录网易邮箱时不成功
- Mysql批量删除带有相同前缀表名的表
- Mybatis中模糊查询的各种写法(转)
- 单元测试(一)-NUnit基础
- Duilib版视频监控客户端(简易版)
- 【推荐】基于Spark的ALS算法
- .net core完成微信公众号的消息接收和请求处理