dubbo服务的运行方式
?1、使用Servlet容器運(yùn)行(Tomcat、Jetty等)----不可取?
? 缺點(diǎn):增加復(fù)雜性(端口、管理)?浪費(fèi)資源(內(nèi)存)?
假設(shè)1個(gè)服務(wù)模塊時(shí),需要1臺(tái)tomcat,消耗3個(gè)端口,和200MB左右內(nèi)存
假設(shè)10個(gè)服務(wù)模塊時(shí),需要10臺(tái)tomcat,消耗30個(gè)端口,和2000MB左右內(nèi)存
假設(shè)100個(gè)服務(wù)模塊時(shí),需要100臺(tái)tomcat,消耗300個(gè)端口,和20000MB左右內(nèi)存
.......大型的分布式項(xiàng)目將不可想象!!!!
?2、自建Main方法類來運(yùn)行(Spring容器) ----不建議(本地調(diào)試可用)?
?缺點(diǎn):Dobbo本身提供的高級(jí)特性沒用上?
?自已編寫啟動(dòng)類可能會(huì)有缺陷。
比如關(guān)閉dubbo的時(shí)候,控制臺(tái)直接點(diǎn)擊關(guān)閉,如果此時(shí)dubbo有服務(wù)正在調(diào)用,就會(huì)導(dǎo)致失敗。
代碼:
package dubbo.test;import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.context.support.ClassPathXmlApplicationContext;/*** * @描述: 啟動(dòng)Dubbo服務(wù)用的MainClass.*/ public class DubboProvider {private static final Log log = LogFactory.getLog(DubboProvider.class);public static void main(String[] args) {try {ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:spring/spring-context.xml");context.start();} catch (Exception e) {log.error("== DubboProvider context start error:",e);}synchronized (DubboProvider.class) {while (true) {try {DubboProvider.class.wait();} catch (InterruptedException e) {log.error("== synchronized error:",e);}}}}}
?3、使用Dubbo框架提供的Main方法類來運(yùn)行(Spring容器)----建議使用?
?優(yōu)點(diǎn):框架本身提供(com.alibaba.dubbo.container.Main)?
? ? ? ? 可實(shí)現(xiàn)優(yōu)雅關(guān)機(jī)(ShutdownHook ) ,即解決第2點(diǎn)關(guān)閉dubbo問題。
參見:
dubbo-user-book.pdf ?第110~111頁
下載地址:
https://www.gitbook.com/@dubbo
總結(jié)
以上是生活随笔為你收集整理的dubbo服务的运行方式的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Flume概述
- 下一篇: 企业网站 源码 服务邮箱:_后来才知道: