当我使用 @HystrixCommand Annotation 注释一个方法时,它是如何工作的
@HystrixCommand(fallbackMethod="getfallBackdisplayDoctorsAndProducts_lipid",
commandProperties= {
@HystrixProperty(name="execution.isolation.thread.timeoutInMilliseconds",value="150"),
@HystrixProperty(name="circuitBreaker.requestVolumeThreshold",value="25"),
@HystrixProperty(name="circuitBreaker.errorThresholdPercentage",value="50"),
@HystrixProperty(name="circuitBreaker.sleepWindowInMilliseconds",value="5000")
})
public List<DoctorsAndProducts> displayDoctorsAndProducts(LipidProfile lipidProfile)
{
}
Run Code Online (Sandbox Code Playgroud) 当我使用FeignClient它时,它设置Content-Type为application/x-www-form-urlencoded而不是application/json;charset=UTF-8.
如果我使用a RestTemplate发送相同的消息,则消息头Content-Type正确设置为application/json;charset=UTF-8.
无论是FeignClient和RestTemplate正在使用Eureka的服务发现,并通过我调试服务器接收HTTP消息发现了这个问题.
服务器端的控制器如下所示:
@RestController
@RequestMapping("/site/alarm")
public class SiteAlarmController {
@RequestMapping(method = RequestMethod.POST)
@ResponseBody
public ResponseEntity<RaiseAlarmResponseDto> raiseAlarm(@RequestBody RaiseSiteAlarmRequestDto requestDto) {
...
}
Run Code Online (Sandbox Code Playgroud)
我FeignClient在电话报警的服务接口看起来是这样的:
@FeignClient("alarm-service")
public interface AlarmFeignService {
@RequestMapping(method = RequestMethod.POST, value = "/site/alarm")
RaiseAlarmResponseDto raiseAlarm(@RequestBody RaiseSiteAlarmRequestDto requestDto);
}
Run Code Online (Sandbox Code Playgroud)
来自的HTTP消息头FeignClient是:
Accept: */*
Cache-Control: no-cache
Pragma: no-cache
User-Agent: Java/1.7.0_60
Host: smit005s-MacBook-Pro.local:9120
Connection: keep-alive
Content-Type: application/x-www-form-urlencoded
Content-Length: 323 …Run Code Online (Sandbox Code Playgroud) 我见过很多项目的例子,其中同时使用了 Hystrix 和 Eureka。如果有人能向我解释他们是如何交流的,那就太好了。也许这是一个错误的构建问题,但我想知道为什么项目中同时存在 hystrix 和 eureka。
我有两个微服务,
这两个都是在本地主机上运行的'eureka-server'注册的DiscoveryClient:8761。
在下面的代码片段中,我尝试从eureka-client-1调用eureka-client-2。我不想调用http:// localhost:8082,而是要调用http:// eureka-client-2,但这会在Eureka服务发现期间引发java.net.UnknownHostException。
搜索之后,我发现我需要使用“ Brixton”来完成它。
有没有办法使用Camden.SR3?
请提出建议。
@Component
public class HystrixDemoService {
@Bean
@LoadBalanced
public RestTemplate restTemplate() {
return new RestTemplate();
}
@HystrixCommand(fallbackMethod = "getFallbackCustomerName")
public String getCustomerName() {
RestTemplate restTemplate = new RestTemplate();
URI uri = URI.create("http://eureka-client-2"); // fails here
return restTemplate.getForObject(uri, String.class);
}
public String getFallbackCustomerName() {
System.out.println("coming inside fallback method");
return "Resillient Customer";
}
}
Run Code Online (Sandbox Code Playgroud)
pom.xml
<?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>
<groupId>com.example</groupId>
<artifactId>demo-pranay-eureka-client1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging> …Run Code Online (Sandbox Code Playgroud) 我们计划使用Spring Cloud Netflix oss组件.所以我做了一个小样本项目.我开发了2个spring微服务,这些服务在 http:// localhost:9000/microsvc-one http:// localhost:9001/microsvc-two上运行良好
并且还编写了一个示例spring cloud etflix eureka maven项目,该项目在http:// localhost:8761上运行良好
我在spring boot微服务主类上使用@EurekaDiscoveryClient和@SpringBootApplication注释
我使用了注释@EnableEurekaServer和@SpringBootApplication
现在我在eureka服务器中注册这些服务时遇到了问题.我提到了一些样本.我不理解那些.我对microsvc-one和microsvc-two的application.yml文件以及eureka服务器的application.yml文件进行了一些更改.但它仍显示为空.
所有更改都需要或丢失或正确配置,以便我的服务在eureka上注册.
我还有其他问题,比如我需要创建一个单独的项目,其中包含@EnableConfigServer和@SpringBootApplication Annotations,而不是上述2个微服务和eureka服务器项目模块,以便在eureka上注册服务.我在大多数例子中看到了这些.
如果是的话.我们如何在这些之间建立联系?
spring-boot microservices netflix-eureka spring-cloud-netflix
我们正在使用 Eureka 和 AWS ECS 服务,可以扩展 docker 容器。在 ECS 中,如果您在任务定义中省略主机端口或将其指定为“0”,则该端口将被自动选择并报告回服务。任务运行后,描述它应该显示它绑定到的端口。
如果我们有多个 EC2 实例,Eureka 如何解决使用哪个端口。例如,来自 EC2-A 的服务 A 尝试从 EC2-B 调用服务 B。所以 Eureka 可以解析主机名,但无法识别暴露的端口
amazon-web-services amazon-ecs netflix-eureka netflix-zuul spring-cloud-netflix
我们使用Spring Cloud Netflix提供了一系列使用Spring Boot构建的微服务。到目前为止,它们已打包为RPM并已部署到VM。显然,使用Eureka可以进行服务注册/发现,并且我们的跨微服务交互可以使用带有虚拟IP(VIP)的Spring RestTemplate完成,如下所示:
http://foo-service/<PATH_TO_RESOURCE>
Run Code Online (Sandbox Code Playgroud)
客户端负载平衡是另一个好处。
现在,我们希望使用Docker并在Rancher中运行。我想知道在这种环境下使用Eureka还是有意义的。
在Rancher中,如果该服务名为“ foo-service”,则该名称将用作Rancher内部网络中的VIP,因此,上面显示的相同URL也可以使用,Eureka除外。
此外,如果有多个容器支持服务,则Rancher将在其中循环负载均衡流量。
另外,似乎Rancher会比Eureka更早地了解Containers的来来往往。
我正在努力寻找保留尤里卡的坚实理由。
我是微服务的新手。我正在尝试创建一个用于学习目的的小型应用程序。这是我的代码:EurekaServer - application.yml
spring:
application:
name: EurekaServer
server:
port: 8080
servlet:
context-path: /EurekaServer
eureka:
client:
fetch-registry: false
register-with-eureka: false
Run Code Online (Sandbox Code Playgroud)
Eureka Server 工作正常,我可以在http://localhost:8080/EurekaServer看到仪表板
EmployeeClient:application.yml 如下:
spring:
application:
name: EmployeeClient
server:
port: 8586
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8080/EurekaServer
Run Code Online (Sandbox Code Playgroud)
在最后一行中,我需要像在 sts 中按 ctrl+space 一样显式地编写 serviceUrl 它不显示选项 serviceUrl 但它显示 service-url、连字符符号。与 defaultZone 相同。我是否缺少一些 jar 或特定版本?
我的 EmployeeClientApplication.java
@EnableEurekaClient
@SpringBootApplication
public class EmployeeClientApplication {
public static void main(String[] args) {
SpringApplication.run(EmployeeClientApplication.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
当我尝试运行 EmployeeClientApplication.java 时,它给了我以下异常:
com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known …Run Code Online (Sandbox Code Playgroud) 我刚开始使用微服务,我想创建一个简单的 Eureka 服务器来执行我的 Serviceregistry。现在我只想在本地主机上运行服务器,稍后我想添加一个注册到它的示例微服务。问题是我在尝试启动 Eureka Server 时遇到错误。我在 Eclipse 中使用 Spring 和 Maven 在 ubuntu vm 中进行开发。
我的 POM.xml 如下所示:
http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0
<groupId>com.example.cloud</groupId>
<artifactId>eureka-service-new</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>eureka-service-new</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring-cloud.version>Edgware.SR2</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId> …Run Code Online (Sandbox Code Playgroud) 我有 Zuul + Eureka + Spring Boot Service Endpoint + Hateoas 响应配置。当我通过 Zuul Gateway 访问服务时,响应中的资源链接是到服务端点的直接链接,它们不应该是网关链接吗?我在这里缺少什么?
网关端点:http://localhost:8762/catalog/products/10001 直接服务端点:http://localhost:8100/products/10001
Zuul 的 application.properties
spring.application.name=zuul-server
eureka.client.service-url.default-zone=http://localhost:8761/eureka/
# Map paths to services
zuul.routes.catalog-service=/catalog/**
zuul.addProxyHeaders=true
Run Code Online (Sandbox Code Playgroud)
网关端点的实际响应:http://localhost:8762/catalog/products/10001
{
"title" : "The Title",
"description" : "The Description",
"brand" : "SOME BRAND",
"price" : 100,
"color" : "Black",
"_links" : {
"self" : {
"href" : "http://localhost:8100/products/10001"
}
}
}
Run Code Online (Sandbox Code Playgroud)
预期响应应在 href 中包含网关 URL
{
"title" : "The Title",
"description" : "The Description",
"brand" : "SOME …Run Code Online (Sandbox Code Playgroud) spring spring-hateoas spring-boot netflix-eureka netflix-zuul
netflix-eureka ×10
spring-boot ×7
spring ×3
hystrix ×2
netflix-zuul ×2
spring-cloud ×2
amazon-ecs ×1
docker ×1
eclipse ×1
java ×1
maven ×1
netflix ×1
rancher ×1
tomcat ×1