我正在尝试将微服务注册为 Eureka 客户端以发现其他微服务,但是,我按照教程进行操作,但 Eureka 服务器中没有任何显示。下面是代码片段:
我的demo应用程序:一个在 上运行的 spring 启动应用程序localhost:9001,我希望它成为一个 Eureka 客户端,即,将自己注册为一个实例,同时具有发现其他实例的能力(我使用了通用@EnableDiscoveryClient注释并且 Spring Netflix Eureka 在类路径上):
@RestController
@SpringBootApplication
@EnableDiscoveryClient
public class DemoApplication {
@RequestMapping("/")
String home() {
return "This is a Demo project";
}
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)应用程序.yml:
server:
port: 9001
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
Run Code Online (Sandbox Code Playgroud)Eureka 服务器应该没问题,因为我localhost:8080在服务器上成功注册了另一个正在运行的 Miscroservice 。以防万一,这里是 Eureka 服务器的 application.yml:
server:
port: 8761
eureka:
instance:
hostname: localhost
client:
registerWithEureka: false
fetchRegistry: false
serviceUrl: …Run Code Online (Sandbox Code Playgroud) 有一个 Eureka Server 应用程序:
@EnableEurekaServer
@SpringBootApplication
public class RegistrationModulesServiceApplication {
public static void main(String[] args) {
SpringApplication.run(RegistrationModulesServiceApplication.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
使用 appplicaton.yml 配置(默认):
eureka:
instance:
hostname: localhost
client:
registerWithEureka: false
fetchRegistry: false
server:
port: 1111
Run Code Online (Sandbox Code Playgroud)
在第一次运行时 - 我看到了带有状态的仪表板。就像在文档中一样:

为什么?
日志中没有错误。
我一直在网上搜寻有关将 spring-cloud-netflix eureka 服务器部署到 aws 的正确方法的指导。我们一直在为使用 spring-cloud 和 nodejs 的微服务使用 docker,所以我一直在尝试将我的 spring-boot spring-cloud eureka 应用程序部署到 ECS。spring-cloud 文档中的信息非常有限,但我在这里找到了一些相当有用的信息:https : //www.slideshare.net/ToddMiller34/spring-cloud-into-production。基于此,我目前有以下几点:
标准 spring-cloud-starter-eureka-server (spring-cloud Camden.SR5, spring-boot 1.5.1) 与
@Bean
@Autowired
@Profile("aws")
public EurekaInstanceConfigBean eurekaInstanceConfigBean(InetUtils inetUtils) {
EurekaInstanceConfigBean config = new EurekaInstanceConfigBean(inetUtils);
AmazonInfo info = AmazonInfo.Builder.newBuilder().autoBuild("eureka");
config.setHostname(info.get(AmazonInfo.MetaDataKey.publicHostname));
config.setIpAddress(info.get(AmazonInfo.MetaDataKey.publicIpv4));
config.setDataCenterInfo(info);
return config;
}
Run Code Online (Sandbox Code Playgroud)
来自 cloud config repo 的相关配置部分:
eureka:
instance:
non-secure-port: ${server.port}
environment: test
client:
eurekaServerDNSName: test.mydomain.com
datacenter: cloud
client:
region: us-west-2
registerWithEureka: true
fetchRegistry: true
eurekaServerURLContext: eureka
eurekaServerPort: 8761
useDnsForFetchingServiceUrls: true …Run Code Online (Sandbox Code Playgroud) 我正在使用 spring boot 和 netflix OSS 在微服务中创建一个简单的项目来弄脏我的手。我创建了两个服务
现在,当我启动这些服务时,由于相互依赖,这两个服务都失败了。解决此问题的最佳实践是什么以及首先开始哪个实践。
PS:-我知道我正在创建循环依赖,但是处理这种情况的方法是什么,我想将 eureka 配置也保留在配置服务器上
谢谢
intellij-idea netflix spring-boot microservices netflix-eureka
我有两个不同的微服务,使用 eureka 作为服务注册表,现在我试图从另一个调用微服务,使用功能区解析端点以进行客户端负载平衡。
服务一:
这个服务暴露了一个端点,http://localhost:15000/api/user/{userId},application.yml 如下,
# Spring properties
spring:
application:
name: user_microservice
cloud:
config:
discovery:
enabled: false
# HTTP Server
server:
port: 15000 # HTTP (Tomcat) port
# Discovery Server Access
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
instance:
instanceId: ${spring.application.name}:${random.int}
metadataMap:
instanceId: ${spring.application.name}:${random.int}
logging:
level:
com.netflix.discovery: 'OFF'
org.springframework.cloud: 'DEBUG'
Run Code Online (Sandbox Code Playgroud)
调用服务 A 的服务 B 具有以下应用程序类:
@EnableDiscoveryClient
@SpringBootApplication
public class UserSummaryApplication {
public static void main(String[] args) {
SpringApplication.run(UserSummaryApplication.class, args);
}
@Bean(name = "restTemplate")
RestTemplate restTemplate() {
return new RestTemplate(); …Run Code Online (Sandbox Code Playgroud) 在 Cloud config 中,我们存储了其他微服务可以访问的配置。在 Eureka 中,我们也存储配置信息。那么有什么区别以及何时使用什么?
我创建了一个 Eureka 服务器 Spring Boot 应用程序。它已正确加载。之后我试图创建一个尤里卡客户端。但它没有在尤里卡服务器 UI 中列出。我正在添加我的客户端应用程序详细信息。
我的主控制器类文件如下,
@SpringBootApplication
@EnableDiscoveryClient
public class ZEurekaClientServiceApplication {
public static void main(String[] args) {
SpringApplication.run(ZEurekaClientServiceApplication.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
我的 pom.xml 包含 ,
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud)
和
<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>
</dependencies>
</dependencyManagement>
Run Code Online (Sandbox Code Playgroud)
我的 application.properties 文件包含,
eureka.client.serviceUrl.defaultZone=http://localhost:8071/eureka
eureka.client.register-with-eureka=true
eureka.client.fetch-registry=true
Run Code Online (Sandbox Code Playgroud)
当 It 客户端运行时,尤里卡服务器 UI 不显示它的名称。仅将 UNKNOWN 显示为应用程序。我在下面添加它的屏幕截图。
我需要在尤里卡服务器 UI 中显示应用程序名称而不是“UNKNOWN”吗?是否有任何额外的设置来添加应用程序名称?
所以我花了一天的时间试图解决这个问题,这非常困难。所以问题是,当您有一个使用 Feign 的简单客户端时,如下所示:
@FeignClient(name = "identity-service")
public interface IdentityClient {
@GetMapping(value = "/")
String request();
}
Run Code Online (Sandbox Code Playgroud)
当然,您的应用程序注释@EnableFeignClients如下:
@EnableEurekaClient
@SpringBootApplication
@EnableFeignClients
public class LicenseServiceApplication {
public static void main(String[] args) {
SpringApplication.run(LicenseServiceApplication.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
如果我对该假客户端进行如下测试:
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment= SpringBootTest.WebEnvironment.NONE)
public class LicenseServiceTest {
@ClassRule
public static WireMockClassRule wiremock = new WireMockClassRule(
WireMockSpring.options().dynamicPort());
// A service that calls out over HTTP
@Autowired
private IdentityClient identityClient;
// Using the WireMock APIs in the normal way:
@Test
public void contextLoads() throws Exception …Run Code Online (Sandbox Code Playgroud) spring wiremock spring-cloud netflix-eureka spring-cloud-feign
我正在建立基于Netflix Eureka的微服务,并在Spring-cloud之上进行实验,经过数周的研究和开发,问题就出现了!
为什么我需要Eureka和spring-cloud?
为什么不开发你的独立容器并将它们作为pods 部署在Kubernetes上并从那里维护一切?
您也可以支持Kubernetes的负载平衡,服务注册,监控,容器化等.
以下是我能想到的一些观点:
根据 Eureka wiki ( https://github.com/Netflix/eureka/wiki ),Eureka 2.0 已停产。
eureka 2.0 的开源工作已经停止。作为 2.x 分支上现有工作存储库的一部分发布的代码库和工件被视为使用风险自负。
问题
与 Eureka 1.0(Spring Cloud 2.0 仍在使用的)相比,Eureka 2.0 有哪些新功能?
Netflix 内部是否仍然使用任何服务发现平台?如果是,那是什么?
编辑
找到了第一个问题的一些答案。阅读这些:
netflix service-discovery spring-cloud netflix-eureka spring-cloud-netflix
netflix-eureka ×10
spring ×4
spring-boot ×3
spring-cloud ×3
java ×2
netflix ×2
amazon-ecs ×1
kubernetes ×1
wiremock ×1