Skip to content

Commit

Permalink
Merge pull request #6 from gglaochen/feature_zzt
Browse files Browse the repository at this point in the history
Addition instruction
  • Loading branch information
CengSin authored Nov 1, 2019
2 parents 626db97 + 912c2c0 commit 9279394
Show file tree
Hide file tree
Showing 17 changed files with 401 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ target/
!**/src/test/**

### demo ###
multiple-rpc-demo
### multiple-rpc-demo ###

### STS ###
.apt_generated
Expand Down
61 changes: 61 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Multiple-RPC-DEMO

在Spring cloud alibaba的基础上,以Nacos为注册中心,提供了两种服务调用方式,默认方式为 Feign,导入Dubbo包之后会使用Dubbo调用

## Required

- JDK1.8
- maven 3.6+

## 项目依赖

- Spring cloud Greenwich.SR1
- Spring boot 2.1.8.RELEASE
- Spring cloud alibaba 2.1.0.RELEASE
- Spring cloud alibaba nacos starter 0.9.0.RELEASE
- Spring cloud starter openfeign 2.1.1.RELEASE

## Gettging Start

* 克隆本项目

```shell script
git clone https://github.com/gglaochen/invokeReplace.git
```

* 将本项目install到本地仓库

进入项目invokeReplace路径下执行

```shell script
mvn install -DskipTests
```

* 在项目pom文件中导入

```xml
<dependency>
<groupId>com.feign.dubbo.example</groupId>
<artifactId>starter</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
```

* 替换Dubbo调用方式

pom中导入

```xml
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo</artifactId>
</dependency>
```

## sample

* [multiple-rpc-demo](multiple-rpc-demo)
47 changes: 47 additions & 0 deletions multiple-rpc-demo/multiple-rpc-demo-api/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.feign.dubbo.exmple</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>com.feign.dubbo.example</groupId>
<artifactId>api</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>api</name>
<description>Demo project for Spring Boot</description>

<properties>
<java.version>1.8</java.version>
</properties>

<dependencies>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
<version>2.7.3</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo</artifactId>
<version>2.7.3</version>
</dependency>
<dependency>
<groupId>com.feign.dubbo.example</groupId>
<artifactId>starter</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.feign.dubbo.example.api;

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

@SpringBootApplication
public class ApiApplication {

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

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.feign.dubbo.example.api.service;

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

@FeignClient("provider")
public interface DemoHelloService {

@GetMapping("/hello")
String sayHello(@RequestParam("msg") String msg);

}
53 changes: 53 additions & 0 deletions multiple-rpc-demo/multiple-rpc-demo-consumer/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.feign.dubbo.exmple</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>com.feign.dubbo.example</groupId>
<artifactId>consumer</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>consumer</name>
<description>Demo project for Spring Boot</description>

<properties>
<java.version>1.8</java.version>
</properties>

<dependencies>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.feign.dubbo.example</groupId>
<artifactId>api</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.feign.dubbo.example.consumer;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;

@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients(basePackages = "com.feign.dubbo.example.api")
public class ConsumerApplication {

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

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.feign.dubbo.example.consumer.controller;

import com.feign.dubbo.example.api.service.DemoHelloService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ConsumerDemoController {

@Autowired
private DemoHelloService demoHelloService;

@GetMapping("/hello")
public String sayHello() {
return demoHelloService.sayHello("Hello World");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
spring.application.name=consumer

server.port=8081

spring.cloud.nacos.discovery.server-addr=localhost:8848

dubbo.application.name=consumer
dubbo.registry.address=nacos://localhost:8848
dubbo.scan.base-packages=com.feign.dubbo.example
dubbo.protocol.name=dubbo
dubbo.protocol.port=12345
dubbo.protocol.payload=16777216
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.feign.dubbo.example.consumer;

import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
class ConsumerApplicationTests {

@Test
void contextLoads() {
}

}
52 changes: 52 additions & 0 deletions multiple-rpc-demo/multiple-rpc-demo-provider/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.feign.dubbo.exmple</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>com.feign.dubbo.example</groupId>
<artifactId>provider</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>provider</name>
<description>Demo project for Spring Boot</description>

<properties>
<java.version>1.8</java.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.feign.dubbo.example</groupId>
<artifactId>api</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.feign.dubbo.example.provider;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;

@SpringBootApplication
@EnableFeignClients(basePackages = "com.feign.dubbo.example.api")
@EnableDiscoveryClient
public class ProviderApplication {

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

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.feign.dubbo.example.provider.service.impl;

import com.feign.dubbo.example.api.service.DemoHelloService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class DemoHelloServiceImpl implements DemoHelloService {

@Override
@GetMapping("/hello")
public String sayHello(String msg) {
return "hello" + msg;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
spring.application.name=provider

spring.cloud.nacos.discovery.server-addr=localhost:8848

dubbo.application.name=provider
dubbo.registry.address=nacos://localhost:8848
dubbo.scan.base-packages=com.feign.dubbo.example.provider.service.impl
dubbo.protocol.name=dubbo
dubbo.protocol.port=12346
dubbo.protocol.payload=16777216

dubbo.application.qos-enable=false
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.feign.dubbo.example.provider;

import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
class ProviderApplicationTests {

@Test
void contextLoads() {
}

}
Loading

0 comments on commit 9279394

Please sign in to comment.