You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by il...@apache.org on 2019/07/23 08:45:22 UTC

[dubbo-samples] branch master updated: add samples for sentinel

This is an automated email from the ASF dual-hosted git repository.

iluo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo-samples.git


The following commit(s) were added to refs/heads/master by this push:
     new 085275d  add samples for sentinel
085275d is described below

commit 085275d6b9d146a8dc7c6a3c703715ec545470ca
Author: Ian Luo <ia...@gmail.com>
AuthorDate: Tue Jul 23 16:42:59 2019 +0800

    add samples for sentinel
---
 dubbo-samples-sentinel/pom.xml                     | 239 +++++++++++++++++++++
 .../samples/sentinel/FooConsumerBootstrap.java     |  53 +++++
 .../samples/sentinel/FooProviderBootstrap.java     |  63 ++++++
 .../org/apache/samples/sentinel/FooService.java    |  25 +++
 .../sentinel/consumer/ConsumerConfiguration.java   |  61 ++++++
 .../sentinel/consumer/FooServiceConsumer.java      |  36 ++++
 .../samples/sentinel/provider/FooServiceImpl.java  |  38 ++++
 .../sentinel/provider/ProviderConfiguration.java   |  59 +++++
 .../org/apache/samples/sentinel/FooServiceIT.java  |  50 +++++
 pom.xml                                            |   1 +
 10 files changed, 625 insertions(+)

