refactor dubbo examples & add datasource feature in example & update docs
parent
d1fd1f0e2f
commit
6598768195
@ -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.2.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-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>
|
7
spring-cloud-alibaba-examples/sentinel-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/dubbo/consumer/FooServiceConsumer.java → spring-cloud-alibaba-examples/sentinel-dubbo-consumer-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/FooServiceConsumer.java
7
spring-cloud-alibaba-examples/sentinel-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/dubbo/consumer/FooServiceConsumer.java → spring-cloud-alibaba-examples/sentinel-dubbo-consumer-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/FooServiceConsumer.java
45
spring-cloud-alibaba-examples/sentinel-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/dubbo/consumer/ConsumerApplication.java → spring-cloud-alibaba-examples/sentinel-dubbo-consumer-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/SentinelDubboConsumerApp.java
45
spring-cloud-alibaba-examples/sentinel-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/dubbo/consumer/ConsumerApplication.java → spring-cloud-alibaba-examples/sentinel-dubbo-consumer-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/SentinelDubboConsumerApp.java
@ -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,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-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-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,20 @@
|
||||
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
|
@ -0,0 +1,18 @@
|
||||
package org.springframework.cloud.alibaba.cloud.examples;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.csp.sentinel.datasource.ConfigParser;
|
||||
import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.TypeReference;
|
||||
|
||||
/**
|
||||
* @author fangjian
|
||||
*/
|
||||
public class JsonFlowRuleListParser implements ConfigParser<String, List<FlowRule>> {
|
||||
@Override
|
||||
public List<FlowRule> parse(String source) {
|
||||
return JSON.parseObject(source, new TypeReference<List<FlowRule>>() {});
|
||||
}
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
package org.springframework.cloud.alibaba.cloud.examples.dubbo;
|
||||
|
||||
import org.springframework.boot.Banner;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.WebApplicationType;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.cloud.alibaba.cloud.examples.dubbo.provider.ProviderApplication;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author fangjian
|
||||
*/
|
||||
@Component
|
||||
public class DubboProviderRunner implements CommandLineRunner {
|
||||
|
||||
@Override
|
||||
public void run(String... args) throws Exception {
|
||||
SpringApplicationBuilder providerBuilder = new SpringApplicationBuilder()
|
||||
.bannerMode(Banner.Mode.OFF).registerShutdownHook(false)
|
||||
.logStartupInfo(false).web(WebApplicationType.NONE);
|
||||
providerBuilder.sources(ProviderApplication.class).run(args);
|
||||
}
|
||||
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
package org.springframework.cloud.alibaba.cloud.examples.dubbo;
|
||||
|
||||
/**
|
||||
* @author fangjian
|
||||
*/
|
||||
public interface FooService {
|
||||
|
||||
String hello(String name);
|
||||
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
package org.springframework.cloud.alibaba.cloud.examples.dubbo.provider;
|
||||
|
||||
import org.springframework.cloud.alibaba.cloud.examples.dubbo.FooService;
|
||||
|
||||
import com.alibaba.dubbo.config.annotation.Service;
|
||||
|
||||
/**
|
||||
* @author fangjian
|
||||
*/
|
||||
@Service
|
||||
public class FooServiceImpl implements FooService {
|
||||
|
||||
@Override
|
||||
public String hello(String name) {
|
||||
return "hello, " + name;
|
||||
}
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
package org.springframework.cloud.alibaba.cloud.examples.dubbo.provider;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
import com.alibaba.dubbo.config.ApplicationConfig;
|
||||
import com.alibaba.dubbo.config.ProtocolConfig;
|
||||
import com.alibaba.dubbo.config.RegistryConfig;
|
||||
import com.alibaba.dubbo.config.spring.context.annotation.DubboComponentScan;
|
||||
|
||||
/**
|
||||
* @author fangjian
|
||||
*/
|
||||
@DubboComponentScan("org.springframework.cloud.alibaba.cloud.examples.dubbo.provider")
|
||||
public class ProviderApplication {
|
||||
|
||||
@Bean
|
||||
public ApplicationConfig applicationConfig() {
|
||||
ApplicationConfig applicationConfig = new ApplicationConfig();
|
||||
applicationConfig.setName("demo-provider");
|
||||
return applicationConfig;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public RegistryConfig registryConfig() {
|
||||
RegistryConfig registryConfig = new RegistryConfig();
|
||||
registryConfig.setAddress("multicast://224.5.6.7:1234");
|
||||
return registryConfig;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ProtocolConfig protocolConfig() {
|
||||
ProtocolConfig protocolConfig = new ProtocolConfig();
|
||||
protocolConfig.setName("dubbo");
|
||||
protocolConfig.setPort(25758);
|
||||
return protocolConfig;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue