- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
在我正在构建的 REST 客户端中连接到远程服务时,我使用 Netflix 的 Hystrix 库充当断路器。我想通过他们提供的库设置事件流和仪表板监控。查看他们的示例应用程序 here ,看来我需要将他们的 servlet 过滤器和 servlet 类应用于我的 Web 应用程序。
我将 Spring Boot 与 Jersey 2 结合使用,并在 JerseyConfig.java(无 web.xml)中连接我的资源和过滤器。我知道 Jersey Filters 与 Servlet Filters 不同,并且正在努力将两者集成在一起。
那么,如何将 Java Servlet 过滤器用作 Jersey 过滤器,以及如何将 Java Servlet 用作 Jersey 资源?
我目前对 Servlet 的策略是像这样包装它们。一人一份。
@Path("/hystrix.stream")
public class HystrixResource extends HystrixUtilizationSseServlet {
@Context
HttpServletRequest httpRequest;
@Context
HttpServletResponse httpResponse;
//This returns void because it is a text/stream output that must remain open,
//so the httpResponse is continually written to until the conenction is closed
@GET
public void doGet() throws ServletException, IOException {
doGet(httpRequest, httpResponse);
}
}
这可能有效,但由于某种原因数据基本上是空的。我猜这是因为过滤器不起作用。
data: {"type":"HystrixUtilization","commands":{},"threadpools":{}}
我不太清楚如何包装 Servlet 过滤器,因为它们期望与 Jersey ContainerRequestFilter 不同的输入和输出。我的 JerseyConfig 中的以下实现似乎什么都不做,因为日志没有表明正在注册过滤器,而且我无法在 Debug模式下中断这些文件中的行。
@Component
@ApplicationPath("/")
public class JerseyConfig extends ResourceConfig {
private static final Logger LOGGER = Logger.getLogger("JerseyConfig");
public JerseyConfig(){
//filter to provide a bridge between JAX-RS and Spring request attributes
register(RequestContextFilter.class);
register(SpringComponentProvider.class);
//handles custom serialization
register(new ObjectMapperContextResolver());
//try to register the filters - which doesn't work because these aren't Jersey Filters
register(HystrixRequestContextServletFilter.class);
register(HystrixRequestLogViaResponseHeaderServletFilter.class);
registerResources();
/*
* Enable the logging filter to see the HTTP response for each request.
*/
register(new LoggingFilter(LOGGER, true));
}
}
最佳答案
Servlet 和 Servlet 过滤器不应在 Jersey 配置中注册。他们将被忽略。您应该使用 ServletRegistrationBean
在 Spring Boot 中注册它们s 和 FilterRegistrationBean
在你的Spring配置中,你可以做类似的事情
@Bean
public ServletRegistrationBean someServlet() {
ServletRegistrationBean registration = ServletRegisrationBean(
new HystrixMetricsStreamServlet(), "/hystrix.stream");
registration.setName("HystrixMetricsStreamServlet");
return registration;
}
@Bean
public FilterRegistrationBean someFilter() {
FilterRegistrationBean registration = new FilterRegistrationBean();
registration.setFilter(new HystrixRequestContextServletFilter());
registration.setUrlPatterns(Arrays.asList("/*"));
registration.setName("HystrixRequestContextServletFilter");
// you can also set the order of filters if you need to
return registration;
}
还有:
SpringComponentProvider
。这是自动注册的。/*
,它占用了所有请求。您可以更改映射或将 Jersey 注册为过滤器以转发未找到的请求。参见 this post 关于java - 在 Jersey 2 中使用 Hystrix Java Servlet 和 Servlet 过滤器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38106445/
我打算使用 hystrix 命令进行远程 http 调用(httpclient)。如果调用因任何原因失败,我想回退到另一个 http 调用,假设我在 fallbackMethod1() 中进行。如果回
我正在将 Hystrix 集成到应用程序中。该应用程序已经投入生产,在将其投入生产之前,我们将在沙箱中测试 hystrix 集成工作。我的问题是有没有办法使用某些配置设置来打开/关闭 hystrix
我正在尝试使用hyst,但是在调用save方法时,该方法使带有resttemplate的帖子出现以下异常: com.netflix.hystrix.contrib.javanica.exception
需要为其中一个项目使用断路器并使用 hystrix 来达到此目的。但是即使超时后也不会触发 hystrix 回退。如果遗漏了什么,请帮忙。先感谢您。 https://github.com/Netfli
我的 Hystrix 命令有问题。如果对 hystrix 包装方法的调用来自类内部,则 hystrix 包装方法不会在 Hystrix 环境中运行 在这种情况下,我将日志视为 05-02-2018 2
我有一个内部调用 soap 网络服务的休息应用程序(基于 cxf)。我想将 hystrix 集成到我的其余应用程序中。 1) 使用我们现有的服务数据修改了下面的 hystrix 演示源代码并部署了其余
我正在使用 Feign 创建一个 REST 客户端。我的电话工作正常,但我想添加一些超时支持,而且我有一段时间想弄清楚如何做到这一点。 Feign 的文档说“要将 Hystrix 与 Feign 一起
我有一个 Dropwizard 0.8.1 应用程序,我在其中添加了一些 HystrixCommand 类,用于调用各种外部服务。我现在想可视化与对这些服务的调用相关的统计信息,但我似乎无法让我的应用
其中ctx我应该在 run 中使用吗? hystrix.Do的参数hystrix-go的功能包裹? ctx从上层,还是 context.Background()? 谢谢。 package main i
我在 localhost:8988/hystrix 上运行了 Hystrix 仪表板,我想监控 OrderService 和 ProductService 之间的请求。端点“hystrix.strea
我在 Spring Boot 应用程序中使用 spring-cloud-starter-hystrix:1.2.3.RELEASE。我有 1 个 HystrixCommand,我可以成功执行。之后我调
1、Hystrix与Rhino对比 项目 Hystrix Rhino 接入方式 提供了注解和API两种接入方
1、执行方式 HystrixCommand提供了3种执行方式: 1、同步执行 即一旦开始执行该命令,当前线程就得阻塞着直到该命令返回结果,然后才能继续执行下面的逻辑。当调用命令的execute(
因为在一个复杂的系统里,可能你的依赖接口的性能很不稳定,有时候2ms,200ms,2s,如果你不对各种依赖接口的调用做超时的控制来给你的服务提供安全保护措施,那么很可能你的服务就被依赖服务的性能给拖死
hystrix介绍 Hystrix 供分布式系统使用,提供延迟和容错功能,隔离远程系统、访问和第三方程序库的访问点,防止级联失败,保证复杂的分布系统在面临不可避免的失败时,仍能有其弹性。 hyst
hystrix提供了两种隔离策略:线程池隔离和信号量隔离。hystrix默认采用线程池隔离。 1、线程池隔离 不同服务通过使用不同线程池,彼此间将不受影响,达到隔离效果。 例如: 我们可以通过
hystrix支持N个请求自动合并为一个请求,这个功能在有网络交互的场景下尤其有用,比如每个请求都要网络访问远程资源,如果把请求合并为一个,将使多次网络交互变成一次,极大节省开销。重要一点,两个请求能
声明:本文仅做个人的一次接口重构过程记录,期间参考了一些写的不错的博客,如果存在抄袭,请留言。 hystrix基本介绍 hystrix 是一个开源的容灾框架,目的是为了解决当依赖服务出现故障或者接
配置HystrixCommand HystxixCommand支持如下的配置: GroupKey:该命令属于哪一个组,可以帮助我们更好的组织命令。 CommandKey:该命令的名称 Thread
Hystrix使用fallback机制很简单,继承HystrixCommand只需重写getFallback(),继承HystrixObservableCommand只需重写resumeWithFal
我是一名优秀的程序员,十分优秀!