You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by "k5h9999 (GitHub)" <gi...@apache.org> on 2018/11/22 07:23:38 UTC
[GitHub] [incubator-dubbo] k5h9999 opened issue #2664: dubbo hystrix熔断集成问题,达不到熔断或降级的效果
- [ ] I have searched the [issues](https://github.com/apache/incubator-dubbo/issues) of this repository and believe that this is not a duplicate.
- [ ] I have checked the [FAQ](https://github.com/apache/incubator-dubbo/blob/master/FAQ.md) of this repository and believe that this is not a duplicate.
### Environment
* Dubbo version: 2.5.x
* Operating System version: xxx
* Java version: 1.8
### Steps to reproduce this issue
1. 人为制造异常
```java
public User getUser ( int id){
System.out.println("getUser");
System.out.println(String.format("%s", 10 / 0));
User user = new User();
user.setId(1);
user.setUsername("test");
user.setPassword("test");
System.out.println("11111111562");
return user;
}
```
2. 单元测试
```java
@Test
public void testEchoException() {
//echoService.echoWithException();
echoService.getUser(1);
System.out.println("666666666666");
}
```
3. 异常结果
```java
java.lang.ClassCastException: java.lang.String cannot be cast to com.test.dubbo.service.User
at com.alibaba.dubbo.common.bytecode.proxy0.getUser(proxy0.java)
at com.test.dubbo.ConsumerTest.testEchoException(ConsumerTest.java:46)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
```
4. HystrixFilter过滤器:
```java
package com.netease.hystrix.dubbo.rpc.filter;
import com.alibaba.dubbo.common.Constants;
import com.alibaba.dubbo.common.extension.Activate;
import com.alibaba.dubbo.rpc.Filter;
import com.alibaba.dubbo.rpc.Invocation;
import com.alibaba.dubbo.rpc.Invoker;
import com.alibaba.dubbo.rpc.Result;
import com.alibaba.dubbo.rpc.RpcException;
@Activate(group = Constants.CONSUMER)
public class HystrixFilter implements Filter {
@Override
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
DubboHystrixCommand command = new DubboHystrixCommand(invoker, invocation);
return command.execute();
}
}
```
5. DubboHystrixCommand 类:
```java
package com.netease.hystrix.dubbo.rpc.filter;
import org.apache.log4j.Logger;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.rpc.Invocation;
import com.alibaba.dubbo.rpc.Invoker;
import com.alibaba.dubbo.rpc.Result;
import com.netflix.hystrix.HystrixCommand;
import com.netflix.hystrix.HystrixCommandGroupKey;
import com.netflix.hystrix.HystrixCommandKey;
import com.netflix.hystrix.HystrixCommandProperties;
import com.netflix.hystrix.HystrixThreadPoolProperties;
public class DubboHystrixCommand extends HystrixCommand<Result> {
private static Logger logger = Logger.getLogger(DubboHystrixCommand.class);
private static final int DEFAULT_THREADPOOL_CORE_SIZE = 30;
private Invoker<?> invoker;
private Invocation invocation;
public DubboHystrixCommand(Invoker<?> invoker,Invocation invocation){
super(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey(invoker.getInterface().getName()))
.andCommandKey(HystrixCommandKey.Factory.asKey(String.format("%s_%d", invocation.getMethodName(),
invocation.getArguments() == null ? 0 : invocation.getArguments().length)))
.andCommandPropertiesDefaults(HystrixCommandProperties.Setter()
.withCircuitBreakerRequestVolumeThreshold(20)//10秒钟内至少19此请求失败,熔断器才发挥起作用
.withCircuitBreakerSleepWindowInMilliseconds(30000)//熔断器中断请求30秒后会进入半打开状态,放部分流量过去重试
.withCircuitBreakerErrorThresholdPercentage(50)//错误率达到50开启熔断保护
.withExecutionTimeoutEnabled(false))//使用dubbo的超时,禁用这里的超时
.andThreadPoolPropertiesDefaults(HystrixThreadPoolProperties.Setter().withCoreSize(getThreadPoolCoreSize(invoker.getUrl()))));//线程池为30
this.invoker=invoker;
this.invocation=invocation;
}
/**
* 获取线程池大小
*
* @param url
* @return
*/
private static int getThreadPoolCoreSize(URL url) {
if (url != null) {
int size = url.getParameter("ThreadPoolCoreSize", DEFAULT_THREADPOOL_CORE_SIZE);
if (logger.isDebugEnabled()) {
logger.debug("ThreadPoolCoreSize:" + size);
}
return size;
}
return DEFAULT_THREADPOOL_CORE_SIZE;
}
@Override
protected Result run() throws Exception {
return invoker.invoke(invocation);
}
}
```
6. 配置:
在resources/META-INF新建dubbo文件夹
hystrixFilter=com.netease.hystrix.dubbo.rpc.filter.HystrixFilter
人为制造了一个异常,如果方法返回void和String类型的话没问题,如果是返回List、实体类等就报以上错!达不到熔断或降级的错误,会是什么原因?该如何处理。。。
[ Full content available at: https://github.com/apache/incubator-dubbo/issues/2664 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org
[GitHub] [incubator-dubbo] moayi commented on issue #2664: dubbo hystrix熔断集成问题,达不到熔断或降级的效果
Posted by "moayi (GitHub)" <gi...@apache.org>.
方便请教一下吗?谢谢
qq:1558056914
[ Full content available at: https://github.com/apache/incubator-dubbo/issues/2664 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org
[GitHub] [incubator-dubbo] k5h9999 commented on issue #2664: dubbo hystrix熔断集成问题,达不到熔断或降级的效果
Posted by "k5h9999 (GitHub)" <gi...@apache.org>.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd">
<dubbo:application name="consumer"/>
<!-- 使用multicast广播注册中心暴露服务地址 -->
<dubbo:registry address="zookeeper://127.0.0.1:2181"/>
<!-- 生成远程服务代理,可以和本地bean一样使用demoService -->
<dubbo:reference id="echoService" interface="com.test.dubbo.service.EchoService" check="false" retries="0">
</dubbo:reference>
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<!-- 提供方应用信息,用于计算依赖关系 -->
<dubbo:application name="provider"/>
<!-- 和本地bean一样实现服务 -->
<bean id="echoService" class="com.test.dubbo.service.EchoServiceImpl"/>
<!-- 使用multicast广播注册中心暴露服务地址 -->
<dubbo:registry address="zookeeper://127.0.0.1:2181"/>
<!-- 用dubbo协议在20880端口暴露服务 -->
<dubbo:protocol name="dubbo" port="20880"/>
<!-- 声明需要暴露的服务接口 -->
<dubbo:service interface="com.test.dubbo.service.EchoService" ref="echoService" retries="0" >
</dubbo:service>
</beans>
pom.xml
<!-- hystrix -->
<dependency>
<groupId>com.netflix.hystrix</groupId>
<artifactId>hystrix-core</artifactId>
<version>1.5.9</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
<version>2.5.3</version>
</dependency>
<dependency>
<groupId>com.github.sgroschupf</groupId>
<artifactId>zkclient</artifactId>
<version>0.1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.24</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.24</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.21.0-GA</version>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty</artifactId>
<version>3.6.10.Final</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
package com.test.dubbo.service;
import java.io.Serializable;
public class User implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
private int id;
private String username;
private String password;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
package com.test.dubbo.service;
public interface EchoService {
String sayHello();
String echoWithTimeOut();
String echoWithException();
String sayHi();
User getUser(int id);
}
package com.test.dubbo.service;
import java.util.Iterator;
import java.util.concurrent.TimeUnit;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
public class EchoServiceImpl implements EchoService {
public String sayHello() {
System.out.println("test");
return "Hello World";
}
public String echoWithTimeOut() {
try {
for (int i = 1; i < 10; i++) {
System.out.println("i==" + i);
TimeUnit.SECONDS.sleep(i);
}
// Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("11111111...echoWithTimeOut");
return "Hello World";
}
public String echoWithException() {
System.out.println(String.format("%s", 10 / 0));
System.out.println("2222222222.......echoWithException");
return String.format("%s", 10 / 0);
}
public String sayHi() {
String str = "Hi........DemoFallback!";
System.out.println("-----------------" + str);
return str;
}
public User getUser(int id) {
System.out.println("getUser");
System.out.println(String.format("%s", 10 / 0));
User user=new User();
user.setId(1);
user.setUsername("test");
user.setPassword("test");
System.out.println("11111111562");
return user;
}
}
package com.test.dubbo;
import com.test.dubbo.service.EchoService;
import com.netflix.config.ConfigurationManager;
import com.netflix.hystrix.HystrixThreadPoolKey;
import com.netflix.hystrix.HystrixThreadPoolProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.strategy.properties.HystrixPropertiesFactory;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import java.util.concurrent.TimeUnit;
public class ConsumerTest {
EchoService echoService;
@Before
public void before() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] { "consumer.xml" });
context.start();
echoService = (EchoService) context.getBean("echoService", EchoService.class);
}
@Test
public void test() {
Assert.assertEquals("Hello World", echoService.sayHello());
// System.out.println(echoService.sayHello());
}
@Test
public void testTimeout() {
// Assert.assertEquals("Hello World", echoService.echoWithTimeOut());
System.out.println(echoService.echoWithTimeOut());
System.out.println("555555555555555");
}
@Test
public void testEchoException() {
//echoService.echoWithException();
// try {
echoService.getUser(1);
// } catch (Exception e) {
// e.printStackTrace();
// }
System.out.println("666666666666");
}
@Test
public void testThreadPool() throws InterruptedException {
for (int i = 0; i < 20; i++) {
new Thread(() -> {
echoService.sayHello();
}).start();
System.out.println("i==="+i);
Thread.sleep(100);
}
// for (int i = 0; i < 5; i++) {
// String res =echoService.sayHello();
// System.out.println("test=" + i + ":" + res + " The time:" + (System.currentTimeMillis() / 1000));
// Thread.sleep(200);
// }
System.out.println("test...");
}
}
package com.test.dubbo;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class ProviderTest {
@Test
public void test() throws Exception {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"provider.xml"});
context.start();
System.in.read(); // 按任意键退出
context.close();
}
}
[ Full content available at: https://github.com/apache/incubator-dubbo/issues/2664 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org
[GitHub] [incubator-dubbo] k5h9999 commented on issue #2664: dubbo hystrix熔断集成问题,达不到熔断或降级的效果
Posted by "k5h9999 (GitHub)" <gi...@apache.org>.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd">
<dubbo:application name="consumer"/>
<!-- 使用multicast广播注册中心暴露服务地址 -->
<dubbo:registry address="zookeeper://127.0.0.1:2181"/>
<!-- 生成远程服务代理,可以和本地bean一样使用demoService -->
<dubbo:reference id="echoService" interface="com.test.dubbo.service.EchoService" check="false" retries="0">
</dubbo:reference>
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<!-- 提供方应用信息,用于计算依赖关系 -->
<dubbo:application name="provider"/>
<!-- 和本地bean一样实现服务 -->
<bean id="echoService" class="com.test.dubbo.service.EchoServiceImpl"/>
<!-- 使用multicast广播注册中心暴露服务地址 -->
<dubbo:registry address="zookeeper://127.0.0.1:2181"/>
<!-- 用dubbo协议在20880端口暴露服务 -->
<dubbo:protocol name="dubbo" port="20880"/>
<!-- 声明需要暴露的服务接口 -->
<dubbo:service interface="com.test.dubbo.service.EchoService" ref="echoService" retries="0" >
</dubbo:service>
</beans>
pom.xml
<!-- hystrix -->
<dependency>
<groupId>com.netflix.hystrix</groupId>
<artifactId>hystrix-core</artifactId>
<version>1.5.9</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
<version>2.5.3</version>
</dependency>
<dependency>
<groupId>com.github.sgroschupf</groupId>
<artifactId>zkclient</artifactId>
<version>0.1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.24</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.24</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.21.0-GA</version>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty</artifactId>
<version>3.6.10.Final</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
package com.test.dubbo.service;
import java.io.Serializable;
public class User implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
private int id;
private String username;
private String password;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
package com.test.dubbo.service;
public interface EchoService {
String sayHello();
String echoWithTimeOut();
String echoWithException();
String sayHi();
User getUser(int id);
}
package com.test.dubbo.service;
import java.util.Iterator;
import java.util.concurrent.TimeUnit;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
public class EchoServiceImpl implements EchoService {
public String sayHello() {
System.out.println("test");
return "Hello World";
}
public String echoWithTimeOut() {
try {
for (int i = 1; i < 10; i++) {
System.out.println("i==" + i);
TimeUnit.SECONDS.sleep(i);
}
// Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("11111111...echoWithTimeOut");
return "Hello World";
}
public String echoWithException() {
System.out.println(String.format("%s", 10 / 0));
System.out.println("2222222222.......echoWithException");
return String.format("%s", 10 / 0);
}
public String sayHi() {
String str = "Hi........DemoFallback!";
System.out.println("-----------------" + str);
return str;
}
public User getUser(int id) {
System.out.println("getUser");
System.out.println(String.format("%s", 10 / 0));
User user=new User();
user.setId(1);
user.setUsername("test");
user.setPassword("test");
System.out.println("11111111562");
return user;
}
}
package com.test.dubbo;
import com.test.dubbo.service.EchoService;
import com.netflix.config.ConfigurationManager;
import com.netflix.hystrix.HystrixThreadPoolKey;
import com.netflix.hystrix.HystrixThreadPoolProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.strategy.properties.HystrixPropertiesFactory;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import java.util.concurrent.TimeUnit;
public class ConsumerTest {
EchoService echoService;
@Before
public void before() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] { "consumer.xml" });
context.start();
echoService = (EchoService) context.getBean("echoService", EchoService.class);
}
@Test
public void test() {
Assert.assertEquals("Hello World", echoService.sayHello());
// System.out.println(echoService.sayHello());
}
@Test
public void testTimeout() {
// Assert.assertEquals("Hello World", echoService.echoWithTimeOut());
System.out.println(echoService.echoWithTimeOut());
System.out.println("555555555555555");
}
@Test
public void testEchoException() {
//echoService.echoWithException();
// try {
echoService.getUser(1);
// } catch (Exception e) {
// e.printStackTrace();
// }
System.out.println("666666666666");
}
@Test
public void testThreadPool() throws InterruptedException {
for (int i = 0; i < 20; i++) {
new Thread(() -> {
echoService.sayHello();
}).start();
System.out.println("i==="+i);
Thread.sleep(100);
}
// for (int i = 0; i < 5; i++) {
// String res =echoService.sayHello();
// System.out.println("test=" + i + ":" + res + " The time:" + (System.currentTimeMillis() / 1000));
// Thread.sleep(200);
// }
System.out.println("test...");
}
}
package com.test.dubbo;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class ProviderTest {
@Test
public void test() throws Exception {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"provider.xml"});
context.start();
System.in.read(); // 按任意键退出
context.close();
}
}
[ Full content available at: https://github.com/apache/incubator-dubbo/issues/2664 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org
[GitHub] [incubator-dubbo] k5h9999 commented on issue #2664: dubbo hystrix熔断集成问题,达不到熔断或降级的效果
Posted by "k5h9999 (GitHub)" <gi...@apache.org>.
> ```
> <dubbo:application name="consumer"/>
> <!-- 使用multicast广播注册中心暴露服务地址 -->
> <dubbo:registry address="zookeeper://127.0.0.1:2181"/>
>
> <!-- 生成远程服务代理,可以和本地bean一样使用demoService -->
> <dubbo:reference id="echoService" interface="com.test.dubbo.service.EchoService" check="false" retries="0">
> </dubbo:reference>
> ```
> ```
> <!-- 提供方应用信息,用于计算依赖关系 -->
> <dubbo:application name="provider"/>
> <!-- 和本地bean一样实现服务 -->
> <bean id="echoService" class="com.test.dubbo.service.EchoServiceImpl"/>
>
> <!-- 使用multicast广播注册中心暴露服务地址 -->
> <dubbo:registry address="zookeeper://127.0.0.1:2181"/>
>
> <!-- 用dubbo协议在20880端口暴露服务 -->
> <dubbo:protocol name="dubbo" port="20880"/>
> <!-- 声明需要暴露的服务接口 -->
> <dubbo:service interface="com.test.dubbo.service.EchoService" ref="echoService" retries="0" >
> </dubbo:service>
> ```
> pom.xml
>
> ```
> <dependency>
> <groupId>com.netflix.hystrix</groupId>
> <artifactId>hystrix-core</artifactId>
> <version>1.5.9</version>
> </dependency>
> <dependency>
> <groupId>com.github.sgroschupf</groupId>
> <artifactId>zkclient</artifactId>
> <version>0.1</version>
> </dependency>
><dependency>
> <groupId>com.alibaba</groupId>
> <artifactId>dubbo</artifactId>
> <version>2.8.4</version>
> </dependency>
><dependency>
> <groupId>com.alibaba</groupId>
> <artifactId>dubbo</artifactId>
> <version>2.5.3</version>
> </dependency>
> <dependency>
> <groupId>com.github.sgroschupf</groupId>
> <artifactId>zkclient</artifactId>
> <version>0.1</version>
> </dependency>
> <dependency>
> <groupId>org.slf4j</groupId>
> <artifactId>slf4j-api</artifactId>
> <version>1.7.24</version>
> </dependency>
> <dependency>
> <groupId>org.slf4j</groupId>
> <artifactId>slf4j-log4j12</artifactId>
> <version>1.7.24</version>
> <scope>test</scope>
> </dependency>
> <dependency>
> <groupId>io.netty</groupId>
> <artifactId>netty</artifactId>
> <version>3.6.10.Final</version>
> </dependency>
> ```
> package com.test.dubbo.service;
>
> import java.io.Serializable;
>
> public class User implements Serializable{
> /**
> *
> */
> private static final long serialVersionUID = 1L;
> private int id;
> private String username;
> private String password;
>
> ```
> public int getId() {
> return id;
> }
>
> public void setId(int id) {
> this.id = id;
> }
>
> public String getUsername() {
> return username;
> }
>
> public void setUsername(String username) {
> this.username = username;
> }
>
> public String getPassword() {
> return password;
> }
>
> public void setPassword(String password) {
> this.password = password;
> }
> ```
> }
>
> package com.test.dubbo.service;
>
> public interface EchoService {
>
> ```
> String sayHello();
>
> String echoWithTimeOut();
>
> String echoWithException();
>
> String sayHi();
>
> User getUser(int id);
> ```
> }
>
> package com.test.dubbo.service;
>
> import java.util.Iterator;
> import java.util.concurrent.TimeUnit;
>
> import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
>
> public class EchoServiceImpl implements EchoService {
> public String sayHello() {
> System.out.println("test");
> return "Hello World";
> }
>
> ```
> public String echoWithTimeOut() {
> try {
> for (int i = 1; i < 10; i++) {
> System.out.println("i==" + i);
> TimeUnit.SECONDS.sleep(i);
> }
> // Thread.sleep(10);
> } catch (InterruptedException e) {
> e.printStackTrace();
> }
> System.out.println("11111111...echoWithTimeOut");
> return "Hello World";
> }
>
> public String echoWithException() {
> System.out.println(String.format("%s", 10 / 0));
> System.out.println("2222222222.......echoWithException");
> return String.format("%s", 10 / 0);
> }
>
> public String sayHi() {
> String str = "Hi........DemoFallback!";
> System.out.println("-----------------" + str);
> return str;
> }
>
> public User getUser(int id) {
> System.out.println("getUser");
> System.out.println(String.format("%s", 10 / 0));
> User user=new User();
> user.setId(1);
> user.setUsername("test");
> user.setPassword("test");
> System.out.println("11111111562");
> return user;
> }
> ```
> }
>
> package com.test.dubbo;
>
> import com.test.dubbo.service.EchoService;
> import com.netflix.config.ConfigurationManager;
> import com.netflix.hystrix.HystrixThreadPoolKey;
> import com.netflix.hystrix.HystrixThreadPoolProperties;
> import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
> import com.netflix.hystrix.strategy.properties.HystrixPropertiesFactory;
> import org.junit.Assert;
> import org.junit.Before;
> import org.junit.Test;
> import org.springframework.context.support.ClassPathXmlApplicationContext;
>
> import java.util.concurrent.TimeUnit;
>
> public class ConsumerTest {
> EchoService echoService;
>
> ```
> @Before
> public void before() {
> ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] { "consumer.xml" });
> context.start();
> echoService = (EchoService) context.getBean("echoService", EchoService.class);
> }
>
> @Test
> public void test() {
> Assert.assertEquals("Hello World", echoService.sayHello());
> // System.out.println(echoService.sayHello());
> }
>
> @Test
> public void testTimeout() {
> // Assert.assertEquals("Hello World", echoService.echoWithTimeOut());
> System.out.println(echoService.echoWithTimeOut());
> System.out.println("555555555555555");
> }
>
>
> @Test
> public void testEchoException() {
> //echoService.echoWithException();
> // try {
> echoService.getUser(1);
> ```
> // } catch (Exception e) {
> // e.printStackTrace();
> // }
>
> ```
> System.out.println("666666666666");
> }
>
> @Test
> public void testThreadPool() throws InterruptedException {
> for (int i = 0; i < 20; i++) {
> new Thread(() -> {
> echoService.sayHello();
> }).start();
> System.out.println("i==="+i);
> Thread.sleep(100);
> }
> ```
> // for (int i = 0; i < 5; i++) {
> // String res =echoService.sayHello();
> // System.out.println("test=" + i + ":" + res + " The time:" + (System.currentTimeMillis() / 1000));
> // Thread.sleep(200);
> // }
>
> ```
> System.out.println("test...");
> }
> ```
> }
>
> package com.test.dubbo;
> import org.junit.Test;
> import org.springframework.context.support.ClassPathXmlApplicationContext;
>
> public class ProviderTest {
>
> ```
> @Test
> public void test() throws Exception
1. {
> ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"provider.xml"});
> context.start();
>
> System.in.read(); // 按任意键退出
> context.close();
>
> }
> ```
> }
- [ ]
[ Full content available at: https://github.com/apache/incubator-dubbo/issues/2664 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org
[GitHub] [incubator-dubbo] beiwei30 commented on issue #2664: dubbo hystrix熔断集成问题,达不到熔断或降级的效果
Posted by "beiwei30 (GitHub)" <gi...@apache.org>.
1. consumer
```xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd">
<dubbo:application name="consumer"/>
<!-- 使用multicast广播注册中心暴露服务地址 -->
<dubbo:registry address="zookeeper://127.0.0.1:2181"/>
<!-- 生成远程服务代理,可以和本地bean一样使用demoService -->
<dubbo:reference id="echoService" interface="com.test.dubbo.service.EchoService" check="false" retries="0">
</dubbo:reference>
</beans>
```
2. provider
```xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<!-- 提供方应用信息,用于计算依赖关系 -->
<dubbo:application name="provider"/>
<!-- 和本地bean一样实现服务 -->
<bean id="echoService" class="com.test.dubbo.service.EchoServiceImpl"/>
<!-- 使用multicast广播注册中心暴露服务地址 -->
<dubbo:registry address="zookeeper://127.0.0.1:2181"/>
<!-- 用dubbo协议在20880端口暴露服务 -->
<dubbo:protocol name="dubbo" port="20880"/>
<!-- 声明需要暴露的服务接口 -->
<dubbo:service interface="com.test.dubbo.service.EchoService" ref="echoService" retries="0" >
</dubbo:service>
</beans>
```
3. pom.xml
```xml
<!-- hystrix -->
<dependency>
<groupId>com.netflix.hystrix</groupId>
<artifactId>hystrix-core</artifactId>
<version>1.5.9</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
<version>2.5.3</version>
</dependency>
<dependency>
<groupId>com.github.sgroschupf</groupId>
<artifactId>zkclient</artifactId>
<version>0.1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.24</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.24</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.21.0-GA</version>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty</artifactId>
<version>3.6.10.Final</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
```
4. User
```java
package com.test.dubbo.service;
import java.io.Serializable;
public class User implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
private int id;
private String username;
private String password;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
```
5. EchoService
```java
package com.test.dubbo.service;
public interface EchoService {
String sayHello();
String echoWithTimeOut();
String echoWithException();
String sayHi();
User getUser(int id);
}
```
6. EchoServiceImpl
```java
package com.test.dubbo.service;
import java.util.Iterator;
import java.util.concurrent.TimeUnit;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
public class EchoServiceImpl implements EchoService {
public String sayHello() {
System.out.println("test");
return "Hello World";
}
public String echoWithTimeOut() {
try {
for (int i = 1; i < 10; i++) {
System.out.println("i==" + i);
TimeUnit.SECONDS.sleep(i);
}
// Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("11111111...echoWithTimeOut");
return "Hello World";
}
public String echoWithException() {
System.out.println(String.format("%s", 10 / 0));
System.out.println("2222222222.......echoWithException");
return String.format("%s", 10 / 0);
}
public String sayHi() {
String str = "Hi........DemoFallback!";
System.out.println("-----------------" + str);
return str;
}
public User getUser(int id) {
System.out.println("getUser");
System.out.println(String.format("%s", 10 / 0));
User user=new User();
user.setId(1);
user.setUsername("test");
user.setPassword("test");
System.out.println("11111111562");
return user;
}
}
```
7. ConsumerTest
```java
package com.test.dubbo;
import com.test.dubbo.service.EchoService;
import com.netflix.config.ConfigurationManager;
import com.netflix.hystrix.HystrixThreadPoolKey;
import com.netflix.hystrix.HystrixThreadPoolProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.strategy.properties.HystrixPropertiesFactory;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import java.util.concurrent.TimeUnit;
public class ConsumerTest {
EchoService echoService;
@Before
public void before() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] { "consumer.xml" });
context.start();
echoService = (EchoService) context.getBean("echoService", EchoService.class);
}
@Test
public void test() {
Assert.assertEquals("Hello World", echoService.sayHello());
// System.out.println(echoService.sayHello());
}
@Test
public void testTimeout() {
// Assert.assertEquals("Hello World", echoService.echoWithTimeOut());
System.out.println(echoService.echoWithTimeOut());
System.out.println("555555555555555");
}
@Test
public void testEchoException() {
//echoService.echoWithException();
// try {
echoService.getUser(1);
// } catch (Exception e) {
// e.printStackTrace();
// }
System.out.println("666666666666");
}
@Test
public void testThreadPool() throws InterruptedException {
for (int i = 0; i < 20; i++) {
new Thread(() -> {
echoService.sayHello();
}).start();
System.out.println("i==="+i);
Thread.sleep(100);
}
// for (int i = 0; i < 5; i++) {
// String res =echoService.sayHello();
// System.out.println("test=" + i + ":" + res + " The time:" + (System.currentTimeMillis() / 1000));
// Thread.sleep(200);
// }
System.out.println("test...");
}
}
```
7. ProviderTest
```java
package com.test.dubbo;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class ProviderTest {
@Test
public void test() throws Exception {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"provider.xml"});
context.start();
System.in.read(); // 按任意键退出
context.close();
}
}
```
[ Full content available at: https://github.com/apache/incubator-dubbo/issues/2664 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org
[GitHub] [incubator-dubbo] carryxyh commented on issue #2664: dubbo hystrix熔断集成问题,达不到熔断或降级的效果
Posted by "carryxyh (GitHub)" <gi...@apache.org>.
Close this issue because it has been solved.
[ Full content available at: https://github.com/apache/incubator-dubbo/issues/2664 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org
[GitHub] [incubator-dubbo] k5h9999 commented on issue #2664: dubbo hystrix熔断集成问题,达不到熔断或降级的效果
Posted by "k5h9999 (GitHub)" <gi...@apache.org>.
@moayi 解决了。
[ Full content available at: https://github.com/apache/incubator-dubbo/issues/2664 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org
[GitHub] [incubator-dubbo] k5h9999 commented on issue #2664: dubbo hystrix熔断集成问题,达不到熔断或降级的效果
Posted by "k5h9999 (GitHub)" <gi...@apache.org>.
> ```
> <dubbo:application name="consumer"/>
> <!-- 使用multicast广播注册中心暴露服务地址 -->
> <dubbo:registry address="zookeeper://127.0.0.1:2181"/>
>
> <!-- 生成远程服务代理,可以和本地bean一样使用demoService -->
> <dubbo:reference id="echoService" interface="com.test.dubbo.service.EchoService" check="false" retries="0">
> </dubbo:reference>
> ```
> ```
> <!-- 提供方应用信息,用于计算依赖关系 -->
> <dubbo:application name="provider"/>
> <!-- 和本地bean一样实现服务 -->
> <bean id="echoService" class="com.test.dubbo.service.EchoServiceImpl"/>
>
> <!-- 使用multicast广播注册中心暴露服务地址 -->
> <dubbo:registry address="zookeeper://127.0.0.1:2181"/>
>
> <!-- 用dubbo协议在20880端口暴露服务 -->
> <dubbo:protocol name="dubbo" port="20880"/>
> <!-- 声明需要暴露的服务接口 -->
> <dubbo:service interface="com.test.dubbo.service.EchoService" ref="echoService" retries="0" >
> </dubbo:service>
> ```
> pom.xml
>
> ```
> <dependency>
> <groupId>com.netflix.hystrix</groupId>
> <artifactId>hystrix-core</artifactId>
> <version>1.5.9</version>
> </dependency>
<dependency>
<groupId>com.github.sgroschupf</groupId>
<artifactId>zkclient</artifactId>
<version>0.1</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
<version>2.8.4</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
<version>2.5.3</version>
</dependency>
<dependency>
<groupId>com.github.sgroschupf</groupId>
<artifactId>zkclient</artifactId>
<version>0.1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.24</version>
</dependency>
> <dependency>
> <groupId>org.slf4j</groupId>
> <artifactId>slf4j-log4j12</artifactId>
> <version>1.7.24</version>
> <scope>test</scope>
> </dependency>
> <dependency>
> <groupId>io.netty</groupId>
> <artifactId>netty</artifactId>
> <version>3.6.10.Final</version>
> </dependency>
> ```
> package com.test.dubbo.service;
>
> import java.io.Serializable;
>
> public class User implements Serializable{
> /**
> *
> */
> private static final long serialVersionUID = 1L;
> private int id;
> private String username;
> private String password;
>
> ```
> public int getId() {
> return id;
> }
>
> public void setId(int id) {
> this.id = id;
> }
>
> public String getUsername() {
> return username;
> }
>
> public void setUsername(String username) {
> this.username = username;
> }
>
> public String getPassword() {
> return password;
> }
>
> public void setPassword(String password) {
> this.password = password;
> }
> ```
> }
>
> package com.test.dubbo.service;
>
> public interface EchoService {
>
> ```
> String sayHello();
>
> String echoWithTimeOut();
>
> String echoWithException();
>
> String sayHi();
>
> User getUser(int id);
> ```
> }
>
> package com.test.dubbo.service;
>
> import java.util.Iterator;
> import java.util.concurrent.TimeUnit;
>
> import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
>
> public class EchoServiceImpl implements EchoService {
> public String sayHello() {
> System.out.println("test");
> return "Hello World";
> }
>
> ```
> public String echoWithTimeOut() {
> try {
> for (int i = 1; i < 10; i++) {
> System.out.println("i==" + i);
> TimeUnit.SECONDS.sleep(i);
> }
> // Thread.sleep(10);
> } catch (InterruptedException e) {
> e.printStackTrace();
> }
> System.out.println("11111111...echoWithTimeOut");
> return "Hello World";
> }
>
> public String echoWithException() {
> System.out.println(String.format("%s", 10 / 0));
> System.out.println("2222222222.......echoWithException");
> return String.format("%s", 10 / 0);
> }
>
> public String sayHi() {
> String str = "Hi........DemoFallback!";
> System.out.println("-----------------" + str);
> return str;
> }
>
> public User getUser(int id) {
> System.out.println("getUser");
> System.out.println(String.format("%s", 10 / 0));
> User user=new User();
> user.setId(1);
> user.setUsername("test");
> user.setPassword("test");
> System.out.println("11111111562");
> return user;
> }
> ```
> }
>
> package com.test.dubbo;
>
> import com.test.dubbo.service.EchoService;
> import com.netflix.config.ConfigurationManager;
> import com.netflix.hystrix.HystrixThreadPoolKey;
> import com.netflix.hystrix.HystrixThreadPoolProperties;
> import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
> import com.netflix.hystrix.strategy.properties.HystrixPropertiesFactory;
> import org.junit.Assert;
> import org.junit.Before;
> import org.junit.Test;
> import org.springframework.context.support.ClassPathXmlApplicationContext;
>
> import java.util.concurrent.TimeUnit;
>
> public class ConsumerTest {
> EchoService echoService;
>
> ```
> @Before
> public void before() {
> ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] { "consumer.xml" });
> context.start();
> echoService = (EchoService) context.getBean("echoService", EchoService.class);
> }
>
> @Test
> public void test() {
> Assert.assertEquals("Hello World", echoService.sayHello());
> // System.out.println(echoService.sayHello());
> }
>
> @Test
> public void testTimeout() {
> // Assert.assertEquals("Hello World", echoService.echoWithTimeOut());
> System.out.println(echoService.echoWithTimeOut());
> System.out.println("555555555555555");
> }
>
>
> @Test
> public void testEchoException() {
> //echoService.echoWithException();
> // try {
> echoService.getUser(1);
> ```
> // } catch (Exception e) {
> // e.printStackTrace();
> // }
>
> ```
> System.out.println("666666666666");
> }
>
> @Test
> public void testThreadPool() throws InterruptedException {
> for (int i = 0; i < 20; i++) {
> new Thread(() -> {
> echoService.sayHello();
> }).start();
> System.out.println("i==="+i);
> Thread.sleep(100);
> }
> ```
> // for (int i = 0; i < 5; i++) {
> // String res =echoService.sayHello();
> // System.out.println("test=" + i + ":" + res + " The time:" + (System.currentTimeMillis() / 1000));
> // Thread.sleep(200);
> // }
>
> ```
> System.out.println("test...");
> }
> ```
> }
>
> package com.test.dubbo;
> import org.junit.Test;
> import org.springframework.context.support.ClassPathXmlApplicationContext;
>
> public class ProviderTest {
>
> ```
> @Test
> public void test() throws Exception {
> ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"provider.xml"});
> context.start();
>
> System.in.read(); // 按任意键退出
> context.close();
>
> }
> ```
> }
[ Full content available at: https://github.com/apache/incubator-dubbo/issues/2664 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org
[GitHub] [incubator-dubbo] k5h9999 commented on issue #2664: dubbo hystrix熔断集成问题,达不到熔断或降级的效果
Posted by "k5h9999 (GitHub)" <gi...@apache.org>.
> ```
> <dubbo:application name="consumer"/>
> <!-- 使用multicast广播注册中心暴露服务地址 -->
> <dubbo:registry address="zookeeper://127.0.0.1:2181"/>
>
> <!-- 生成远程服务代理,可以和本地bean一样使用demoService -->
> <dubbo:reference id="echoService" interface="com.test.dubbo.service.EchoService" check="false" retries="0">
> </dubbo:reference>
> ```
> ```
> <!-- 提供方应用信息,用于计算依赖关系 -->
> <dubbo:application name="provider"/>
> <!-- 和本地bean一样实现服务 -->
> <bean id="echoService" class="com.test.dubbo.service.EchoServiceImpl"/>
>
> <!-- 使用multicast广播注册中心暴露服务地址 -->
> <dubbo:registry address="zookeeper://127.0.0.1:2181"/>
>
> <!-- 用dubbo协议在20880端口暴露服务 -->
> <dubbo:protocol name="dubbo" port="20880"/>
> <!-- 声明需要暴露的服务接口 -->
> <dubbo:service interface="com.test.dubbo.service.EchoService" ref="echoService" retries="0" >
> </dubbo:service>
> ```
> pom.xml
>
> ```
> <dependency>
> <groupId>com.netflix.hystrix</groupId>
> <artifactId>hystrix-core</artifactId>
> <version>1.5.9</version>
> </dependency>
> <dependency>
> <groupId>com.github.sgroschupf</groupId>
> <artifactId>zkclient</artifactId>
> <version>0.1</version>
> </dependency>
><dependency>
> <groupId>com.alibaba</groupId>
> <artifactId>dubbo</artifactId>
> <version>2.8.4</version>
> </dependency>
><dependency>
> <groupId>com.alibaba</groupId>
> <artifactId>dubbo</artifactId>
> <version>2.5.3</version>
> </dependency>
> <dependency>
> <groupId>com.github.sgroschupf</groupId>
> <artifactId>zkclient</artifactId>
> <version>0.1</version>
> </dependency>
> <dependency>
> <groupId>org.slf4j</groupId>
> <artifactId>slf4j-api</artifactId>
> <version>1.7.24</version>
> </dependency>
> <dependency>
> <groupId>org.slf4j</groupId>
> <artifactId>slf4j-log4j12</artifactId>
> <version>1.7.24</version>
> <scope>test</scope>
> </dependency>
> <dependency>
> <groupId>io.netty</groupId>
> <artifactId>netty</artifactId>
> <version>3.6.10.Final</version>
> </dependency>
> ```
> package com.test.dubbo.service;
>
> import java.io.Serializable;
>
> public class User implements Serializable{
> /**
> *
> */
> private static final long serialVersionUID = 1L;
> private int id;
> private String username;
> private String password;
>
> ```
> public int getId() {
> return id;
> }
>
> public void setId(int id) {
> this.id = id;
> }
>
> public String getUsername() {
> return username;
> }
>
> public void setUsername(String username) {
> this.username = username;
> }
>
> public String getPassword() {
> return password;
> }
>
> public void setPassword(String password) {
> this.password = password;
> }
> ```
> }
>
> package com.test.dubbo.service;
>
> public interface EchoService {
>
> ```
> String sayHello();
>
> String echoWithTimeOut();
>
> String echoWithException();
>
> String sayHi();
>
> User getUser(int id);
> ```
> }
>
> package com.test.dubbo.service;
>
> import java.util.Iterator;
> import java.util.concurrent.TimeUnit;
>
> import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
>
> public class EchoServiceImpl implements EchoService {
> public String sayHello() {
> System.out.println("test");
> return "Hello World";
> }
>
> ```
> public String echoWithTimeOut() {
> try {
> for (int i = 1; i < 10; i++) {
> System.out.println("i==" + i);
> TimeUnit.SECONDS.sleep(i);
> }
> // Thread.sleep(10);
> } catch (InterruptedException e) {
> e.printStackTrace();
> }
> System.out.println("11111111...echoWithTimeOut");
> return "Hello World";
> }
>
> public String echoWithException() {
> System.out.println(String.format("%s", 10 / 0));
> System.out.println("2222222222.......echoWithException");
> return String.format("%s", 10 / 0);
> }
>
> public String sayHi() {
> String str = "Hi........DemoFallback!";
> System.out.println("-----------------" + str);
> return str;
> }
>
> public User getUser(int id) {
> System.out.println("getUser");
> System.out.println(String.format("%s", 10 / 0));
> User user=new User();
> user.setId(1);
> user.setUsername("test");
> user.setPassword("test");
> System.out.println("11111111562");
> return user;
> }
> ```
> }
>
> package com.test.dubbo;
>
> import com.test.dubbo.service.EchoService;
> import com.netflix.config.ConfigurationManager;
> import com.netflix.hystrix.HystrixThreadPoolKey;
> import com.netflix.hystrix.HystrixThreadPoolProperties;
> import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
> import com.netflix.hystrix.strategy.properties.HystrixPropertiesFactory;
> import org.junit.Assert;
> import org.junit.Before;
> import org.junit.Test;
> import org.springframework.context.support.ClassPathXmlApplicationContext;
>
> import java.util.concurrent.TimeUnit;
>
> public class ConsumerTest {
> EchoService echoService;
>
> ```
> @Before
> public void before() {
> ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] { "consumer.xml" });
> context.start();
> echoService = (EchoService) context.getBean("echoService", EchoService.class);
> }
>
> @Test
> public void test() {
> Assert.assertEquals("Hello World", echoService.sayHello());
> // System.out.println(echoService.sayHello());
> }
>
> @Test
> public void testTimeout() {
> // Assert.assertEquals("Hello World", echoService.echoWithTimeOut());
> System.out.println(echoService.echoWithTimeOut());
> System.out.println("555555555555555");
> }
>
>
> @Test
> public void testEchoException() {
> //echoService.echoWithException();
> // try {
> echoService.getUser(1);
> ```
> // } catch (Exception e) {
> // e.printStackTrace();
> // }
>
> ```
> System.out.println("666666666666");
> }
>
> @Test
> public void testThreadPool() throws InterruptedException {
> for (int i = 0; i < 20; i++) {
> new Thread(() -> {
> echoService.sayHello();
> }).start();
> System.out.println("i==="+i);
> Thread.sleep(100);
> }
> ```
> // for (int i = 0; i < 5; i++) {
> // String res =echoService.sayHello();
> // System.out.println("test=" + i + ":" + res + " The time:" + (System.currentTimeMillis() / 1000));
> // Thread.sleep(200);
> // }
>
> ```
> System.out.println("test...");
> }
> ```
> }
>
> package com.test.dubbo;
> import org.junit.Test;
> import org.springframework.context.support.ClassPathXmlApplicationContext;
>
> public class ProviderTest {
>
> ```
> @Test
> public void test() throws Exception
1. {
> ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"provider.xml"});
> context.start();
>
> System.in.read(); // 按任意键退出
> context.close();
>
> }
> ```
> }
- [ ]
[ Full content available at: https://github.com/apache/incubator-dubbo/issues/2664 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org
[GitHub] [incubator-dubbo] carryxyh closed issue #2664: dubbo hystrix熔断集成问题,达不到熔断或降级的效果
Posted by "carryxyh (GitHub)" <gi...@apache.org>.
[ issue closed by carryxyh ]
[ Full content available at: https://github.com/apache/incubator-dubbo/issues/2664 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org
[GitHub] [incubator-dubbo] moayi commented on issue #2664: dubbo hystrix熔断集成问题,达不到熔断或降级的效果
Posted by "moayi (GitHub)" <gi...@apache.org>.
你好,你的这个解决了吗?谢谢
[ Full content available at: https://github.com/apache/incubator-dubbo/issues/2664 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org
[GitHub] [incubator-dubbo] carryxyh commented on issue #2664: dubbo hystrix熔断集成问题,达不到熔断或降级的效果
Posted by "carryxyh (GitHub)" <gi...@apache.org>.
Can you provide a complete demo?
You can upload the demo to github and provide the address of github.
Throws a classcast exception, so I guess this is not a problem with dubbo.
[ Full content available at: https://github.com/apache/incubator-dubbo/issues/2664 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org
[GitHub] [incubator-dubbo] k5h9999 closed issue #2664: dubbo hystrix熔断集成问题,达不到熔断或降级的效果
Posted by "k5h9999 (GitHub)" <gi...@apache.org>.
[ issue closed by k5h9999 ]
[ Full content available at: https://github.com/apache/incubator-dubbo/issues/2664 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org
[GitHub] [incubator-dubbo] hepin1989 commented on issue #2664: dubbo hystrix熔断集成问题,达不到熔断或降级的效果
Posted by "hepin1989 (GitHub)" <gi...@apache.org>.
应该是断路器。
[ Full content available at: https://github.com/apache/incubator-dubbo/issues/2664 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org
[GitHub] [incubator-dubbo] k5h9999 commented on issue #2664: dubbo hystrix熔断集成问题,达不到熔断或降级的效果
Posted by "k5h9999 (GitHub)" <gi...@apache.org>.
> ```
> <dubbo:application name="consumer"/>
> <!-- 使用multicast广播注册中心暴露服务地址 -->
> <dubbo:registry address="zookeeper://127.0.0.1:2181"/>
>
> <!-- 生成远程服务代理,可以和本地bean一样使用demoService -->
> <dubbo:reference id="echoService" interface="com.test.dubbo.service.EchoService" check="false" retries="0">
> </dubbo:reference>
> ```
> ```
> <!-- 提供方应用信息,用于计算依赖关系 -->
> <dubbo:application name="provider"/>
> <!-- 和本地bean一样实现服务 -->
> <bean id="echoService" class="com.test.dubbo.service.EchoServiceImpl"/>
>
> <!-- 使用multicast广播注册中心暴露服务地址 -->
> <dubbo:registry address="zookeeper://127.0.0.1:2181"/>
>
> <!-- 用dubbo协议在20880端口暴露服务 -->
> <dubbo:protocol name="dubbo" port="20880"/>
> <!-- 声明需要暴露的服务接口 -->
> <dubbo:service interface="com.test.dubbo.service.EchoService" ref="echoService" retries="0" >
> </dubbo:service>
> ```
> pom.xml
>
> ```
> <dependency>
> <groupId>com.netflix.hystrix</groupId>
> <artifactId>hystrix-core</artifactId>
> <version>1.5.9</version>
> </dependency>
<dependency>
<groupId>com.github.sgroschupf</groupId>
<artifactId>zkclient</artifactId>
<version>0.1</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
<version>2.8.4</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
<version>2.5.3</version>
</dependency>
<dependency>
<groupId>com.github.sgroschupf</groupId>
<artifactId>zkclient</artifactId>
<version>0.1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.24</version>
</dependency>
> <dependency>
> <groupId>org.slf4j</groupId>
> <artifactId>slf4j-log4j12</artifactId>
> <version>1.7.24</version>
> <scope>test</scope>
> </dependency>
> <dependency>
> <groupId>io.netty</groupId>
> <artifactId>netty</artifactId>
> <version>3.6.10.Final</version>
> </dependency>
> ```
> package com.test.dubbo.service;
>
> import java.io.Serializable;
>
> public class User implements Serializable{
> /**
> *
> */
> private static final long serialVersionUID = 1L;
> private int id;
> private String username;
> private String password;
>
> ```
> public int getId() {
> return id;
> }
>
> public void setId(int id) {
> this.id = id;
> }
>
> public String getUsername() {
> return username;
> }
>
> public void setUsername(String username) {
> this.username = username;
> }
>
> public String getPassword() {
> return password;
> }
>
> public void setPassword(String password) {
> this.password = password;
> }
> ```
> }
>
> package com.test.dubbo.service;
>
> public interface EchoService {
>
> ```
> String sayHello();
>
> String echoWithTimeOut();
>
> String echoWithException();
>
> String sayHi();
>
> User getUser(int id);
> ```
> }
>
> package com.test.dubbo.service;
>
> import java.util.Iterator;
> import java.util.concurrent.TimeUnit;
>
> import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
>
> public class EchoServiceImpl implements EchoService {
> public String sayHello() {
> System.out.println("test");
> return "Hello World";
> }
>
> ```
> public String echoWithTimeOut() {
> try {
> for (int i = 1; i < 10; i++) {
> System.out.println("i==" + i);
> TimeUnit.SECONDS.sleep(i);
> }
> // Thread.sleep(10);
> } catch (InterruptedException e) {
> e.printStackTrace();
> }
> System.out.println("11111111...echoWithTimeOut");
> return "Hello World";
> }
>
> public String echoWithException() {
> System.out.println(String.format("%s", 10 / 0));
> System.out.println("2222222222.......echoWithException");
> return String.format("%s", 10 / 0);
> }
>
> public String sayHi() {
> String str = "Hi........DemoFallback!";
> System.out.println("-----------------" + str);
> return str;
> }
>
> public User getUser(int id) {
> System.out.println("getUser");
> System.out.println(String.format("%s", 10 / 0));
> User user=new User();
> user.setId(1);
> user.setUsername("test");
> user.setPassword("test");
> System.out.println("11111111562");
> return user;
> }
> ```
> }
>
> package com.test.dubbo;
>
> import com.test.dubbo.service.EchoService;
> import com.netflix.config.ConfigurationManager;
> import com.netflix.hystrix.HystrixThreadPoolKey;
> import com.netflix.hystrix.HystrixThreadPoolProperties;
> import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
> import com.netflix.hystrix.strategy.properties.HystrixPropertiesFactory;
> import org.junit.Assert;
> import org.junit.Before;
> import org.junit.Test;
> import org.springframework.context.support.ClassPathXmlApplicationContext;
>
> import java.util.concurrent.TimeUnit;
>
> public class ConsumerTest {
> EchoService echoService;
>
> ```
> @Before
> public void before() {
> ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] { "consumer.xml" });
> context.start();
> echoService = (EchoService) context.getBean("echoService", EchoService.class);
> }
>
> @Test
> public void test() {
> Assert.assertEquals("Hello World", echoService.sayHello());
> // System.out.println(echoService.sayHello());
> }
>
> @Test
> public void testTimeout() {
> // Assert.assertEquals("Hello World", echoService.echoWithTimeOut());
> System.out.println(echoService.echoWithTimeOut());
> System.out.println("555555555555555");
> }
>
>
> @Test
> public void testEchoException() {
> //echoService.echoWithException();
> // try {
> echoService.getUser(1);
> ```
> // } catch (Exception e) {
> // e.printStackTrace();
> // }
>
> ```
> System.out.println("666666666666");
> }
>
> @Test
> public void testThreadPool() throws InterruptedException {
> for (int i = 0; i < 20; i++) {
> new Thread(() -> {
> echoService.sayHello();
> }).start();
> System.out.println("i==="+i);
> Thread.sleep(100);
> }
> ```
> // for (int i = 0; i < 5; i++) {
> // String res =echoService.sayHello();
> // System.out.println("test=" + i + ":" + res + " The time:" + (System.currentTimeMillis() / 1000));
> // Thread.sleep(200);
> // }
>
> ```
> System.out.println("test...");
> }
> ```
> }
>
> package com.test.dubbo;
> import org.junit.Test;
> import org.springframework.context.support.ClassPathXmlApplicationContext;
>
> public class ProviderTest {
>
> ```
> @Test
> public void test() throws Exception {
> ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"provider.xml"});
> context.start();
>
> System.in.read(); // 按任意键退出
> context.close();
>
> }
> ```
> }
[ Full content available at: https://github.com/apache/incubator-dubbo/issues/2664 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org