我在后端使用微服务体系结构,其中我使用Typescript和其他使用Java创建的服务。另外,我还有一个Spring Gateway和Eureka服务器(都使用Spring)。
然后,Gateway工作正常,尤里卡(Eureka)工作正常,其他用Java编写的微服务也可以正常工作。问题是当我尝试到达网关的打字稿微服务时。
我有一个简单的Eureka服务器,使用注释 @enableeurekaserver
在春季。
Eureka
spring:
application:
name: gateway-service
cloud:
gateway:
discovery:
locator:
enabled: true
lowerCaseServiceId: true
routes:
- id: ms1
uri: lb://ms1
predicates:
- Path=/ms1/**
- id: ms2
uri: lb://ms2
predicates:
- Path=/ms2/**
还连接到尤里卡( TS)或Microservice2(用Java编写)。
当我运行所有服务时,尤里卡(Eureka)会显示为:
您可以看到 Gateway
, MS1
和 MS2
。但是,为什么Java Services具有 192.168.8.121
和TS服务不呢?
顺便说一句,链接工作正常,每个服务都路由到存在的端口,网关和Java微服务被路由到< gateway_url>:< service_port_port>/cartuator/cotuator/info
andypect microservice and Typescript Microservice IS IS IS路由到 localhost:< service_port>
。
MicroService2非常简单:
@RestController
public class Controller {
@GetMapping("/hello-world")
public ResponseEntity<String> getHi() {
return ResponseEntity.ok("hi");
}
}
并且也进入application.yml:
spring:
application:
name: ms2
但是TS微服务使用使用这种配置:
this._client = new Eureka({
instance: {
app: 'ms1',
instanceId: 'ms1',
hostName: 'localhost',
ipAddr: '127.0.0.1',
statusPageUrl: `http://localhost:8081`,
healthCheckUrl: `http://localhost:8081/health`,
port: {
'$': 8081,
'@enabled': true,
},
vipAddress: 'myvip',
dataCenterInfo: {
'@class': 'com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo',
name: 'MyOwn',
},
},
eureka: {
host: 'localhost',
port: 8761,
servicePath: '/eureka/apps/'
},
})
因此,我的想法是:
- 当我击中
&lt; gateway_url&gt;:&lt; gateway_port&gt;/ms1/hello-world
时,会从Typescript Microservice中显示数据。
- 当我点击
&lt; gateway_url&gt;:&lt; gateway_port&gt;/ms2/hello-world
时,它将出现来自Java Microservice的数据。
第二个工作正常,但是路线 http:/ http://192.168.8.8.8.8.8.121:8762/ms1/ms1/mms1/mms1/hello -world 返回503错误:
Whitelabel Error Page
This application has no configured error view, so you are seeing this as a fallback.
Mon May 16 19:02:56 CEST 2022
[fa1d8857-5] There was an unexpected error (type=Service Unavailable, status=503).
控制台说无可用的服务器:MS1
。
因此,我不知道我是否在误解某些内容, eureka-js-client
是 ms1
。 LB是为此服务...但行不通。
正如我所说,使用Java服务效果很好,所以也许问题是服务连接到Eureka,使用或类似的名称的方式?但是在仪表板中,它显示为 ms1
和 ms2
,所以我很困惑...
谢谢
I use a microservices architecture in the backend where I have services created using TypeScript and others using Java. Also I have a Spring Gateway and an Eureka server (both using Spring).
Then, Gateway works fine, Eureka works fine and also others microservices written in Java work fine too. The problem is when I try to reach the TypeScript microservice accross the Gateway.
I have a simple Eureka Server using the annotation @EnableEurekaServer
in Spring.
Also a Gateway connected to Eureka as client where the yaml has this part:
spring:
application:
name: gateway-service
cloud:
gateway:
discovery:
locator:
enabled: true
lowerCaseServiceId: true
routes:
- id: ms1
uri: lb://ms1
predicates:
- Path=/ms1/**
- id: ms2
uri: lb://ms2
predicates:
- Path=/ms2/**
With this Gateway I want to have two routes /ms1
and /ms2
to access the microservice1 (written in TS) or microservice2 (written in Java).
When I run all services, Eureka is shown like this:

You can see the gateway
, ms1
and ms2
. But, why Java services has 192.168.8.121
and TS service not?
By the way, the links work ok, every service is routed to the port where exists, Gateway and Java microservice are routed to <gateway_url>:<service_port>/actuator/info
and TypeScript microservice is routed to localhost:<service_port>
.
Microservice2 is so simple:
@RestController
public class Controller {
@GetMapping("/hello-world")
public ResponseEntity<String> getHi() {
return ResponseEntity.ok("hi");
}
}
And also into application.yml:
spring:
application:
name: ms2
But TS microservice uses eureka-js-client with this configuration:
this._client = new Eureka({
instance: {
app: 'ms1',
instanceId: 'ms1',
hostName: 'localhost',
ipAddr: '127.0.0.1',
statusPageUrl: `http://localhost:8081`,
healthCheckUrl: `http://localhost:8081/health`,
port: {
'
So, my idea is:
- When I hit
<gateway_url>:<gateway_port>/ms1/hello-world
it appears the data from TypeScript microservice.
- When I hit
<gateway_url>:<gateway_port>/ms2/hello-world
it appears the data from Java microservice.
The second one works fine, but the route http://192.168.8.121:8762/ms1/hello-world returns a 503 error:
Whitelabel Error Page
This application has no configured error view, so you are seeing this as a fallback.
Mon May 16 19:02:56 CEST 2022
[fa1d8857-5] There was an unexpected error (type=Service Unavailable, status=503).
And console says No servers available for service: ms1
.
So I don't know if I'm misunderstanding something, the name from eureka-js-client
is ms1
. The LB is to that service... but it not works.
As I've said, with a Java service works fine, so maybe the problem is the way the service connect to Eureka, the name who uses or something like that? But in the dashboard it appears as MS1
and MS2
so I'm confused...
Thanks in advance
: 8081,
'@enabled': true,
},
vipAddress: 'myvip',
dataCenterInfo: {
'@class': 'com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo',
name: 'MyOwn',
},
},
eureka: {
host: 'localhost',
port: 8761,
servicePath: '/eureka/apps/'
},
})
So, my idea is:
- When I hit
<gateway_url>:<gateway_port>/ms1/hello-world
it appears the data from TypeScript microservice.
- When I hit
<gateway_url>:<gateway_port>/ms2/hello-world
it appears the data from Java microservice.
The second one works fine, but the route http://192.168.8.121:8762/ms1/hello-world returns a 503 error:
And console says No servers available for service: ms1
.
So I don't know if I'm misunderstanding something, the name from eureka-js-client
is ms1
. The LB is to that service... but it not works.
As I've said, with a Java service works fine, so maybe the problem is the way the service connect to Eureka, the name who uses or something like that? But in the dashboard it appears as MS1
and MS2
so I'm confused...
Thanks in advance
发布评论
评论(1)
解决了我的问题,这很奇怪。
我的
vipaddress
不正确。似乎Spring Cloud Gateway检查instance.vipaddress
而不是instance.app
。因此,用
它可以完美地工作。
ms1
替换Solved my issue, it was a weird thing.
My
vipAddress
was not correct. It seems Spring Cloud Gateway checks for theinstance.vipAddress
instead ofinstance.app
.So replacing
myvip
withms1
it works perfectly.