一、Dubbo服务的运行方式:
tomcat/jetty等占用端口,dubbo服务也需要端口
浪费资源(内存):单独启动tomcat,jetty占用内存大
2、自建Main方法类来运行(Spring容器) ----不建议(本地调试可用)
缺点: Dobbo本身提供的高级特性没用上
自已编写启动类可能会有缺陷可实现优雅关机(ShutdownHook)
注意点
spring-context.xml
<import resource="classpath:spring/xxx.xml" />
官方:服务容器的加载内容可以扩展,内置了spring, jetty, log4j等加载,可通过Container扩展点进行扩展
Dubbo是通过JDK的ShutdownHook来完成优雅停机的,所以如果用户使用"kill -9 PID"等强制关闭指令,是不会执行优雅停机的,只有通过"kill PID"时,才会执行。
原理:
服务提供方停止时,先标记为不接收新请求,新请求过来时直接报错,让客户端重试其它机器。 然后,检测线程池中的线程是否正在运行,如果有,等待所有线程执行完成,除非超时,则强制关闭。
服务消费方停止时,不再发起新的调用请求,所有新的调用在客户端即报错。然后,检测有没有请求的响应还没有返回,等待响应返回,除非超时,则强制关闭。
二、Maven构建Dubbo服务可执行Jar包的配置
<!--MAVEN打包duboo可执行jar begin --> <build> <finalName>edu-service-user</finalName> <resources> <resource> <targetPath>${project.build.directory}/classes</targetPath> <directory>src/main/resources</directory> <filtering>true</filtering> <includes> <include>**/*.xml</include> <include>**/*.properties</include> </includes> </resource> <!-- 结合com.alibaba.dubbo.container.Main --> <resource> <targetPath>${project.build.directory}/classes/META-INF/spring</targetPath> <directory>src/main/resources/spring</directory> <filtering>true</filtering> <includes> <include>spring-context.xml</include> </includes> </resource> </resources> <pluginManagement> <plugins> <!-- 解决Maven插件在Eclipse内执行了一系列的生命周期引起冲突 --> <plugin> <groupId>org.eclipse.m2e</groupId> <artifactId>lifecycle-mapping</artifactId> <version>1.0.0</version> <configuration> <lifecycleMappingMetadata> <pluginExecutions> <pluginExecution> <pluginExecutionFilter> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <goals> <goal>copy-dependencies</goal> </goals> </pluginExecutionFilter> <action> <ignore /> </action> </pluginExecution> </pluginExecutions> </lifecycleMappingMetadata> </configuration> </plugin> </plugins> </pluginManagement> <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> <!--MAVEN打包duboo可执行jar end -->三、可执行Dubbo服务Jar在linux上的操作
1.获取数据库密码密文,使用druid
上传druid-0.2.23.jar包到CI服务器192.168.1.51上,使用 java -cp druid-0.2.23.jar com.alibaba.druid.filter.config.ConfigTools root获取加密的密码
[root@bogon ~]# java -cp druid-0.2.23.jar com.alibaba.druid.filter.config.ConfigTools root
bNVOqb7WKLX5Bjnw+LMv92taj25KOxDimXxILPQjw42wgv+1lHzOH8kr97xDwWdhpY67QuYCS7sWN4W46YbkFA==
[root@bogon ~]#
2.打包provider提供者服务jar
3.把edu-service-user.jar与其lib上传到CI服务器上
[root@bogon home]# mkdir /home/ca/service
[root@bogon home]# mkdir /home/ca/service/user
4.手动执行jar
启动zookeeper注册中心192.168.1.121
[root@bogon user]# ls
edu-service-user.jar lib
[root@bogon user]# java -jar edu-service-user.jar
dubbo管理控制台
[root@bogon user]# ps -ef | grep edu-service
root 12391 11678 1 06:46 pts/0 00:00:08 java -jar edu-service-user.jar
root 12423 11678 0 06:59 pts/0 00:00:00 grep edu-service
[root@bogon user]# kill 12391
手工维护Dubbo服务
java -jar edu-service-xxx.jar &
kill PID
kill -9 PID