エンタープライズアプリケーション、どのように3のサービス(ダボエントリ-ケース)エンタープライズアプリケーション、どのように2つ(ダボアーキテクチャ)のサービス

  今日は何千マイルも離れた貴州省帰って、素敵な広州、から、子供の日です!Haoshanhaoshui良い気分は、よくして何かを書きます。このエンタープライズクラスのアプリケーション、シリーズの第3の方法をサービス。最後の一:エンタープライズアプリケーション、どのように2つ(ダボアーキテクチャ)のサービス、全体的なアーキテクチャのダボの理解、およびダボ4つの特性:接続性、堅牢性、拡張性、アップグレード。エントリーレベルのデモ、直感的な感覚を実装するために、次の最初の。

1.備考

単純なケースでは、プレゼンテーションのエントリが使用することをダボ。専用ケースサービスプロバイダ、サービスコンシューマ。

2.ケースの実現

  2.1。プロジェクトを作成します。

 

 

  2.2コンフィギュレーションの依存関係はのpom.xmlを輸入しています

<?XMLバージョン= "1.0"エンコード= "UTF-8" ?> 
< プロジェクトのxmlns = "http://maven.apache.org/POM/4.0.0" 
         のxmlns:XSI = "http://www.w3.org / 2001 / XMLスキーマ・インスタンス」
         の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.anan </ groupIdを> 
    < たartifactId >ダボ-デモ</ たartifactId > 
    <</ バージョン> 

    < パッケージ> JAR </ 梱包> 

    < プロパティ> 
        <! - 春版本- > 
        < spring.version > 5.0.2.RELEASE </ spring.version > 
        <! - ダボ版本- > 
        < dubbo.version > 2.7.0 </ dubbo.version > 
    </ プロパティ> 

    < 依存性> 
        <! - 春依赖包- > 
        < 依存> 
            <groupId >org.springframework </ groupIdを> 
            < たartifactId >春・コンテキスト</ たartifactId > 
            < バージョン> $ {spring.version} </ バージョン> 
        </ 依存関係> 
        <! - ダボ依赖- > 
        < 依存> 
            < groupIdを>組織.apache.dubbo </ のgroupId > 
            < たartifactId >ダボ</ たartifactId > 
            < バージョン> $ {dubbo.version} </ バージョン> 
        </ 依存関係> 

    </ 依存関係> 
</ プロジェクト>

 

  2.3サーバ側の開発

    2.3.1.serviceインタフェース

パッケージcom.anan.dubbo.service; 

/ ** 
 *サービスインタフェース
 * / 
パブリック インターフェースHelloService { 

    / ** 
     *ハロー
     * / 
    文字のsayHello(文字列名); 
}

 

    2.3.2.serviceインターフェース

パッケージcom.anan.dubbo.service.impl。

輸入com.anan.dubbo.service.HelloService。

/ ** 
 *服务接口实现
 * / 
パブリック クラス HelloServiceImpl 実装HelloService { 

    / ** 
     *问好
     * 
     * @paramの* / 
    パブリック文字列のsayHello(文字列名){
         リターン "こんにちは、" +名+ "!" ; 
    } 
}

 

 

  2.4。構成サービスプロバイダ

<?XMLバージョン= "1.0"エンコード= "UTF-8" ?> 
< ビーンズのxmlns = "http://www.springframework.org/schema/beans" 
       のxmlns:XSI =「http://www.w3.org / 2001 / XMLスキーマ・インスタンス" 
       のxmlns:ダボ=" http://dubbo.apache.org/schema/dubbo " 
       のxsi:schemaLocationの=" http://www.springframework.org/schema/beans 
       HTTP:// WWW。 springframework.org/schema/beans/spring-beans.xsd 
       http://dubbo.apache.org/schema/dubbo 
       http://dubbo.apache.org/schema/dubbo/dubbo.xsd " > 

    <! - 申し出パーティのアプリケーション情報、依存関係を計算する- > 
    < ダボ:アプリケーション=「プロバイダ・ハローワールドアプリ」  />

    <! - マルチキャスト放送露光レジストリサービスのアドレスを使用して- > 
    < ダボ:レジストリアドレス= "マルチキャスト://224.1.1.1:6666" /> 

    <! - ダボで20880ポートでサービス契約を暴露- > 
    < ダボ:プロトコル= "ダボ" ポート= "20880" /> 

    <! - 文では、サービス・インターフェース公開する必要があります- > 
    < ダボ:サービスのインターフェース= "com.anan.dubbo.service.HelloService" REF = "helloService" /> 

    <! - と地元の豆のようなサービスを実装する- > 
    < 上記ID = "helloService" クラス=「com.ananを。dubbo.service.impl.HelloServiceImpl」 />

</ >

 

  2.5。設定サービスコンシューマ

<?XMLバージョン= "1.0"エンコード= "UTF-8" ?> 
< ビーンズのxmlns = "http://www.springframework.org/schema/beans" 
       のxmlns:XSI =「http://www.w3.org / 2001 / XMLスキーマ・インスタンス" 
       のxmlns:ダボ=" http://dubbo.apache.org/schema/dubbo " 
       のxsi:schemaLocationの=" http://www.springframework.org/schema/beans 
       HTTP:// WWW。 springframework.org/schema/beans/spring-beans.xsd 
       http://dubbo.apache.org/schema/dubbo 
       http://dubbo.apache.org/schema/dubbo/dubbo.xsd " > 

    <! - 消費依存関係を計算するために使用されるパーティのアプリケーション名、条件に一致しない、プロバイダを好きではない- > 
    < ダボ:アプリケーション=「消費者のhello-世界アプリ」  /> 

    <! - ディスカバリーサービスアドレスに使用するマルチキャスト・ブロードキャスト・レジストリ暴露- > 
    < ダボ:レジストリアドレス=「マルチキャスト://224.1.1.1:6666」/> 

    <! - リモートサービスエージェントを生成し、ローカルBeanができますhelloServiceを用い様- > 
    < ダボ:リファレンスID = "helloService" インターフェイス= "com.anan.dubbo.service.HelloService"  /> 

</ >

 

  2.6。テスト

    2.6.1。サービスプロバイダプロバイダを開始します

パッケージcom.anan.dubbo.provider; 

インポートorg.springframework.context.ApplicationContext;
 インポートorg.springframework.context.support.ClassPathXmlApplicationContext; 

/ ** 
 *プロバイダ
 * / 
パブリック クラスプロバイダ{ 

    公共の 静的な 無効メイン(文字列[]引数)スロー例外{
         // ばねコンテナを作成し、負荷スプリング設定ファイルを 
        ApplicationContextのコンテキストは= 新しい新しい ClassPathXmlApplicationContext(「CLASSPATH:provider.xmlの」); // ブロック:終了する入力を待って、任意のキーを押し        System.in.readを(); 
    } 
}
                

        

 

    2.6.2。消費者の消費者サービスを開始

以下のためのパッケージ変更com.anan.dubbo.consumer; 

インポートcom.anan.dubbo.service.HelloService;
 インポートorg.springframework.context.ApplicationContext;
 インポートorg.springframework.context.support.ClassPathXmlApplicationContext; 

/ ** 
 *コンシューマーサービス
 * / 
パブリック クラスの消費者{ 

    公共の 静的な 無効メイン(文字列[] args)を{
         // 春のコンテナを作成し、春のコンフィギュレーション・ファイルをロードする 
        のApplicationContextコンテキスト= 新しい新 ClassPathXmlApplicationContext(「CLASSPATH:consumer.xml」); //は、リモート・サービス・エージェント取得 
        helloService helloService =(helloServiceを)context.getBean( "helloService"
                

        );
         // のSystem.out.println(helloService.getClass()); 

        // リモートメソッド実行 
        =( "アナン"文字列helloService.sayHello結果
        のSystem.out.println(結果); 


    } 
}

 

おすすめ

転載: www.cnblogs.com/itall/p/10958365.html