dubbo zookeeper spring統合のハローワールド


dubboは今とても流行っている分散サービス技術で、多くの会社が使っています。暇の間、ハローワールドを作って、みんなに分けます。本論文のdemoダウンロード1.zookeeperをダウンロードすることはサービスの登録センターであり、ダウンロードしてインストールディレクトリG:bakCenter zookeeper-33.6 binに入ります。zkServer.cmdをダブルクリックすると登録センターサービスが起動します。zkServer.sh【Linux】またはzkServer.cmd【Windows】Zookeeperの設定ファイルはconfディレクトリの下にあります。このディレクトリの下にはzoo_があります。sample.cfgとlog 4 j.propertiesは、zoo_を必要とします。sample.cfgはzoo.cfgと名前を変えて、Zookeeperは起動時にこのファイルをデフォルトの設定ファイルとして探します。
# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial 
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between 
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
dataDir=/tmp/zookeeper
# the port at which the clients will connect
clientPort=2181
プロファイルはここ2を参照してもいいです。サービスプロバイダ定義サービスインターフェース:
package com.hy.service;
public interface DemoService {
    String sayHello(String name);
}
実現サービスインターフェース:
package com.hy.service.impl;

import com.hy.service.DemoService;
public class DemoServiceImpl implements DemoService {
    public String sayHello(String name) {
        System.out.println("init : " + name);
        return "hello " + name;
    }
}
Spring構成でサービスを登録します。


    
    
    
    
    
     
    

    
    

サービス提供者の主な方法を実行してサービスを有効にします。
package main;

import java.io.IOException;

import org.springframework.context.support.ClassPathXmlApplicationContext;

public class ProviderMain {

    public static void main(String[] args) throws IOException {

        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( new String[] { "applicationProvider.xml" });
        context.start();

        System.out.println("      ..");
        System.in.read();
        context.close();
    }
}
3.dubbo監視センターがサービスを調べて住所をダウンロードした後、dubbo-admin-2.5.4-NAPSHOT.warカバンをtomcatサーバのwebappsディレクトリに置いて、tomcatサーバを起動します。下のリンクを開くと、利用可能なサービスとその状態が表示されます。http://localhost:8080/dubbo-a…ユーザー名とパスワードはC:Program FilesApache Software FoundationTomcat 7.0 webapps dubro-admin-2.4.5-SCPSHOTWEB-INFdubro.propertiesファイルに配置されています。
dubbo.registry.address=zookeeper://127.0.0.1:2181
dubbo.admin.root.password=root
dubbo.admin.guest.password=guest
4.サービス消費者がSpring配置で購読サービス提供者が暴露するサービス


    

    

    
    
 
サービス消費者の主な方法を実行してサービスを有効にします。
package main;

import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.hy.service.DemoService;

public class ConsumerMain {
    public static void main(String[] args) {
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
                new String[] { "applicationConsumer.xml" });
        context.start();
        DemoService service = (DemoService) context.getBean("demoService");
        System.out.println(service.sayHello("world"));
        context.close();
    }
}
コンソールにおける可視サービス提供者方法の呼び出し結果。