Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
武汉红喜
whatsmars
提交
114a8c45
W
whatsmars
项目概览
武汉红喜
/
whatsmars
通知
3
Star
0
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
W
whatsmars
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
114a8c45
编写于
2月 08, 2019
作者:
武汉红喜
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Upgrade to dubbo 2.7.0, remove whatsmars-dubbo-sentinel,whatsmars-dubbo-service
上级
a29ff9de
变更
36
隐藏空白更改
内联
并排
Showing
36 changed file
with
36 addition
and
801 deletion
+36
-801
pom.xml
pom.xml
+2
-14
whatsmars-dubbo/pom.xml
whatsmars-dubbo/pom.xml
+0
-14
whatsmars-dubbo/whatsmars-dubbo-consumer-boot/pom.xml
whatsmars-dubbo/whatsmars-dubbo-consumer-boot/pom.xml
+0
-4
whatsmars-dubbo/whatsmars-dubbo-consumer/pom.xml
whatsmars-dubbo/whatsmars-dubbo-consumer/pom.xml
+2
-25
whatsmars-dubbo/whatsmars-dubbo-consumer/src/main/java/org/hongxi/whatsmars/dubbo/demo/consumer/AsyncConsumer.java
...g/hongxi/whatsmars/dubbo/demo/consumer/AsyncConsumer.java
+1
-1
whatsmars-dubbo/whatsmars-dubbo-consumer/src/main/java/org/hongxi/whatsmars/dubbo/demo/consumer/AsyncConsumer2.java
.../hongxi/whatsmars/dubbo/demo/consumer/AsyncConsumer2.java
+1
-1
whatsmars-dubbo/whatsmars-dubbo-consumer/src/main/java/org/hongxi/whatsmars/dubbo/demo/consumer/DemoConsumer.java
...rg/hongxi/whatsmars/dubbo/demo/consumer/DemoConsumer.java
+5
-5
whatsmars-dubbo/whatsmars-dubbo-consumer/src/main/resources/META-INF/spring/dubbo-demo-consumer.xml
...rc/main/resources/META-INF/spring/dubbo-demo-consumer.xml
+2
-3
whatsmars-dubbo/whatsmars-dubbo-consumer/src/test/java/org/hongxi/whatsmars/dubbo/demo/consumer/Consumer.java
...va/org/hongxi/whatsmars/dubbo/demo/consumer/Consumer.java
+3
-3
whatsmars-dubbo/whatsmars-dubbo-provider-boot/pom.xml
whatsmars-dubbo/whatsmars-dubbo-provider-boot/pom.xml
+1
-10
whatsmars-dubbo/whatsmars-dubbo-provider-boot/src/main/java/org/hongxi/whatsmars/dubbo/demo/provider/ProviderApplication.java
...xi/whatsmars/dubbo/demo/provider/ProviderApplication.java
+0
-2
whatsmars-dubbo/whatsmars-dubbo-provider-boot/src/main/java/org/hongxi/whatsmars/dubbo/demo/provider/service/DemoServiceImpl.java
...hatsmars/dubbo/demo/provider/service/DemoServiceImpl.java
+1
-7
whatsmars-dubbo/whatsmars-dubbo-provider-boot/src/main/java/org/hongxi/whatsmars/dubbo/demo/provider/service/OtherServiceImpl.java
...atsmars/dubbo/demo/provider/service/OtherServiceImpl.java
+1
-7
whatsmars-dubbo/whatsmars-dubbo-provider-boot/src/main/resources/application.yml
...rs-dubbo-provider-boot/src/main/resources/application.yml
+0
-8
whatsmars-dubbo/whatsmars-dubbo-provider/pom.xml
whatsmars-dubbo/whatsmars-dubbo-provider/pom.xml
+2
-22
whatsmars-dubbo/whatsmars-dubbo-provider/src/main/java/org/hongxi/whatsmars/dubbo/demo/provider/BarServiceMock.java
.../hongxi/whatsmars/dubbo/demo/provider/BarServiceMock.java
+0
-13
whatsmars-dubbo/whatsmars-dubbo-provider/src/main/java/org/hongxi/whatsmars/dubbo/demo/provider/DemoProvider.java
...rg/hongxi/whatsmars/dubbo/demo/provider/DemoProvider.java
+1
-1
whatsmars-dubbo/whatsmars-dubbo-provider/src/main/java/org/hongxi/whatsmars/dubbo/demo/provider/DemoServiceImpl.java
...hongxi/whatsmars/dubbo/demo/provider/DemoServiceImpl.java
+2
-8
whatsmars-dubbo/whatsmars-dubbo-provider/src/main/java/org/hongxi/whatsmars/dubbo/demo/provider/DemoServiceImpl2.java
...ongxi/whatsmars/dubbo/demo/provider/DemoServiceImpl2.java
+6
-1
whatsmars-dubbo/whatsmars-dubbo-provider/src/main/resources/META-INF/spring/dubbo-demo-provider.xml
...rc/main/resources/META-INF/spring/dubbo-demo-provider.xml
+2
-3
whatsmars-dubbo/whatsmars-dubbo-provider/src/test/java/org/hongxi/whatsmars/dubbo/demo/provider/Provider.java
...va/org/hongxi/whatsmars/dubbo/demo/provider/Provider.java
+4
-4
whatsmars-dubbo/whatsmars-dubbo-sentinel/pom.xml
whatsmars-dubbo/whatsmars-dubbo-sentinel/pom.xml
+0
-42
whatsmars-dubbo/whatsmars-dubbo-sentinel/src/main/java/org/hongxi/whatsmars/dubbo/sentinel/FooService.java
.../java/org/hongxi/whatsmars/dubbo/sentinel/FooService.java
+0
-25
whatsmars-dubbo/whatsmars-dubbo-sentinel/src/main/java/org/hongxi/whatsmars/dubbo/sentinel/consumer/ConsumerConfiguration.java
...tsmars/dubbo/sentinel/consumer/ConsumerConfiguration.java
+0
-57
whatsmars-dubbo/whatsmars-dubbo-sentinel/src/main/java/org/hongxi/whatsmars/dubbo/sentinel/consumer/FooServiceConsumer.java
...whatsmars/dubbo/sentinel/consumer/FooServiceConsumer.java
+0
-36
whatsmars-dubbo/whatsmars-dubbo-sentinel/src/main/java/org/hongxi/whatsmars/dubbo/sentinel/demo1/FooConsumerBootstrap.java
.../whatsmars/dubbo/sentinel/demo1/FooConsumerBootstrap.java
+0
-53
whatsmars-dubbo/whatsmars-dubbo-sentinel/src/main/java/org/hongxi/whatsmars/dubbo/sentinel/demo1/FooProviderBootstrap.java
.../whatsmars/dubbo/sentinel/demo1/FooProviderBootstrap.java
+0
-62
whatsmars-dubbo/whatsmars-dubbo-sentinel/src/main/java/org/hongxi/whatsmars/dubbo/sentinel/demo1/FooServiceImpl.java
...hongxi/whatsmars/dubbo/sentinel/demo1/FooServiceImpl.java
+0
-38
whatsmars-dubbo/whatsmars-dubbo-sentinel/src/main/java/org/hongxi/whatsmars/dubbo/sentinel/demo1/ProviderConfiguration.java
...whatsmars/dubbo/sentinel/demo1/ProviderConfiguration.java
+0
-53
whatsmars-dubbo/whatsmars-dubbo-sentinel/src/main/java/org/hongxi/whatsmars/dubbo/sentinel/demo2/FooConsumerBootstrap.java
.../whatsmars/dubbo/sentinel/demo2/FooConsumerBootstrap.java
+0
-95
whatsmars-dubbo/whatsmars-dubbo-sentinel/src/main/java/org/hongxi/whatsmars/dubbo/sentinel/demo2/FooProviderBootstrap.java
.../whatsmars/dubbo/sentinel/demo2/FooProviderBootstrap.java
+0
-43
whatsmars-dubbo/whatsmars-dubbo-sentinel/src/main/java/org/hongxi/whatsmars/dubbo/sentinel/demo2/FooServiceImpl.java
...hongxi/whatsmars/dubbo/sentinel/demo2/FooServiceImpl.java
+0
-38
whatsmars-dubbo/whatsmars-dubbo-sentinel/src/main/java/org/hongxi/whatsmars/dubbo/sentinel/demo2/ProviderConfiguration.java
...whatsmars/dubbo/sentinel/demo2/ProviderConfiguration.java
+0
-53
whatsmars-dubbo/whatsmars-dubbo-service/pom.xml
whatsmars-dubbo/whatsmars-dubbo-service/pom.xml
+0
-25
whatsmars-dubbo/whatsmars-dubbo-service/src/main/java/org/hongxi/whatsmars/dubbo/service/UserService.java
.../java/org/hongxi/whatsmars/dubbo/service/UserService.java
+0
-9
whatsmars-dubbo/whatsmars-dubbo-service/src/main/java/org/hongxi/whatsmars/dubbo/service/impl/UserServiceImpl.java
.../hongxi/whatsmars/dubbo/service/impl/UserServiceImpl.java
+0
-16
未找到文件。
pom.xml
浏览文件 @
114a8c45
...
...
@@ -41,7 +41,7 @@
<mybatis-spring.version>
1.3.1
</mybatis-spring.version>
<mybatis.version>
3.4.5
</mybatis.version>
<dubbo.version>
2.
6.4
</dubbo.version>
<dubbo.version>
2.
7.0
</dubbo.version>
<rocketmq.version>
4.3.2
</rocketmq.version>
<guava.version>
20.0
</guava.version>
...
...
@@ -54,8 +54,6 @@
<commons-dbcp.version>
1.4
</commons-dbcp.version>
<fastjson.version>
1.2.44
</fastjson.version>
<swagger2.version>
2.5.0
</swagger2.version>
<jetty_version>
6.1.26
</jetty_version>
<hessian.version>
4.0.7
</hessian.version>
<zkclient.version>
0.9
</zkclient.version>
<curator.version>
2.12.0
</curator.version>
<javassist.version>
3.24.1-GA
</javassist.version>
...
...
@@ -73,7 +71,7 @@
</dependency>
<dependency>
<groupId>
com.alibaba
</groupId>
<groupId>
org.apache.dubbo
</groupId>
<artifactId>
dubbo
</artifactId>
<version>
${dubbo.version}
</version>
</dependency>
...
...
@@ -144,16 +142,6 @@
<artifactId>
springfox-swagger-ui
</artifactId>
<version>
${swagger2.version}
</version>
</dependency>
<dependency>
<groupId>
org.mortbay.jetty
</groupId>
<artifactId>
jetty
</artifactId>
<version>
${jetty_version}
</version>
</dependency>
<dependency>
<groupId>
com.caucho
</groupId>
<artifactId>
hessian
</artifactId>
<version>
${hessian.version}
</version>
</dependency>
<dependency>
<groupId>
com.101tec
</groupId>
<artifactId>
zkclient
</artifactId>
...
...
whatsmars-dubbo/pom.xml
浏览文件 @
114a8c45
...
...
@@ -21,13 +21,10 @@
<module>
whatsmars-dubbo-provider
</module>
<module>
whatsmars-dubbo-provider-boot
</module>
<module>
whatsmars-dubbo-consumer-boot
</module>
<module>
whatsmars-dubbo-service
</module>
<module>
whatsmars-dubbo-sentinel
</module>
</modules>
<properties>
<dubbo-boot.version>
0.2.0
</dubbo-boot.version>
<sentinel.version>
1.3.0-GA
</sentinel.version>
</properties>
<dependencyManagement>
...
...
@@ -37,17 +34,6 @@
<artifactId>
dubbo-spring-boot-starter
</artifactId>
<version>
${dubbo-boot.version}
</version>
</dependency>
<dependency>
<groupId>
com.alibaba.csp
</groupId>
<artifactId>
sentinel-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>
</dependencies>
</dependencyManagement>
...
...
whatsmars-dubbo/whatsmars-dubbo-consumer-boot/pom.xml
浏览文件 @
114a8c45
...
...
@@ -20,10 +20,6 @@
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-actuator
</artifactId>
</dependency>
<dependency>
<groupId>
com.alibaba.boot
</groupId>
<artifactId>
dubbo-spring-boot-starter
</artifactId>
...
...
whatsmars-dubbo/whatsmars-dubbo-consumer/pom.xml
浏览文件 @
114a8c45
...
...
@@ -15,10 +15,6 @@
<name>
${project.artifactId}
</name>
<description>
The demo consumer module of dubbo project
</description>
<properties>
<skip_maven_deploy>
false
</skip_maven_deploy>
</properties>
<dependencies>
<dependency>
<groupId>
org.hongxi
</groupId>
...
...
@@ -26,7 +22,7 @@
<version>
${project.version}
</version>
</dependency>
<dependency>
<groupId>
com.alibaba
</groupId>
<groupId>
org.apache.dubbo
</groupId>
<artifactId>
dubbo
</artifactId>
</dependency>
<dependency>
...
...
@@ -35,7 +31,7 @@
</dependency>
<dependency>
<groupId>
org.apache.curator
</groupId>
<artifactId>
curator-
framework
</artifactId>
<artifactId>
curator-
recipes
</artifactId>
</dependency>
<dependency>
...
...
@@ -51,30 +47,11 @@
<artifactId>
commons-lang3
</artifactId>
</dependency>
<!-- for hessian protocol -->
<dependency>
<groupId>
com.caucho
</groupId>
<artifactId>
hessian
</artifactId>
</dependency>
<dependency>
<groupId>
org.mortbay.jetty
</groupId>
<artifactId>
jetty
</artifactId>
</dependency>
<!-- netty4 -->
<dependency>
<groupId>
io.netty
</groupId>
<artifactId>
netty-all
</artifactId>
</dependency>
<dependency>
<groupId>
com.alibaba.csp
</groupId>
<artifactId>
sentinel-dubbo-adapter
</artifactId>
</dependency>
<dependency>
<groupId>
com.alibaba.csp
</groupId>
<artifactId>
sentinel-transport-simple-http
</artifactId>
</dependency>
</dependencies>
<build>
...
...
whatsmars-dubbo/whatsmars-dubbo-consumer/src/main/java/org/hongxi/whatsmars/dubbo/demo/consumer/AsyncConsumer.java
浏览文件 @
114a8c45
...
...
@@ -3,7 +3,7 @@
*/
package
org.hongxi.whatsmars.dubbo.demo.consumer
;
import
com.alibaba
.dubbo.rpc.RpcContext
;
import
org.apache
.dubbo.rpc.RpcContext
;
import
org.hongxi.whatsmars.dubbo.demo.api.BarService
;
import
org.hongxi.whatsmars.dubbo.demo.api.DemoService
;
import
org.hongxi.whatsmars.dubbo.demo.api.vo.Bar
;
...
...
whatsmars-dubbo/whatsmars-dubbo-consumer/src/main/java/org/hongxi/whatsmars/dubbo/demo/consumer/AsyncConsumer2.java
浏览文件 @
114a8c45
...
...
@@ -3,7 +3,7 @@
*/
package
org.hongxi.whatsmars.dubbo.demo.consumer
;
import
com.alibaba
.dubbo.rpc.RpcContext
;
import
org.apache
.dubbo.rpc.RpcContext
;
import
org.hongxi.whatsmars.dubbo.demo.api.DemoService
;
import
org.springframework.context.support.ClassPathXmlApplicationContext
;
...
...
whatsmars-dubbo/whatsmars-dubbo-consumer/src/main/java/org/hongxi/whatsmars/dubbo/demo/consumer/DemoConsumer.java
浏览文件 @
114a8c45
...
...
@@ -3,7 +3,7 @@
*/
package
org.hongxi.whatsmars.dubbo.demo.consumer
;
import
com.alibaba
.dubbo.rpc.service.EchoService
;
import
org.apache
.dubbo.rpc.service.EchoService
;
import
org.hongxi.whatsmars.dubbo.demo.api.DemoService
;
import
org.springframework.context.support.ClassPathXmlApplicationContext
;
...
...
@@ -24,13 +24,13 @@ public class DemoConsumer {
// hessian protocol 直连
DemoService
demoService2
=
(
DemoService
)
context
.
getBean
(
"demoService2"
);
String
hello2
=
demoService2
.
sayHello
(
"
hessian
直连"
);
String
hello2
=
demoService2
.
sayHello
(
"
dubbo
直连"
);
System
.
out
.
println
(
hello2
);
// hessian protocol
DemoService
demoService3
=
(
DemoService
)
context
.
getBean
(
"demoService3"
);
String
hello3
=
demoService3
.
sayHello
(
"hessian"
);
System
.
out
.
println
(
hello3
);
//
DemoService demoService3 = (DemoService) context.getBean("demoService3");
//
String hello3 = demoService3.sayHello("hessian");
//
System.out.println(hello3);
// service group
DemoService
demoService4
=
(
DemoService
)
context
.
getBean
(
"demoService4"
);
...
...
whatsmars-dubbo/whatsmars-dubbo-consumer/src/main/resources/META-INF/spring/dubbo-demo-consumer.xml
浏览文件 @
114a8c45
...
...
@@ -14,12 +14,11 @@
<dubbo:reference
id=
"demoService"
interface=
"org.hongxi.whatsmars.dubbo.demo.api.DemoService"
mock=
"return null"
/>
<!-- url="hessian://127.0.0.1:8080/org.hongxi.whatsmars.dubbo.demo.api.DemoService" -->
<dubbo:reference
id=
"demoService2"
interface=
"org.hongxi.whatsmars.dubbo.demo.api.DemoService"
url=
"
hessian://127.0.0.1:80
80"
/>
url=
"
dubbo://127.0.0.1:208
80"
/>
<!--protocol默认dubbo,可指定,如果provider没有以该protocol发布,consumer启动会报 No provider-->
<
dubbo:reference
id=
"demoService3"
interface=
"org.hongxi.whatsmars.dubbo.demo.api.DemoService"
protocol=
"hessian"
/
>
<
!--<dubbo:reference id="demoService3" interface="org.hongxi.whatsmars.dubbo.demo.api.DemoService" protocol="hessian" />--
>
<dubbo:reference
id=
"demoService4"
group=
"new"
interface=
"org.hongxi.whatsmars.dubbo.demo.api.DemoService"
/>
...
...
whatsmars-dubbo/whatsmars-dubbo-consumer/src/test/java/org/hongxi/whatsmars/dubbo/demo/consumer/Consumer.java
浏览文件 @
114a8c45
package
org.hongxi.whatsmars.dubbo.demo.consumer
;
import
com.alibaba
.dubbo.config.ApplicationConfig
;
import
com.alibaba
.dubbo.config.ReferenceConfig
;
import
com.alibaba
.dubbo.config.RegistryConfig
;
import
org.apache
.dubbo.config.ApplicationConfig
;
import
org.apache
.dubbo.config.ReferenceConfig
;
import
org.apache
.dubbo.config.RegistryConfig
;
import
org.hongxi.whatsmars.dubbo.demo.api.DemoService
;
public
class
Consumer
{
...
...
whatsmars-dubbo/whatsmars-dubbo-provider-boot/pom.xml
浏览文件 @
114a8c45
...
...
@@ -18,11 +18,7 @@
<dependencies>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-web
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-actuator
</artifactId>
<artifactId>
spring-boot-starter
</artifactId>
</dependency>
<dependency>
<groupId>
com.alibaba.boot
</groupId>
...
...
@@ -38,11 +34,6 @@
<artifactId>
whatsmars-dubbo-api
</artifactId>
<version>
${project.version}
</version>
</dependency>
<dependency>
<groupId>
org.hongxi
</groupId>
<artifactId>
whatsmars-dubbo-service
</artifactId>
<version>
${project.version}
</version>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
...
...
whatsmars-dubbo/whatsmars-dubbo-provider-boot/src/main/java/org/hongxi/whatsmars/dubbo/demo/provider/ProviderApplication.java
浏览文件 @
114a8c45
...
...
@@ -2,13 +2,11 @@ package org.hongxi.whatsmars.dubbo.demo.provider;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.context.annotation.ComponentScan
;
/**
* Created by javahongxi on 2017/12/4.
*/
@SpringBootApplication
@ComponentScan
(
value
=
{
"org.hongxi.whatsmars.dubbo"
})
public
class
ProviderApplication
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
SpringApplication
.
run
(
ProviderApplication
.
class
,
args
);
...
...
whatsmars-dubbo/whatsmars-dubbo-provider-boot/src/main/java/org/hongxi/whatsmars/dubbo/demo/provider/service/DemoServiceImpl.java
浏览文件 @
114a8c45
...
...
@@ -6,8 +6,6 @@ package org.hongxi.whatsmars.dubbo.demo.provider.service;
import
com.alibaba.dubbo.config.annotation.Service
;
import
com.alibaba.dubbo.rpc.RpcContext
;
import
org.hongxi.whatsmars.dubbo.demo.api.DemoService
;
import
org.hongxi.whatsmars.dubbo.service.UserService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
...
...
@@ -15,13 +13,9 @@ import java.util.Date;
@Service
public
class
DemoServiceImpl
implements
DemoService
{
@Autowired
private
UserService
userService
;
public
String
sayHello
(
String
name
)
{
boolean
registerSuccess
=
userService
.
register
(
name
);
System
.
out
.
println
(
"["
+
new
SimpleDateFormat
(
"HH:mm:ss"
).
format
(
new
Date
())
+
"] Hello "
+
name
+
", request from consumer: "
+
RpcContext
.
getContext
().
getRemoteAddress
());
return
"Hello "
+
name
+
", re
gisterSuccess:"
+
registerSuccess
+
", re
sponse form provider: "
+
RpcContext
.
getContext
().
getLocalAddress
();
return
"Hello "
+
name
+
", response form provider: "
+
RpcContext
.
getContext
().
getLocalAddress
();
}
}
\ No newline at end of file
whatsmars-dubbo/whatsmars-dubbo-provider-boot/src/main/java/org/hongxi/whatsmars/dubbo/demo/provider/service/OtherServiceImpl.java
浏览文件 @
114a8c45
...
...
@@ -6,8 +6,6 @@ package org.hongxi.whatsmars.dubbo.demo.provider.service;
import
com.alibaba.dubbo.config.annotation.Service
;
import
com.alibaba.dubbo.rpc.RpcContext
;
import
org.hongxi.whatsmars.dubbo.demo.api.OtherService
;
import
org.hongxi.whatsmars.dubbo.service.UserService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
...
...
@@ -15,13 +13,9 @@ import java.util.Date;
@Service
(
registry
=
"otherRegistry"
)
public
class
OtherServiceImpl
implements
OtherService
{
@Autowired
private
UserService
userService
;
public
String
sayHello
(
String
name
)
{
boolean
registerSuccess
=
userService
.
register
(
name
);
System
.
out
.
println
(
"["
+
new
SimpleDateFormat
(
"HH:mm:ss"
).
format
(
new
Date
())
+
"] Hello "
+
name
+
", request from consumer: "
+
RpcContext
.
getContext
().
getRemoteAddress
());
return
"H
ello "
+
name
+
", registerSuccess:"
+
registerSuccess
+
", response form provider: "
+
RpcContext
.
getContext
().
getLocalAddress
();
return
"H
i "
+
name
+
", response form provider: "
+
RpcContext
.
getContext
().
getLocalAddress
();
}
}
\ No newline at end of file
whatsmars-dubbo/whatsmars-dubbo-provider-boot/src/main/resources/application.yml
浏览文件 @
114a8c45
...
...
@@ -20,14 +20,6 @@ dubbo:
scan
:
basePackages
:
org.hongxi.whatsmars.dubbo.demo.provider.service
endpoints
:
dubbo
:
enabled
:
true
management
:
port
:
9091
security
:
enabled
:
false
registry
:
other
:
protocol
:
zookeeper
...
...
whatsmars-dubbo/whatsmars-dubbo-provider/pom.xml
浏览文件 @
114a8c45
...
...
@@ -15,10 +15,6 @@
<name>
${project.artifactId}
</name>
<description>
The demo provider module of dubbo project
</description>
<properties>
<skip_maven_deploy>
false
</skip_maven_deploy>
</properties>
<dependencies>
<dependency>
<groupId>
org.hongxi
</groupId>
...
...
@@ -26,7 +22,7 @@
<version>
${project.version}
</version>
</dependency>
<dependency>
<groupId>
com.alibaba
</groupId>
<groupId>
org.apache.dubbo
</groupId>
<artifactId>
dubbo
</artifactId>
</dependency>
<dependency>
...
...
@@ -35,7 +31,7 @@
</dependency>
<dependency>
<groupId>
org.apache.curator
</groupId>
<artifactId>
curator-
framework
</artifactId>
<artifactId>
curator-
recipes
</artifactId>
</dependency>
<dependency>
...
...
@@ -51,27 +47,11 @@
<artifactId>
commons-lang3
</artifactId>
</dependency>
<!-- for hessian protocol -->
<dependency>
<groupId>
com.caucho
</groupId>
<artifactId>
hessian
</artifactId>
</dependency>
<dependency>
<groupId>
org.mortbay.jetty
</groupId>
<artifactId>
jetty
</artifactId>
</dependency>
<!-- netty4 -->
<dependency>
<groupId>
io.netty
</groupId>
<artifactId>
netty-all
</artifactId>
</dependency>
<dependency>
<groupId>
org.hongxi
</groupId>
<artifactId>
whatsmars-dubbo-service
</artifactId>
<version>
${project.version}
</version>
</dependency>
</dependencies>
<build>
...
...
whatsmars-dubbo/whatsmars-dubbo-provider/src/main/java/org/hongxi/whatsmars/dubbo/demo/provider/BarServiceMock.java
已删除
100644 → 0
浏览文件 @
a29ff9de
package
org.hongxi.whatsmars.dubbo.demo.provider
;
import
org.hongxi.whatsmars.dubbo.demo.api.BarService
;
import
org.hongxi.whatsmars.dubbo.demo.api.vo.Bar
;
public
class
BarServiceMock
implements
BarService
{
@Override
public
Bar
findBar
(
String
barId
)
{
// 你可以伪造容错数据,此方法只在出现RpcException时被执行
return
new
Bar
(
""
,
"容错数据"
,
""
);
}
}
\ No newline at end of file
whatsmars-dubbo/whatsmars-dubbo-provider/src/main/java/org/hongxi/whatsmars/dubbo/demo/provider/DemoProvider.java
浏览文件 @
114a8c45
...
...
@@ -12,7 +12,7 @@ public class DemoProvider {
//Prevent to get IPV6 address,this way only work in debug mode
//But you can pass use -Djava.net.preferIPv4Stack=true,then it work well whether in debug mode or not
System
.
setProperty
(
"java.net.preferIPv4Stack"
,
"true"
);
com
.
alibaba
.
dubbo
.
container
.
Main
.
main
(
args
);
org
.
apache
.
dubbo
.
container
.
Main
.
main
(
args
);
}
...
...
whatsmars-dubbo/whatsmars-dubbo-provider/src/main/java/org/hongxi/whatsmars/dubbo/demo/provider/DemoServiceImpl.java
浏览文件 @
114a8c45
...
...
@@ -3,10 +3,8 @@
*/
package
org.hongxi.whatsmars.dubbo.demo.provider
;
import
com.alibaba
.dubbo.rpc.RpcContext
;
import
org.apache
.dubbo.rpc.RpcContext
;
import
org.hongxi.whatsmars.dubbo.demo.api.DemoService
;
import
org.hongxi.whatsmars.dubbo.service.UserService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.text.SimpleDateFormat
;
...
...
@@ -15,13 +13,9 @@ import java.util.Date;
@Service
(
"demoService"
)
public
class
DemoServiceImpl
implements
DemoService
{
@Autowired
private
UserService
userService
;
public
String
sayHello
(
String
name
)
{
boolean
registerSuccess
=
userService
.
register
(
name
);
System
.
out
.
println
(
"["
+
new
SimpleDateFormat
(
"HH:mm:ss"
).
format
(
new
Date
())
+
"] Hello "
+
name
+
", request from consumer: "
+
RpcContext
.
getContext
().
getRemoteAddress
());
return
"Hello "
+
name
+
", re
gisterSuccess:"
+
registerSuccess
+
", re
sponse form provider: "
+
RpcContext
.
getContext
().
getLocalAddress
();
return
"Hello "
+
name
+
", response form provider: "
+
RpcContext
.
getContext
().
getLocalAddress
();
}
}
\ No newline at end of file
whatsmars-dubbo/whatsmars-dubbo-provider/src/main/java/org/hongxi/whatsmars/dubbo/demo/provider/DemoServiceImpl2.java
浏览文件 @
114a8c45
...
...
@@ -3,14 +3,19 @@
*/
package
org.hongxi.whatsmars.dubbo.demo.provider
;
import
org.apache.dubbo.rpc.RpcContext
;
import
org.hongxi.whatsmars.dubbo.demo.api.DemoService
;
import
org.springframework.stereotype.Service
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
@Service
(
"demoService2"
)
public
class
DemoServiceImpl2
implements
DemoService
{
public
String
sayHello
(
String
name
)
{
return
"Hello "
+
name
;
System
.
out
.
println
(
"["
+
new
SimpleDateFormat
(
"HH:mm:ss"
).
format
(
new
Date
())
+
"] Hello "
+
name
+
", request from consumer: "
+
RpcContext
.
getContext
().
getRemoteAddress
());
return
"Hi "
+
name
+
", response form provider: "
+
RpcContext
.
getContext
().
getLocalAddress
();
}
}
\ No newline at end of file
whatsmars-dubbo/whatsmars-dubbo-provider/src/main/resources/META-INF/spring/dubbo-demo-provider.xml
浏览文件 @
114a8c45
...
...
@@ -19,7 +19,7 @@
(也是官方推荐,出于稳定性和性能的折中考虑)
序列化方式由provider决定,所以团队要决定改序列化方式时,只需修改provider配置 -->
<dubbo:protocol
name=
"dubbo"
port=
"20880"
server=
"netty4"
/>
<
dubbo:protocol
name=
"hessian"
port=
"8080"
server=
"jetty"
/
>
<
!--<dubbo:protocol name="hessian" port="8080" server="jetty" />--
>
<context:component-scan
base-package=
"org.hongxi.whatsmars.dubbo"
/>
...
...
@@ -34,7 +34,6 @@
<dubbo:service
group=
"new"
interface=
"org.hongxi.whatsmars.dubbo.demo.api.DemoService"
ref=
"demoService2"
protocol=
"dubbo"
/>
<!-- 通过loadbalance="leastactive"也可实现并发控制,此 Loadbalance 会调用并发数最小的 Provider(Consumer端并发数) -->
<dubbo:service
interface=
"org.hongxi.whatsmars.dubbo.demo.api.BarService"
ref=
"barService"
mock=
"org.hongxi.whatsmars.dubbo.demo.provider.BarServiceMock"
executes=
"10"
protocol=
"dubbo"
/>
<dubbo:service
interface=
"org.hongxi.whatsmars.dubbo.demo.api.BarService"
ref=
"barService"
executes=
"10"
protocol=
"dubbo"
/>
</beans>
\ No newline at end of file
whatsmars-dubbo/whatsmars-dubbo-provider/src/test/java/org/hongxi/whatsmars/dubbo/demo/provider/Provider.java
浏览文件 @
114a8c45
package
org.hongxi.whatsmars.dubbo.demo.provider
;
import
com.alibaba
.dubbo.config.ApplicationConfig
;
import
com.alibaba
.dubbo.config.ProtocolConfig
;
import
com.alibaba
.dubbo.config.RegistryConfig
;
import
com.alibaba
.dubbo.config.ServiceConfig
;
import
org.apache
.dubbo.config.ApplicationConfig
;
import
org.apache
.dubbo.config.ProtocolConfig
;
import
org.apache
.dubbo.config.RegistryConfig
;
import
org.apache
.dubbo.config.ServiceConfig
;
import
org.hongxi.whatsmars.dubbo.demo.api.DemoService
;
public
class
Provider
{
...
...
whatsmars-dubbo/whatsmars-dubbo-sentinel/pom.xml
已删除
100644 → 0
浏览文件 @
a29ff9de
<?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>
<artifactId>
whatsmars-dubbo
</artifactId>
<groupId>
org.hongxi
</groupId>
<version>
Rocket.S4
</version>
</parent>
<artifactId>
whatsmars-dubbo-sentinel
</artifactId>
<packaging>
jar
</packaging>
<name>
${project.artifactId}
</name>
<description>
use sentinel in dubbo
</description>
<dependencies>
<dependency>
<groupId>
org.springframework
</groupId>
<artifactId>
spring-context
</artifactId>
</dependency>
<dependency>
<groupId>
com.alibaba
</groupId>
<artifactId>
dubbo
</artifactId>
</dependency>
<dependency>
<groupId>
org.apache.curator
</groupId>
<artifactId>
curator-framework
</artifactId>
</dependency>
<dependency>
<groupId>
com.alibaba.csp
</groupId>
<artifactId>
sentinel-dubbo-adapter
</artifactId>
</dependency>
<dependency>
<groupId>
com.alibaba.csp
</groupId>
<artifactId>
sentinel-transport-simple-http
</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
whatsmars-dubbo/whatsmars-dubbo-sentinel/src/main/java/org/hongxi/whatsmars/dubbo/sentinel/FooService.java
已删除
100644 → 0
浏览文件 @
a29ff9de
/*
* Copyright 1999-2018 Alibaba Group Holding Ltd.
*
* Licensed 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.hongxi.whatsmars.dubbo.sentinel
;
/**
* @author Eric Zhao
*/
public
interface
FooService
{
String
sayHello
(
String
name
);
String
doAnother
();
}
whatsmars-dubbo/whatsmars-dubbo-sentinel/src/main/java/org/hongxi/whatsmars/dubbo/sentinel/consumer/ConsumerConfiguration.java
已删除
100644 → 0
浏览文件 @
a29ff9de
/*
* Copyright 1999-2018 Alibaba Group Holding Ltd.
*
* Licensed 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.hongxi.whatsmars.dubbo.sentinel.consumer
;
import
com.alibaba.dubbo.config.ApplicationConfig
;
import
com.alibaba.dubbo.config.ConsumerConfig
;
import
com.alibaba.dubbo.config.RegistryConfig
;
import
com.alibaba.dubbo.config.spring.context.annotation.DubboComponentScan
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
/**
* @author Eric Zhao
*/
@Configuration
@DubboComponentScan
public
class
ConsumerConfiguration
{
@Bean
public
ApplicationConfig
applicationConfig
()
{
ApplicationConfig
applicationConfig
=
new
ApplicationConfig
();
applicationConfig
.
setName
(
"demo-consumer"
);
return
applicationConfig
;
}
@Bean
public
RegistryConfig
registryConfig
()
{
RegistryConfig
registryConfig
=
new
RegistryConfig
();
registryConfig
.
setAddress
(
"zookeeper://127.0.0.1:2181"
);
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
();
}
}
whatsmars-dubbo/whatsmars-dubbo-sentinel/src/main/java/org/hongxi/whatsmars/dubbo/sentinel/consumer/FooServiceConsumer.java
已删除
100644 → 0
浏览文件 @
a29ff9de
/*
* Copyright 1999-2018 Alibaba Group Holding Ltd.
*
* Licensed 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.hongxi.whatsmars.dubbo.sentinel.consumer
;
import
com.alibaba.dubbo.config.annotation.Reference
;
import
org.hongxi.whatsmars.dubbo.sentinel.FooService
;
/**
* @author Eric Zhao
*/
public
class
FooServiceConsumer
{
@Reference
private
FooService
fooService
;
public
String
sayHello
(
String
name
)
{
return
fooService
.
sayHello
(
name
);
}
public
String
doAnother
()
{
return
fooService
.
doAnother
();
}
}
whatsmars-dubbo/whatsmars-dubbo-sentinel/src/main/java/org/hongxi/whatsmars/dubbo/sentinel/demo1/FooConsumerBootstrap.java
已删除
100644 → 0
浏览文件 @
a29ff9de
/*
* Copyright 1999-2018 Alibaba Group Holding Ltd.
*
* Licensed 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.hongxi.whatsmars.dubbo.sentinel.demo1
;
import
com.alibaba.csp.sentinel.slots.block.SentinelRpcException
;
import
org.hongxi.whatsmars.dubbo.sentinel.consumer.ConsumerConfiguration
;
import
org.hongxi.whatsmars.dubbo.sentinel.consumer.FooServiceConsumer
;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
/**
* Please add the following VM arguments:
* <pre>
* -Djava.net.preferIPv4Stack=true
* -Dcsp.sentinel.api.port=8721
* -Dproject.name=dubbo-consumer-demo
* </pre>
*
* @author Eric Zhao
*/
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
(
"Eric"
);
System
.
out
.
println
(
"Success: "
+
message
);
}
catch
(
SentinelRpcException
ex
)
{
System
.
out
.
println
(
"Blocked"
);
}
catch
(
Exception
ex
)
{
ex
.
printStackTrace
();
}
}
}
}
whatsmars-dubbo/whatsmars-dubbo-sentinel/src/main/java/org/hongxi/whatsmars/dubbo/sentinel/demo1/FooProviderBootstrap.java
已删除
100644 → 0
浏览文件 @
a29ff9de
/*
* Copyright 1999-2018 Alibaba Group Holding Ltd.
*
* Licensed 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.hongxi.whatsmars.dubbo.sentinel.demo1
;
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.springframework.context.annotation.AnnotationConfigApplicationContext
;
import
java.util.Collections
;
/**
* Please add the following VM arguments:
* <pre>
* -Djava.net.preferIPv4Stack=true
* -Dcsp.sentinel.api.port=8720
* -Dproject.name=dubbo-provider-demo
* </pre>
*
* @author Eric Zhao
*/
public
class
FooProviderBootstrap
{
private
static
final
String
RES_KEY
=
"org.hongxi.whatsmars.dubbo.sentinel.FooService:sayHello(java.lang.String)"
;
private
static
final
String
INTERFACE_RES_KEY
=
"org.hongxi.whatsmars.dubbo.sentinel.FooService"
;
public
static
void
main
(
String
[]
args
)
{
// Users don't need to manually call this method.
InitExecutor
.
doInit
();
initFlowRule
();
AnnotationConfigApplicationContext
context
=
new
AnnotationConfigApplicationContext
();
context
.
register
(
ProviderConfiguration
.
class
);
context
.
refresh
();
System
.
out
.
println
(
"Service provider is ready"
);
}
private
static
void
initFlowRule
()
{
FlowRule
flowRule
=
new
FlowRule
();
flowRule
.
setResource
(
RES_KEY
);
flowRule
.
setCount
(
10
);
flowRule
.
setGrade
(
RuleConstant
.
FLOW_GRADE_QPS
);
flowRule
.
setLimitApp
(
"default"
);
FlowRuleManager
.
loadRules
(
Collections
.
singletonList
(
flowRule
));
}
}
whatsmars-dubbo/whatsmars-dubbo-sentinel/src/main/java/org/hongxi/whatsmars/dubbo/sentinel/demo1/FooServiceImpl.java
已删除
100644 → 0
浏览文件 @
a29ff9de
/*
* Copyright 1999-2018 Alibaba Group Holding Ltd.
*
* Licensed 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.hongxi.whatsmars.dubbo.sentinel.demo1
;
import
com.alibaba.dubbo.config.annotation.Service
;
import
org.hongxi.whatsmars.dubbo.sentinel.FooService
;
import
java.time.LocalDateTime
;
/**
* @author Eric Zhao
*/
@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
();
}
}
whatsmars-dubbo/whatsmars-dubbo-sentinel/src/main/java/org/hongxi/whatsmars/dubbo/sentinel/demo1/ProviderConfiguration.java
已删除
100644 → 0
浏览文件 @
a29ff9de
/*
* Copyright 1999-2018 Alibaba Group Holding Ltd.
*
* Licensed 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.hongxi.whatsmars.dubbo.sentinel.demo1
;
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
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
/**
* @author Eric Zhao
*/
@Configuration
@DubboComponentScan
(
"org.hongxi.whatsmars.dubbo.sentinel.demo1"
)
public
class
ProviderConfiguration
{
@Bean
public
ApplicationConfig
applicationConfig
()
{
ApplicationConfig
applicationConfig
=
new
ApplicationConfig
();
applicationConfig
.
setName
(
"demo-provider"
);
return
applicationConfig
;
}
@Bean
public
RegistryConfig
registryConfig
()
{
RegistryConfig
registryConfig
=
new
RegistryConfig
();
registryConfig
.
setAddress
(
"zookeeper://127.0.0.1:2181"
);
return
registryConfig
;
}
@Bean
public
ProtocolConfig
protocolConfig
()
{
ProtocolConfig
protocolConfig
=
new
ProtocolConfig
();
protocolConfig
.
setName
(
"dubbo"
);
protocolConfig
.
setPort
(
25758
);
return
protocolConfig
;
}
}
whatsmars-dubbo/whatsmars-dubbo-sentinel/src/main/java/org/hongxi/whatsmars/dubbo/sentinel/demo2/FooConsumerBootstrap.java
已删除
100644 → 0
浏览文件 @
a29ff9de
/*
* Copyright 1999-2018 Alibaba Group Holding Ltd.
*
* Licensed 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.hongxi.whatsmars.dubbo.sentinel.demo2
;
import
com.alibaba.csp.sentinel.adapter.dubbo.fallback.DubboFallbackRegistry
;
import
com.alibaba.csp.sentinel.concurrent.NamedThreadFactory
;
import
com.alibaba.csp.sentinel.slots.block.BlockException
;
import
com.alibaba.csp.sentinel.slots.block.RuleConstant
;
import
com.alibaba.csp.sentinel.slots.block.SentinelRpcException
;
import
com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule
;
import
com.alibaba.csp.sentinel.slots.block.degrade.DegradeRuleManager
;
import
com.alibaba.dubbo.rpc.RpcResult
;
import
org.hongxi.whatsmars.dubbo.sentinel.consumer.ConsumerConfiguration
;
import
org.hongxi.whatsmars.dubbo.sentinel.consumer.FooServiceConsumer
;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
import
java.util.Collections
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.Executors
;
/**
* Please add the following VM arguments:
* <pre>
* -Djava.net.preferIPv4Stack=true
* -Dcsp.sentinel.api.port=8721
* -Dproject.name=dubbo-consumer-demo
* </pre>
*
* @author Eric Zhao
*/
public
class
FooConsumerBootstrap
{
private
static
final
String
RES_KEY
=
"org.hongxi.whatsmars.dubbo.sentinel.FooService:sayHello(java.lang.String)"
;
private
static
final
String
INTERFACE_RES_KEY
=
"org.hongxi.whatsmars.dubbo.sentinel.FooService"
;
private
static
final
ExecutorService
pool
=
Executors
.
newFixedThreadPool
(
10
,
new
NamedThreadFactory
(
"dubbo-consumer-pool"
));
public
static
void
main
(
String
[]
args
)
{
initFlowRule
();
registerFallback
();
AnnotationConfigApplicationContext
consumerContext
=
new
AnnotationConfigApplicationContext
();
consumerContext
.
register
(
ConsumerConfiguration
.
class
);
consumerContext
.
refresh
();
FooServiceConsumer
service
=
consumerContext
.
getBean
(
FooServiceConsumer
.
class
);
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
pool
.
submit
(()
->
{
try
{
String
message
=
service
.
sayHello
(
"Eric"
);
System
.
out
.
println
(
"Success: "
+
message
);
}
catch
(
Exception
ex
)
{
if
(
BlockException
.
isBlockException
(
ex
))
{
System
.
out
.
println
(
"service.sayHello degrade"
);
}
else
{
ex
.
printStackTrace
();
}
}
});
pool
.
submit
(()
->
System
.
out
.
println
(
"Another: "
+
service
.
doAnother
()));
}
}
private
static
void
initFlowRule
()
{
DegradeRule
rule
=
new
DegradeRule
();
rule
.
setResource
(
RES_KEY
);
rule
.
setCount
(
1
);
rule
.
setGrade
(
RuleConstant
.
DEGRADE_GRADE_RT
);
rule
.
setTimeWindow
(
1
);
rule
.
setLimitApp
(
"default"
);
DegradeRuleManager
.
loadRules
(
Collections
.
singletonList
(
rule
));
}
private
static
void
registerFallback
()
{
// Register fallback handler for consumer.
// If you only want to handle degrading, you need to
// check the type of BlockException.
DubboFallbackRegistry
.
setConsumerFallback
((
a
,
b
,
ex
)
->
new
RpcResult
(
"Error: "
+
ex
.
getClass
().
getTypeName
()));
}
}
whatsmars-dubbo/whatsmars-dubbo-sentinel/src/main/java/org/hongxi/whatsmars/dubbo/sentinel/demo2/FooProviderBootstrap.java
已删除
100644 → 0
浏览文件 @
a29ff9de
/*
* Copyright 1999-2018 Alibaba Group Holding Ltd.
*
* Licensed 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.hongxi.whatsmars.dubbo.sentinel.demo2
;
import
com.alibaba.csp.sentinel.init.InitExecutor
;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
/**
* Please add the following VM arguments:
* <pre>
* -Djava.net.preferIPv4Stack=true
* -Dcsp.sentinel.api.port=8720
* -Dproject.name=dubbo-provider-demo
* </pre>
*
* @author Eric Zhao
*/
public
class
FooProviderBootstrap
{
public
static
void
main
(
String
[]
args
)
{
// Users don't need to manually call this method.
InitExecutor
.
doInit
();
AnnotationConfigApplicationContext
context
=
new
AnnotationConfigApplicationContext
();
context
.
register
(
ProviderConfiguration
.
class
);
context
.
refresh
();
System
.
out
.
println
(
"Service provider is ready"
);
}
}
whatsmars-dubbo/whatsmars-dubbo-sentinel/src/main/java/org/hongxi/whatsmars/dubbo/sentinel/demo2/FooServiceImpl.java
已删除
100644 → 0
浏览文件 @
a29ff9de
/*
* Copyright 1999-2018 Alibaba Group Holding Ltd.
*
* Licensed 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.hongxi.whatsmars.dubbo.sentinel.demo2
;
import
com.alibaba.dubbo.config.annotation.Service
;
import
org.hongxi.whatsmars.dubbo.sentinel.FooService
;
import
java.time.LocalDateTime
;
/**
* @author Eric Zhao
*/
@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
();
}
}
whatsmars-dubbo/whatsmars-dubbo-sentinel/src/main/java/org/hongxi/whatsmars/dubbo/sentinel/demo2/ProviderConfiguration.java
已删除
100644 → 0
浏览文件 @
a29ff9de
/*
* Copyright 1999-2018 Alibaba Group Holding Ltd.
*
* Licensed 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.hongxi.whatsmars.dubbo.sentinel.demo2
;
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
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
/**
* @author Eric Zhao
*/
@Configuration
@DubboComponentScan
(
"org.hongxi.whatsmars.dubbo.sentinel.demo2"
)
public
class
ProviderConfiguration
{
@Bean
public
ApplicationConfig
applicationConfig
()
{
ApplicationConfig
applicationConfig
=
new
ApplicationConfig
();
applicationConfig
.
setName
(
"demo-provider"
);
return
applicationConfig
;
}
@Bean
public
RegistryConfig
registryConfig
()
{
RegistryConfig
registryConfig
=
new
RegistryConfig
();
registryConfig
.
setAddress
(
"zookeeper://127.0.0.1:2181"
);
return
registryConfig
;
}
@Bean
public
ProtocolConfig
protocolConfig
()
{
ProtocolConfig
protocolConfig
=
new
ProtocolConfig
();
protocolConfig
.
setName
(
"dubbo"
);
protocolConfig
.
setPort
(
25758
);
return
protocolConfig
;
}
}
whatsmars-dubbo/whatsmars-dubbo-service/pom.xml
已删除
100644 → 0
浏览文件 @
a29ff9de
<?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>
<artifactId>
whatsmars-dubbo
</artifactId>
<groupId>
org.hongxi
</groupId>
<version>
Rocket.S4
</version>
</parent>
<artifactId>
whatsmars-dubbo-service
</artifactId>
<packaging>
jar
</packaging>
<name>
${project.artifactId}
</name>
<description>
普通service
</description>
<dependencies>
<dependency>
<groupId>
org.springframework
</groupId>
<artifactId>
spring-context
</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
whatsmars-dubbo/whatsmars-dubbo-service/src/main/java/org/hongxi/whatsmars/dubbo/service/UserService.java
已删除
100644 → 0
浏览文件 @
a29ff9de
package
org.hongxi.whatsmars.dubbo.service
;
/**
* Created by shenhongxi on 2017/12/4.
*/
public
interface
UserService
{
boolean
register
(
String
name
);
}
whatsmars-dubbo/whatsmars-dubbo-service/src/main/java/org/hongxi/whatsmars/dubbo/service/impl/UserServiceImpl.java
已删除
100644 → 0
浏览文件 @
a29ff9de
package
org.hongxi.whatsmars.dubbo.service.impl
;
import
org.hongxi.whatsmars.dubbo.service.UserService
;
import
org.springframework.stereotype.Service
;
/**
* Created by shenhongxi on 2017/12/4.
*/
@Service
(
"userService"
)
public
class
UserServiceImpl
implements
UserService
{
@Override
public
boolean
register
(
String
name
)
{
// register ...
return
true
;
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录