diff --git a/dubbo-samples-sentinel/pom.xml b/dubbo-samples-sentinel/pom.xml
new file mode 100644
index 0000000..78f082a
--- /dev/null
+++ b/dubbo-samples-sentinel/pom.xml
@@ -0,0 +1,239 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one or more
+  ~ contributor license agreements.  See the NOTICE file distributed with
+  ~ this work for additional information regarding copyright ownership.
+  ~ The ASF licenses this file to You under the Apache License, Version 2.0
+  ~ (the "License"); you may not use this file except in compliance with
+  ~ the License.  You may obtain a copy of the License at
+  ~
+  ~     http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing, software
+  ~ distributed under the License is distributed on an "AS IS" BASIS,
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~ See the License for the specific language governing permissions and
+  ~ limitations under the License.
+  -->
+
+<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>dubbo-samples-all</artifactId>
+        <groupId>org.apache.dubbo</groupId>
+        <version>1.0-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>dubbo-samples-sentinel</artifactId>
+
+    <properties>
+        <source.level>1.8</source.level>
+        <target.level>1.8</target.level>
+        <dubbo.version>2.7.4-SNAPSHOT</dubbo.version>
+        <sentinel.version>1.6.2</sentinel.version>
+        <junit.version>4.12</junit.version>
+        <spring.version>4.3.16.RELEASE</spring.version>
+        <docker-maven-plugin.version>0.30.0</docker-maven-plugin.version>
+        <jib-maven-plugin.version>1.2.0</jib-maven-plugin.version>
+        <maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
+        <maven-failsafe-plugin.version>2.21.0</maven-failsafe-plugin.version>
+        <image.name>${artifactId}:${dubbo.version}</image.name>
+        <java-image.name>openjdk:8</java-image.name>
+        <dubbo.port>20888</dubbo.port>
+        <zookeeper.port>2181</zookeeper.port>
+        <main-class>org.apache.samples.sentinel.FooProviderBootstrap</main-class>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.dubbo</groupId>
+            <artifactId>dubbo</artifactId>
+            <version>${dubbo.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.dubbo</groupId>
+            <artifactId>dubbo-dependencies-zookeeper</artifactId>
+            <version>${dubbo.version}</version>
+            <type>pom</type>
+        </dependency>
+
+        <dependency>
+            <groupId>com.alibaba.csp</groupId>
+            <artifactId>sentinel-apache-dubbo-adapter</artifactId>
+            <version>${sentinel.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>com.alibaba.csp</groupId>
+            <artifactId>sentinel-transport-simple-http</artifactId>
+            <version>${sentinel.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>${junit.version}</version>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-test</artifactId>
+            <version>${spring.version}</version>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+    <profiles>
+        <profile>
+            <id>dubbo-integration-test</id>
+            <build>
+                <plugins>
+                    <plugin>
+                        <groupId>org.apache.dubbo</groupId>
+                        <artifactId>dubbo-maven-address-plugin</artifactId>
+                        <version>1.0-SNAPSHOT</version>
+                        <executions>
+                            <execution>
+                                <goals>
+                                    <goal>local-address</goal>
+                                </goals>
+                                <configuration>
+                                    <localAddress>dubbo-local-address</localAddress>
+                                </configuration>
+                                <phase>initialize</phase>
+                            </execution>
+                        </executions>
+                    </plugin>
+
+                    <plugin>
+                        <groupId>com.google.cloud.tools</groupId>
+                        <artifactId>jib-maven-plugin</artifactId>
+                        <version>${jib-maven-plugin.version}</version>
+                        <configuration>
+                            <from>
+                                <image>${java-image.name}</image>
+                            </from>
+                            <to>
+                                <image>${image.name}</image>
+                            </to>
+                            <container>
+                                <mainClass>${main-class}</mainClass>
+                                <ports>
+                                    <port>${dubbo.port}</port>
+                                </ports>
+                                <environment>
+                                    <DUBBO_IP_TO_REGISTRY>${dubbo-local-address}</DUBBO_IP_TO_REGISTRY>
+                                </environment>
+                                <jvmFlags>
+                                    <jvmFlag>-Dzookeeper.address=${dubbo-local-address}</jvmFlag>
+                                    <jvmFlag>-Ddubbo.port=${dubbo.port}</jvmFlag>
+                                </jvmFlags>
+                            </container>
+                        </configuration>
+                        <executions>
+                            <execution>
+                                <phase>package</phase>
+                                <goals>
+                                    <goal>dockerBuild</goal>
+                                </goals>
+                            </execution>
+                        </executions>
+                    </plugin>
+
+                    <plugin>
+                        <groupId>io.fabric8</groupId>
+                        <artifactId>docker-maven-plugin</artifactId>
+                        <version>${docker-maven-plugin.version}</version>
+                        <configuration>
+                            <images>
+                                <image>
+                                    <name>zookeeper:latest</name>
+                                    <run>
+                                        <ports>
+                                            <port>${zookeeper.port}:${zookeeper.port}</port>
+                                        </ports>
+                                        <wait>
+                                            <tcp>
+                                                <host>${dubbo-local-address}</host>
+                                                <ports>
+                                                    <port>${zookeeper.port}</port>
+                                                </ports>
+                                            </tcp>
+                                        </wait>
+                                    </run>
+                                </image>
+                                <image>
+                                    <name>${image.name}</name>
+                                    <run>
+                                        <ports>
+                                            <port>${dubbo.port}:${dubbo.port}</port>
+                                        </ports>
+                                        <wait>
+                                            <log>dubbo service started</log>
+                                        </wait>
+                                    </run>
+                                </image>
+                            </images>
+                        </configuration>
+                        <executions>
+                            <execution>
+                                <id>start</id>
+                                <phase>pre-integration-test</phase>
+                                <goals>
+                                    <goal>start</goal>
+                                </goals>
+                            </execution>
+                            <execution>
+                                <id>stop</id>
+                                <phase>post-integration-test</phase>
+                                <goals>
+                                    <goal>stop</goal>
+                                </goals>
+                            </execution>
+                        </executions>
+                    </plugin>
+
+                    <plugin>
+                        <groupId>org.apache.maven.plugins</groupId>
+                        <artifactId>maven-failsafe-plugin</artifactId>
+                        <version>${maven-failsafe-plugin.version}</version>
+                        <executions>
+                            <execution>
+                                <goals>
+                                    <goal>integration-test</goal>
+                                    <goal>verify</goal>
+                                </goals>
+                                <configuration>
+                                    <systemPropertyVariables>
+                                        <zookeeper.address>${dubbo-local-address}</zookeeper.address>
+                                    </systemPropertyVariables>
+                                    <includes>
+                                        <include>**/*IT.java</include>
+                                    </includes>
+                                </configuration>
+                            </execution>
+                        </executions>
+                    </plugin>
+                </plugins>
+            </build>
+        </profile>
+    </profiles>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <version>${maven-compiler-plugin.version}</version>
+                <configuration>
+                    <source>${source.level}</source>
+                    <target>${target.level}</target>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+</project>
diff --git a/dubbo-samples-sentinel/src/main/java/org/apache/samples/sentinel/FooConsumerBootstrap.java b/dubbo-samples-sentinel/src/main/java/org/apache/samples/sentinel/FooConsumerBootstrap.java
new file mode 100644
index 0000000..c91464d
--- /dev/null
+++ b/dubbo-samples-sentinel/src/main/java/org/apache/samples/sentinel/FooConsumerBootstrap.java
@@ -0,0 +1,53 @@
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.samples.sentinel;
+
+import com.alibaba.csp.sentinel.slots.block.SentinelRpcException;
+import org.apache.samples.sentinel.consumer.ConsumerConfiguration;
+import org.apache.samples.sentinel.consumer.FooServiceConsumer;
+import org.springframework.context.annotation.AnnotationConfigApplicationContext;
+
+/**
+ * Please add the following VM arguments:
+ * <pre>
+ * -Dcsp.sentinel.api.port=8721
+ * -Dproject.name=dubbo-consumer-demo
+ * </pre>
+ */
+public class FooConsumerBootstrap {
+
+    public static void main(String[] args) {
+        AnnotationConfigApplicationContext consumerContext = new AnnotationConfigApplicationContext();
+        consumerContext.register(ConsumerConfiguration.class);
+        consumerContext.refresh();
+
+        FooServiceConsumer service = consumerContext.getBean(FooServiceConsumer.class);
+
+        for (int i = 0; i < 15; i++) {
+            try {
+                String message = service.sayHello("dubbo");
+                System.out.println("Success: " + message);
+            } catch (SentinelRpcException ex) {
+                System.out.println("Blocked");
+            } catch (Exception ex) {
+                ex.printStackTrace();
+            }
+        }
+    }
+}
diff --git a/dubbo-samples-sentinel/src/main/java/org/apache/samples/sentinel/FooProviderBootstrap.java b/dubbo-samples-sentinel/src/main/java/org/apache/samples/sentinel/FooProviderBootstrap.java
new file mode 100644
index 0000000..68b8a66
--- /dev/null
+++ b/dubbo-samples-sentinel/src/main/java/org/apache/samples/sentinel/FooProviderBootstrap.java
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.samples.sentinel;
+
+import com.alibaba.csp.sentinel.init.InitExecutor;
+import com.alibaba.csp.sentinel.slots.block.RuleConstant;
+import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
+import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager;
+import org.apache.samples.sentinel.provider.ProviderConfiguration;
+import org.springframework.context.annotation.AnnotationConfigApplicationContext;
+
+import java.util.Collections;
+import java.util.concurrent.CountDownLatch;
+
+/**
+ * Provider demo for Apache Dubbo 2.7.x or above. Please add the following VM arguments:
+ * <pre>
+ * -Dcsp.sentinel.api.port=8720
+ * -Dproject.name=dubbo-provider-demo
+ * </pre>
+ */
+public class FooProviderBootstrap {
+
+    private static final String INTERFACE_RES_KEY = FooService.class.getName();
+    private static final String RES_KEY = INTERFACE_RES_KEY + ":sayHello(java.lang.String)";
+
+    public static void main(String[] args) throws InterruptedException {
+        // Users don't need to manually call this method.
+        // Only for eager initialization.
+        InitExecutor.doInit();
+
+        initFlowRule();
+
+        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
+        context.register(ProviderConfiguration.class);
+        context.refresh();
+
+        System.out.println("dubbo service started");
+        new CountDownLatch(1).await();
+    }
+
+    private static void initFlowRule() {
+        FlowRule flowRule = new FlowRule(INTERFACE_RES_KEY)
+                .setCount(10)
+                .setGrade(RuleConstant.FLOW_GRADE_QPS);
+        FlowRuleManager.loadRules(Collections.singletonList(flowRule));
+    }
+}
diff --git a/dubbo-samples-sentinel/src/main/java/org/apache/samples/sentinel/FooService.java b/dubbo-samples-sentinel/src/main/java/org/apache/samples/sentinel/FooService.java
new file mode 100644
index 0000000..5c578ec
--- /dev/null
+++ b/dubbo-samples-sentinel/src/main/java/org/apache/samples/sentinel/FooService.java
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.samples.sentinel;
+
+public interface FooService {
+
+    String sayHello(String name);
+
+    String doAnother();
+}
diff --git a/dubbo-samples-sentinel/src/main/java/org/apache/samples/sentinel/consumer/ConsumerConfiguration.java b/dubbo-samples-sentinel/src/main/java/org/apache/samples/sentinel/consumer/ConsumerConfiguration.java
new file mode 100644
index 0000000..3ce2c38
--- /dev/null
+++ b/dubbo-samples-sentinel/src/main/java/org/apache/samples/sentinel/consumer/ConsumerConfiguration.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.samples.sentinel.consumer;
+
+import org.apache.dubbo.config.ApplicationConfig;
+import org.apache.dubbo.config.ConsumerConfig;
+import org.apache.dubbo.config.RegistryConfig;
+import org.apache.dubbo.config.spring.context.annotation.DubboComponentScan;
+
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+@DubboComponentScan
+public class ConsumerConfiguration {
+    @Value("zookeeper://${zookeeper.address:127.0.0.1}:2181")
+    private String zookeeperAddress;
+
+    @Bean
+    public ApplicationConfig applicationConfig() {
+        ApplicationConfig applicationConfig = new ApplicationConfig();
+        applicationConfig.setName("sentinel-demo-consumer");
+        return applicationConfig;
+    }
+
+    @Bean
+    public RegistryConfig registryConfig() {
+        RegistryConfig registryConfig = new RegistryConfig();
+        registryConfig.setAddress(zookeeperAddress);
+        return registryConfig;
+    }
+
+    @Bean
+    public ConsumerConfig consumerConfig() {
+        ConsumerConfig consumerConfig = new ConsumerConfig();
+        // Uncomment below line if you don't want to enable Sentinel for Dubbo service consumers.
+        // consumerConfig.setFilter("-sentinel.dubbo.consumer.filter");
+        return consumerConfig;
+    }
+
+    @Bean
+    public FooServiceConsumer annotationDemoServiceConsumer() {
+        return new FooServiceConsumer();
+    }
+}
diff --git a/dubbo-samples-sentinel/src/main/java/org/apache/samples/sentinel/consumer/FooServiceConsumer.java b/dubbo-samples-sentinel/src/main/java/org/apache/samples/sentinel/consumer/FooServiceConsumer.java
new file mode 100644
index 0000000..3b5f10d
--- /dev/null
+++ b/dubbo-samples-sentinel/src/main/java/org/apache/samples/sentinel/consumer/FooServiceConsumer.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.samples.sentinel.consumer;
+
+import org.apache.dubbo.config.annotation.Reference;
+
+import org.apache.samples.sentinel.FooService;
+
+public class FooServiceConsumer {
+
+    @Reference
+    private FooService fooService;
+
+    public String sayHello(String name) {
+        return fooService.sayHello(name);
+    }
+
+    public String doAnother() {
+        return fooService.doAnother();
+    }
+}
diff --git a/dubbo-samples-sentinel/src/main/java/org/apache/samples/sentinel/provider/FooServiceImpl.java b/dubbo-samples-sentinel/src/main/java/org/apache/samples/sentinel/provider/FooServiceImpl.java
new file mode 100644
index 0000000..ca9b1d0
--- /dev/null
+++ b/dubbo-samples-sentinel/src/main/java/org/apache/samples/sentinel/provider/FooServiceImpl.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.samples.sentinel.provider;
+
+import org.apache.dubbo.config.annotation.Service;
+
+import org.apache.samples.sentinel.FooService;
+
+import java.time.LocalDateTime;
+
+@Service
+public class FooServiceImpl implements FooService {
+
+    @Override
+    public String sayHello(String name) {
+        return String.format("Hello, %s at %s", name, LocalDateTime.now());
+    }
+
+    @Override
+    public String doAnother() {
+        return LocalDateTime.now().toString();
+    }
+}
diff --git a/dubbo-samples-sentinel/src/main/java/org/apache/samples/sentinel/provider/ProviderConfiguration.java b/dubbo-samples-sentinel/src/main/java/org/apache/samples/sentinel/provider/ProviderConfiguration.java
new file mode 100644
index 0000000..7139c01
--- /dev/null
+++ b/dubbo-samples-sentinel/src/main/java/org/apache/samples/sentinel/provider/ProviderConfiguration.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.samples.sentinel.provider;
+
+import org.apache.dubbo.config.ApplicationConfig;
+import org.apache.dubbo.config.ProtocolConfig;
+import org.apache.dubbo.config.RegistryConfig;
+import org.apache.dubbo.config.spring.context.annotation.DubboComponentScan;
+
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+@DubboComponentScan
+public class ProviderConfiguration {
+    @Value("zookeeper://${zookeeper.address:127.0.0.1}:2181")
+    private String zookeeperAddress;
+
+    @Value("${dubbo.port:20880}")
+    private int dubboPort;
+
+    @Bean
+    public ApplicationConfig applicationConfig() {
+        ApplicationConfig applicationConfig = new ApplicationConfig();
+        applicationConfig.setName("sentinel-demo-provider");
+        return applicationConfig;
+    }
+
+    @Bean
+    public RegistryConfig registryConfig() {
+        RegistryConfig registryConfig = new RegistryConfig();
+        registryConfig.setAddress(zookeeperAddress);
+        return registryConfig;
+    }
+
+    @Bean
+    public ProtocolConfig protocolConfig() {
+        ProtocolConfig protocolConfig = new ProtocolConfig();
+        protocolConfig.setName("dubbo");
+        protocolConfig.setPort(dubboPort);
+        return protocolConfig;
+    }
+}
diff --git a/dubbo-samples-sentinel/src/test/java/org/apache/samples/sentinel/FooServiceIT.java b/dubbo-samples-sentinel/src/test/java/org/apache/samples/sentinel/FooServiceIT.java
new file mode 100644
index 0000000..08c9eba
--- /dev/null
+++ b/dubbo-samples-sentinel/src/test/java/org/apache/samples/sentinel/FooServiceIT.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.samples.sentinel;
+
+import org.apache.dubbo.rpc.RpcException;
+
+import org.apache.samples.sentinel.consumer.ConsumerConfiguration;
+import org.apache.samples.sentinel.consumer.FooServiceConsumer;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(classes = {ConsumerConfiguration.class})
+public class FooServiceIT {
+    @Autowired
+    private FooServiceConsumer consumer;
+
+    @Test
+    public void testFlowControl1() throws Exception {
+        for (int i = 0; i < 10; i++) {
+            consumer.sayHello("dubbo");
+        }
+    }
+
+    // FIXME: I think here sentinel's FlowException is expected.
+    @Test(expected = RpcException.class)
+    public void testFlowControl2() throws Exception {
+        for (int i = 0; i < 11; i++) {
+            consumer.sayHello("dubbo");
+        }
+    }
+}
diff --git a/pom.xml b/pom.xml
index c5a76c7..6d1f93b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -73,6 +73,7 @@
         <module>dubbo-samples-metrics</module>
         <module>dubbo-samples-environment-keys</module>
         <module>dubbo-samples-serialization</module>
+        <module>dubbo-samples-sentinel</module>
     </modules>
 
     <repositories>


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org