add dubbo example in springboot 1.x and fix some typo
parent
4600f42647
commit
a50079bd75
@ -0,0 +1,30 @@
|
||||
<?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>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-alibaba-examples</artifactId>
|
||||
<version>0.1.0.BUILD-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
<artifactId>sentinel-dubbo-api</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<description>api for sentinel dubbo example</description>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-deploy-plugin</artifactId>
|
||||
<version>${maven-deploy-plugin.version}</version>
|
||||
<configuration>
|
||||
<skip>true</skip>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
@ -0,0 +1,10 @@
|
||||
package org.springframework.cloud.alibaba.cloud.examples;
|
||||
|
||||
/**
|
||||
* @author fangjian
|
||||
*/
|
||||
public interface FooService {
|
||||
|
||||
String hello(String name);
|
||||
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
<?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>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-alibaba-examples</artifactId>
|
||||
<version>0.2.0.BUILD-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
<artifactId>sentinel-dubbo-consumer-example</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<description>Example demonstrating how to use sentinel with dubbo</description>
|
||||
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>sentinel-dubbo-api</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba.boot</groupId>
|
||||
<artifactId>dubbo-spring-boot-starter</artifactId>
|
||||
<version>0.2.0</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-deploy-plugin</artifactId>
|
||||
<version>${maven-deploy-plugin.version}</version>
|
||||
<configuration>
|
||||
<skip>true</skip>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
@ -0,0 +1,17 @@
|
||||
package org.springframework.cloud.alibaba.cloud.examples;
|
||||
|
||||
import com.alibaba.dubbo.config.annotation.Reference;
|
||||
|
||||
/**
|
||||
* @author fangjian
|
||||
*/
|
||||
public class FooServiceConsumer {
|
||||
|
||||
@Reference(version = "${foo.service.version}", application = "${dubbo.application.id}", url = "dubbo://localhost:12345", timeout = 30000)
|
||||
private FooService fooService;
|
||||
|
||||
public String hello(String name) {
|
||||
return fooService.hello(name);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
package org.springframework.cloud.alibaba.cloud.examples;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import org.springframework.boot.WebApplicationType;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
import com.alibaba.csp.sentinel.slots.block.RuleConstant;
|
||||
import com.alibaba.csp.sentinel.slots.block.SentinelRpcException;
|
||||
import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
|
||||
import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager;
|
||||
|
||||
/**
|
||||
* @author fangjian
|
||||
*/
|
||||
@SpringBootApplication(scanBasePackages = "org.springframework.cloud.alibaba.cloud.examples")
|
||||
public class SentinelDubboConsumerApp {
|
||||
|
||||
@Bean
|
||||
public FooServiceConsumer annotationDemoServiceConsumer() {
|
||||
return new FooServiceConsumer();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
FlowRule flowRule = new FlowRule();
|
||||
flowRule.setResource(
|
||||
"org.springframework.cloud.alibaba.cloud.examples.FooService:hello(java.lang.String)");
|
||||
flowRule.setCount(10);
|
||||
flowRule.setGrade(RuleConstant.FLOW_GRADE_QPS);
|
||||
flowRule.setLimitApp("default");
|
||||
FlowRuleManager.loadRules(Collections.singletonList(flowRule));
|
||||
|
||||
SpringApplicationBuilder consumerBuilder = new SpringApplicationBuilder();
|
||||
ApplicationContext applicationContext = consumerBuilder
|
||||
.web(WebApplicationType.NONE).sources(SentinelDubboConsumerApp.class)
|
||||
.run(args);
|
||||
|
||||
FooServiceConsumer service = applicationContext.getBean(FooServiceConsumer.class);
|
||||
|
||||
for (int i = 0; i < 15; i++) {
|
||||
try {
|
||||
String message = service.hello("Jim");
|
||||
System.out.println((i + 1) + " -> Success: " + message);
|
||||
}
|
||||
catch (SentinelRpcException ex) {
|
||||
System.out.println("Blocked");
|
||||
}
|
||||
catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
spring.application.name = dubbo-consumer-demo
|
||||
|
||||
foo.service.version = 1.0.0
|
||||
|
||||
dubbo.application.id = dubbo-consumer-demo
|
||||
dubbo.application.name = dubbo-consumer-demo
|
||||
|
||||
dubbo.protocol.id = dubbo
|
||||
dubbo.protocol.name = dubbo
|
||||
dubbo.protocol.port = 12345
|
||||
|
@ -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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-alibaba-examples</artifactId>
|
||||
<version>0.2.0.BUILD-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
<artifactId>sentinel-dubbo-provider-example</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<description>Example demonstrating how to use sentinel with dubbo</description>
|
||||
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>sentinel-dubbo-api</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba.boot</groupId>
|
||||
<artifactId>dubbo-spring-boot-starter</artifactId>
|
||||
<version>0.2.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-deploy-plugin</artifactId>
|
||||
<version>${maven-deploy-plugin.version}</version>
|
||||
<configuration>
|
||||
<skip>true</skip>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
@ -0,0 +1,15 @@
|
||||
package org.springframework.cloud.alibaba.cloud.examples;
|
||||
|
||||
import com.alibaba.dubbo.config.annotation.Service;
|
||||
|
||||
/**
|
||||
* @author fangjian
|
||||
*/
|
||||
@Service(version = "${foo.service.version}", application = "${dubbo.application.id}", protocol = "${dubbo.protocol.id}", registry = "${dubbo.registry.id}")
|
||||
public class FooServiceImpl implements FooService {
|
||||
|
||||
@Override
|
||||
public String hello(String name) {
|
||||
return "hello, " + name;
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package org.springframework.cloud.alibaba.cloud.examples;
|
||||
|
||||
import org.springframework.boot.WebApplicationType;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
|
||||
/**
|
||||
* @author fangjian
|
||||
*/
|
||||
@SpringBootApplication
|
||||
public class SentinelDubboProviderApp {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplicationBuilder providerBuilder = new SpringApplicationBuilder();
|
||||
providerBuilder.web(WebApplicationType.NONE)
|
||||
.sources(SentinelDubboProviderApp.class).run(args);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
spring.application.name = dubbo-provider-demo
|
||||
|
||||
foo.service.version = 1.0.0
|
||||
|
||||
dubbo.scan.basePackages = org.springframework.cloud.alibaba.cloud.examples
|
||||
|
||||
dubbo.application.id = dubbo-provider-demo
|
||||
dubbo.application.name = dubbo-provider-demo
|
||||
|
||||
dubbo.protocol.id = dubbo
|
||||
dubbo.protocol.name = dubbo
|
||||
dubbo.protocol.port = 12345
|
||||
dubbo.protocol.status = server
|
||||
|
||||
dubbo.registry.id = my-registry
|
||||
dubbo.registry.address = N/A
|
Loading…
Reference in New Issue