원래 dubbo 발표 서비스 가 이렇게 간단 합 니 다. springboot + dubbo

10286 단어 springboot
대단히 감사합니다http://blog.csdn.net/hulei19900322/article/details/78106718
마이크로 서비스 기술 학습 https://www.itkc8.com
Dubbo 는 Alibaba 가 소스 를 오픈 하 는 분포 식 서비스 구조 로 가장 큰 특징 은 업무 별 구조 에 따라 이런 방식 을 사용 하면 각 업무 간 의 결합 (또는 최대한 느슨 한 결합) 을 풀 수 있다 는 것 이다.서비스 모델 의 측면 에서 볼 때 Dubbo 는 매우 간단 한 모델 을 사용 하 는데 제공 자가 서 비 스 를 제공 하거나 소비자 가 서 비 스 를 소비 하 는 것 이기 때문에 이 를 바탕 으로 서비스 제공 자 (Provider) 와 서비스 소비 자 (Consumer) 두 가지 역할 을 추상 화 할 수 있다.등록 센터, 협의 지원, 서비스 모니터링 등 내용 에 대해 서 는 다음 과 같이 설명 한다.spring - boot 는 최근 몇 년 동안 점점 유행 하 는 라 이브 러 리 로 Spring Boot 는 Spring 프레임 워 크 를 사용 할 때의 개발 효율 을 크게 향상 시 킬 수 있 습 니 다.spring - boot - starter - dubbo 는 spring - boot 의 효율 적 이 고 dubbo 를 통합 시 켜 dubbo 의 사용 을 서민 화 시킨다.
쾌속 입문
1. maven 이 관리 하 는 spring - boot 프로젝트 에 의존 도 를 도입 합 니 다. (spring - boot 버 전 1.5 이상, 1.5 이하 테스트 되 지 않 은 것 을 권장 합 니 다)

    <dependency>
        <groupId>com.gitee.regergroupId>
        <artifactId>spring-boot-starter-dubboartifactId>
        <version>${spring-boot-starter-dubbo.version}version>
    dependency>

2. spring-boot ’application.yml’ dubbo


spring:
  dubbo: 
    application:
      name: demo-provider
    base-package: com.test.dubbo.provider  # dubbo         
    registry:
      address: 127.0.0.1                   # zookeeper       
      port: 2181                           # zookeeper       
    protocol:
      name: dubbo
      serialization: hessian2
    provider:
      retries: 0                           #         ,         ,          


spring:
  dubbo: 
    application:
      name: demo-consumer
    base-package: com.test.dubbo.consumer  # dubbo          
    registry:
      address: 127.0.0.1                   # zookeeper       
      port: 2181                           # zookeeper       
    consumer:
      timeout: 1000 
      check: true                          #                 
      retries: 2                           #          

3. ,

api


package com.test.dubbo.service;

public interface DemoService {
    Integer add(Integer a,Integer b);
}

4.


package com.test.dubbo.provider;
import com.test.dubbo.service.DemoService;
import com.alibaba.dubbo.config.annotation.Service;

@Service
public class DemoServiceImpl implements DemoService{

    public Integer add(Integer a,Integer b){
        System.err.printf("  add    %s+%s", a, b);
        System.err.println();
        if(a==null||b==null){
            return 0;
        }
        return a+b;
    }
}

5.


package com.test.dubbo.consumer;

import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import com.alibaba.dubbo.config.annotation.Reference;
import com.reger.dubbo.annotation.Inject;

import com.test.dubbo.service.DemoService;

@Component
public class DemoConsumer implements CommandLineRunner {

    //       ,    dubbo    @Reference  
    @Inject DemoService service; 

    @Override
    public void run(String... args){  
        int a=1;
        int b =2;
        System.err.printf("%s+%s=%s", a, b, service.add(a,b));
        System.err.println(); 
    }
}

6. , 。

spring-boot main


package com.test.dubbo.main;

import java.util.concurrent.TimeUnit;

import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication 
public class SpringDubboConfigApplication implements CommandLineRunner {

    public static void main(String[] args) throws InterruptedException {
        SpringApplication.run(SpringDubboConfigApplication.class, args);
        TimeUnit.MINUTES.sleep(10); //   main    10       
        System.err.println("     ------>>    ");
    }

    @Override
    public void run(String... args) throws Exception {
        System.err.println("     ------>>    ");
    } 
}

spring-boot main


package com.test.dubbo.main;

import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication 
public class SpringDubboConfigApplication implements CommandLineRunner {

    public static void main(String[] args) {
        SpringApplication.run(SpringDubboConfigApplication.class, args);
    }

    @Override
    public void run(String... args) throws Exception {
        System.err.println("     ------>>    ");
    }
}

spring-boot-starter-dubbo-example  
spring-boot-starter-dubbo  
dubbo  
spring-boot

jar rpc , app h5 restful api, restful spring-boot-starter-swagger

 https://www.itkc8.com

 

 

좋은 웹페이지 즐겨찾기