Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
354 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>spring-boot-dubbo-annotation</artifactId> | ||
<groupId>com.rhwayfun</groupId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>dubbo-api</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
|
||
</project> |
11 changes: 11 additions & 0 deletions
11
...on/dubbo-api/src/main/java/com/rhwayfun/springboot/dubbo/annotation/api/DemoProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.rhwayfun.springboot.dubbo.annotation.api; | ||
|
||
/** | ||
* @author rhwayfun | ||
* @since 0.0.1 | ||
*/ | ||
public interface DemoProvider { | ||
|
||
String sayHello(String name); | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
...ubbo-api/src/main/java/com/rhwayfun/springboot/dubbo/annotation/api/DemoProviderMock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.rhwayfun.springboot.dubbo.annotation.api; | ||
|
||
/** | ||
* @author rhwayfun | ||
* @since 0.0.1 | ||
*/ | ||
public class DemoProviderMock implements DemoProvider { | ||
|
||
@Override | ||
public String sayHello(String name) { | ||
// 容错数据,此方法只在出现RpcException时被执行 | ||
return null; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>com.rhwayfun</groupId> | ||
<artifactId>spring-boot-dubbo-annotation</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>dubbo-consumer</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.rhwayfun</groupId> | ||
<artifactId>dubbo-api</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.rhwayfun</groupId> | ||
<artifactId>dubbo-provider</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.alibaba.boot</groupId> | ||
<artifactId>dubbo-spring-boot-starter</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.alibaba</groupId> | ||
<artifactId>dubbo</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.jacoco</groupId> | ||
<artifactId>jacoco-maven-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
17 changes: 17 additions & 0 deletions
17
...consumer/src/main/java/com/rhwayfun/springboot/dubbo/annotation/consumer/Application.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.rhwayfun.springboot.dubbo.annotation.consumer; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
/** | ||
* @author rhwayfun | ||
* @since 0.0.1 | ||
*/ | ||
@SpringBootApplication | ||
public class Application { | ||
|
||
public static void main(String[] args) throws InterruptedException { | ||
SpringApplication.run(Application.class, args); | ||
Thread.sleep(Long.MAX_VALUE); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...mer/src/main/java/com/rhwayfun/springboot/dubbo/annotation/consumer/config/AppConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.rhwayfun.springboot.dubbo.annotation.consumer.config; | ||
|
||
import org.springframework.context.annotation.Configuration; | ||
|
||
/** | ||
* @author rhwayfun | ||
* @since 0.0.1 | ||
*/ | ||
@Configuration | ||
public class AppConfig { | ||
} |
23 changes: 23 additions & 0 deletions
23
...src/main/java/com/rhwayfun/springboot/dubbo/annotation/consumer/service/DemoConsumer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.rhwayfun.springboot.dubbo.annotation.consumer.service; | ||
|
||
import com.alibaba.dubbo.config.annotation.Reference; | ||
import com.rhwayfun.springboot.dubbo.annotation.api.DemoProvider; | ||
import org.springframework.stereotype.Component; | ||
|
||
/** | ||
* @author rhwayfun | ||
* @since 0.0.1 | ||
*/ | ||
@Component | ||
public class DemoConsumer { | ||
|
||
@Reference(version = "1.0.0", | ||
application = "${dubbo.application.id}", | ||
url = "dubbo://localhost:20880") | ||
private DemoProvider demoProvider; | ||
|
||
public String sayHi(String name) { | ||
return demoProvider.sayHello(name); | ||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
spring-boot-dubbo-annotation/dubbo-consumer/src/main/resources/application.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Spring boot application | ||
spring.application.name=spring-boot-dubbo-annotation-consumer | ||
|
||
# Dubbo Config properties | ||
## ApplicationConfig Bean | ||
dubbo.application.id=spring-boot-dubbo-annotation-consumer | ||
dubbo.application.name=spring-boot-dubbo-annotation-consumer | ||
|
||
## ProtocolConfig Bean | ||
dubbo.protocol.id=dubbo | ||
dubbo.protocol.name=dubbo | ||
dubbo.protocol.port=20880 | ||
|
||
# Dubbo Endpoint (default status is disable) | ||
endpoints.dubbo.enabled=true | ||
|
||
# Dubbo Health | ||
## StatusChecker Name defaults (default : "memory", "load" ) | ||
management.health.dubbo.status.defaults=memory |
40 changes: 40 additions & 0 deletions
40
...o-consumer/src/test/java/com/rhwayfun/springboot/dubbo/annotation/consumer/DubboTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.rhwayfun.springboot.dubbo.annotation.consumer; | ||
|
||
import com.rhwayfun.springboot.dubbo.annotation.consumer.service.DemoConsumer; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.context.junit4.SpringRunner; | ||
|
||
import javax.annotation.Resource; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNull; | ||
|
||
/** | ||
* @author rhwayfun | ||
* @since 0.0.1 | ||
*/ | ||
@RunWith(SpringRunner.class) | ||
@SpringBootTest | ||
public class DubboTest { | ||
|
||
private static final String PARAM = "Dubbo"; | ||
|
||
@Resource | ||
private DemoConsumer demoConsumer; | ||
|
||
@Test | ||
public void testDubbo() throws Exception { | ||
String result = null; | ||
try { | ||
result = demoConsumer.sayHi(PARAM); | ||
if (result != null) { | ||
assertEquals("Hello " + PARAM, result); | ||
} | ||
} catch (Exception e) { | ||
assertNull(result); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>com.rhwayfun</groupId> | ||
<artifactId>spring-boot-dubbo-annotation</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>dubbo-provider</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.rhwayfun</groupId> | ||
<artifactId>dubbo-api</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.alibaba</groupId> | ||
<artifactId>dubbo</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.alibaba.boot</groupId> | ||
<artifactId>dubbo-spring-boot-starter</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.jacoco</groupId> | ||
<artifactId>jacoco-maven-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
17 changes: 17 additions & 0 deletions
17
...on/dubbo-provider/src/main/java/com/rhwayfun/springboot/dubbo/annotation/Application.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.rhwayfun.springboot.dubbo.annotation; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
/** | ||
* @author rhwayfun | ||
* @since 0.0.1 | ||
*/ | ||
@SpringBootApplication | ||
public class Application { | ||
|
||
public static void main(String[] args) throws InterruptedException { | ||
SpringApplication.run(Application.class, args); | ||
Thread.sleep(Long.MAX_VALUE); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...bbo-provider/src/main/java/com/rhwayfun/springboot/dubbo/annotation/config/AppConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.rhwayfun.springboot.dubbo.annotation.config; | ||
|
||
import org.springframework.context.annotation.Configuration; | ||
|
||
/** | ||
* @author rhwayfun | ||
* @since 0.0.1 | ||
*/ | ||
@Configuration | ||
public class AppConfig { | ||
} |
23 changes: 23 additions & 0 deletions
23
...der/src/main/java/com/rhwayfun/springboot/dubbo/annotation/provider/DemoProviderImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.rhwayfun.springboot.dubbo.annotation.provider; | ||
|
||
import com.alibaba.dubbo.config.annotation.Service; | ||
import com.rhwayfun.springboot.dubbo.annotation.api.DemoProvider; | ||
|
||
/** | ||
* @author rhwayfun | ||
* @since 0.0.1 | ||
*/ | ||
@Service( | ||
version = "1.0.0", | ||
application = "${dubbo.application.id}", | ||
protocol = "${dubbo.protocol.id}", | ||
registry = "${dubbo.registry.id}" | ||
) | ||
public class DemoProviderImpl implements DemoProvider { | ||
|
||
@Override | ||
public String sayHello(String name) { | ||
return "Hello " + name; | ||
} | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
spring-boot-dubbo-annotation/dubbo-provider/src/main/resources/application.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Spring boot application | ||
spring.application.name=spring-boot-dubbo-annotation-provider | ||
|
||
# Base packages to scan Dubbo Components (e.g., @Service, @Reference) | ||
dubbo.scan.basePackages=com.rhwayfun.springboot.dubbo.annotation.provider | ||
|
||
# Dubbo Config properties | ||
## ApplicationConfig Bean | ||
dubbo.application.id=spring-boot-dubbo-annotation-provider | ||
dubbo.application.name=spring-boot-dubbo-annotation-provider | ||
|
||
## ProtocolConfig Bean | ||
dubbo.protocol.id=dubbo | ||
dubbo.protocol.name=dubbo | ||
dubbo.protocol.port=20880 | ||
dubbo.protocol.status=server | ||
|
||
## RegistryConfig Bean | ||
dubbo.registry.id=my-registry | ||
dubbo.registry.address=N/A |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.