我有简单的服务:
transactions-core-service和transactions-api-service。
transactions-api-service调用transactions-core-service来返回事务列表。使用hystrix命令启用transactions-api-service。
两者均在以下服务ID的Eureka服务器中注册:
bool MySortFilterProxyModel::filterAcceptsRow(int sourceRow,
const QModelIndex &sourceParent) const
{
QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
return ShowThis(index);
}
bool MySortFilterProxyModel::ShowThis(const QModelIndex index) const
{
bool retVal = false;
//Gives you the info for number of childs with a parent
if ( sourceModel()->rowCount(index) > 0 )
{
for( int nChild = 0; nChild < sourceModel()->rowCount(index); nChild++)
{
QModelIndex childIndex = sourceModel()->index(nChild,0,index);
if ( ! childIndex.isValid() )
break;
retVal = ShowThis(childIndex);
if (retVal)
{
break;
}
}
}
else
{
QModelIndex useIndex0 = sourceModel()->index(index.row(), 0, index.parent());
QString name = sourceModel()->data(useIndex0, Qt::DisplayRole).toString();
QModelIndex useIndex1 = sourceModel()->index(index.row(), 1, index.parent());
QString value = sourceModel()->data(useIndex1, Qt::DisplayRole).toString();
std::cout << "name : " << name.toStdString() << ", value : " << value.toStdString() << "\n";// , filterRegExp : " << filterRegExp() << "\n";
if ( (name.contains(filterRegExp()) || value.contains(filterRegExp())) )
{
retVal = true;
}
else
retVal = false;
}`enter code here`
return retVal;
}
以下是Zuul服务器:
TRANSACTIONS-API-SERVICE n/a (1) (1) UP (1) - 192.168.2.12:transactions-api-service:8083
TRANSACTIONS-CORE-SERVICE n/a (1) (1) UP (1) - 192.168.2.12:transactions-core-service:8087
Zuul配置:
@SpringBootApplication
@Controller
@EnableZuulProxy
public class ZuulApplication {
public static void main(String[] args) {
new SpringApplicationBuilder(ZuulApplication.class).web(true).run(args);
}
}
当我尝试使用url(===============================================
info:
component: Zuul Server
server:
port: 8765
endpoints:
restart:
enabled: true
shutdown:
enabled: true
health:
sensitive: false
zuul:
ignoredServices: "*"
routes:
transactions-api-service:
path: transactions/accounts/**
serviceId: transactions-api-service
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
logging:
level:
ROOT: INFO
org.springframework.web: DEBUG
===============================================
)调用transactions-api-service时,我得到了Zuul异常:
2016-02-13 11:29:29.050 WARN 4936 --- [nio-8765-exec-1] o.s.c.n.z.filters.post.SendErrorFilter:过滤期间出错
com.netflix.zuul.exception.ZuulException:转发错误 在org.springframework.cloud.netflix.zuul.filters.route.RibbonRoutingFilter.forward(RibbonRoutingFilter.java:131) 〜[spring-cloud-net flix-core-1.1.0.M3.jar:1.1.0.M3] 在org.springframework.cloud.netflix.zuul.filters.route.RibbonRoutingFilter.run(RibbonRoutingFilter.java:76) 〜[spring-cloud-netflix-core-1.1.0.M3.jar:1.1.0.M3] ......
如果我单独调用transactions-api-service(使用http://localhost:8765/transactions/accounts/123/transactions/786
),它可以正常工作。
我错过了Zuul的任何配置吗?
答案 0 :(得分:7)
您需要通过在zuul服务器的 application.yml 中添加此属性来更改zuul执行超时:
# Increase the Hystrix timeout to 60s (globally)
hystrix:
command:
default:
execution:
isolation:
thread:
timeoutInMilliseconds: 60000
请参阅netflix问题的这个主题:https://github.com/spring-cloud/spring-cloud-netflix/issues/321
答案 1 :(得分:4)
您的缩进不正确。而不是:
zuul:
ignoredServices: "*"
routes:
transactions-api-service:
path: transactions/accounts/**
serviceId: transactions-api-service
应该是:
zuul:
ignoredServices: "*"
routes:
transactions-api-service:
path: transactions/accounts/**
serviceId: transactions-api-service
答案 2 :(得分:1)
答案 3 :(得分:1)
您可以使用它来避免500错误
hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds = 1000000
zuul.host.connect-timeout-millis = 10000
zuul.host.socket-timeout-millis = 1000000
答案 4 :(得分:0)
我遇到了同样的问题,然后我意识到我正在使用不同版本的Spring Cloud和Spring Boot。
现在,我使用了最新版本的fresh,它不会引发任何错误。
不确定为什么会发生,但我分享了 my repo link here,以便大家看看。
尽管我仍然无法访问路线,但是该服务运行正常。
我刚刚使用了从start.spring.io下载的项目。
答案 5 :(得分:0)
如果在这种情况下,如果您的Zuul网关使用发现服务进行服务查找,则可以禁用hystrix超时或增加hysterix超时,如下所示:
# Disable Hystrix timeout globally (for all services)
hystrix.command.default.execution.timeout.enabled: false
#To disable timeout foror particular service,
hystrix.command.<serviceName>.execution.timeout.enabled: false
# Increase the Hystrix timeout to 60s (globally)
hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds: 60000
# Increase the Hystrix timeout to 60s (per service)
hystrix.command.<serviceName>.execution.isolation.thread.timeoutInMilliseconds: 60000