我正在尝试将微服务与Eureka连接。
我已经在主类中添加了注释@EnableDiscoveryClient
:
@EnableDiscoveryClient
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
我正在build.gradle
中使用下一个依赖项:
compile group: 'org.springframework.cloud', name: 'spring-cloud-netflix-eureka-client', version: '2.0.1.RELEASE'
最后,我已将配置添加到application.yml
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
spring:
application.name: receipt-processing-microservice
而且,正如您可以建议的那样,它不起作用。在日志中,我看不到任何带有标签DiscoveryChannel
或Eureka
答案 0 :(得分:1)
也许您缺少配置的一部分?
我满足以下条件,并且一切运行正常:
#Eureka configuration
eureka.client.enabled=true
eureka.client.serviceUrl.defaultZone=${EUREKA_SERVICE_URL:http://admin:admin@localhost:7995}/eureka/
eureka.client.healthcheck.enabled=true
eureka.client.registerWithEureka=true
eureka.client.fetchRegistry=true
eureka.instance.leaseRenewalIntervalInSeconds=15
eureka.instance.leaseExpirationDurationInSeconds=30
您可以尝试使用更多参数,看看会发生什么。
此外,如果只是控制台日志问题,请检查eureka Web-ui中的服务列表:请参阅localhost:8761 /#。
答案 1 :(得分:0)
尝试启用调试日志。您将获得大量信息(可以将其重定向到文件),并尝试查看其下发生了什么—特别是在容器启动后以及发现客户端初始化时。在我的情况下,发现服务器正在8061端口上运行,我的服务注册日志如下所示(请参阅指示服务向eureka服务器发送请求注册的日志)
DEBUG [employee-service,,,] Returning cached instance of singleton bean 'refreshEventListener'
DEBUG [employee-service,,,] Closing connections idle longer than 30000 SECONDS
DEBUG [employee-service,,,] Closing connections idle longer than 30000 SECONDS
INFO [employee-service,,,] Disable delta property : false
INFO [employee-service,,,] Single vip registry refresh property : null
INFO [employee-service,,,] Force full registry fetch : false
INFO [employee-service,,,] Application is null : false
INFO [employee-service,,,] Registered Applications size is zero : true
INFO [employee-service,,,] Application version is -1: false
INFO [employee-service,,,] Getting all instance registry info from the eureka server
Get connection: {}->http://localhost:8061, timeout = 5000
[{}->http://localhost:8061] total kept alive: 1, total issued: 0, total allocated: 1 out of 200
Getting free connection [{}->http://localhost:8061][null]
Stale connection check
CookieSpec selected: default
Auth cache not set in the context
Target auth state: UNCHALLENGED
Proxy auth state: UNCHALLENGED
Attempt 1 to execute request
Sending request: GET /eureka/apps/ HTTP/1.1
>> "GET /eureka/apps/ HTTP/1.1[\r][\n]"
>> "Accept: application/json[\r][\n]"
>> "DiscoveryIdentity-Name: DefaultClient[\r][\n]"
>> "DiscoveryIdentity-Version: 1.4[\r][\n]"
>> "DiscoveryIdentity-Id: 192.168.28.145[\r][\n]"
>> "Accept-Encoding: gzip[\r][\n]"
>> "Host: localhost:8061[\r][\n]"
>> "Connection: Keep-Alive[\r][\n]"
>> "User-Agent: Java-EurekaClient/v1.9.2[\r][\n]"
>> "[\r][\n]"
>> GET /eureka/apps/ HTTP/1.1
>> Accept: application/json
>> DiscoveryIdentity-Name: DefaultClient
>> DiscoveryIdentity-Version: 1.4
>> DiscoveryIdentity-Id: 192.168.28.145
>> Accept-Encoding: gzip
>> Host: localhost:8061
>> Connection: Keep-Alive
>> User-Agent: Java-EurekaClient/v1.9.2
Get connection: {}->http://localhost:8061, timeout = 5000
[{}->http://localhost:8061] total kept alive: 0, total issued: 1, total allocated: 1 out of 200
No free connections [{}->http://localhost:8061][null]
Available capacity: 49 out of 50 [{}->http://localhost:8061][null]
Creating new connection [{}->http://localhost:8061]
<< "HTTP/1.1 200 [\r][\n]"
<< "Content-Encoding: gzip[\r][\n]"
<< "Content-Type: application/json[\r][\n]"
<< "Content-Length: 549[\r][\n]"
<< "Date: Tue, 28 Aug 2018 06:48:14 GMT[\r][\n]"
<< "[\r][\n]"
Receiving response: HTTP/1.1 200
<< HTTP/1.1 200
<< Content-Encoding: gzip
<< Content-Type: application/json
<< Content-Length: 549
<< Date: Tue, 28 Aug 2018 06:48:14 GMT
Connection can be kept alive indefinitely
<< "[0x1f][0x8b][0x8][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x9d]S[0xd1][0x8e][0xda]0[0x10][0xfc][0x17][0xeb][0x1e]![0x10][0x8]4[0x97][0xa7];[0x91][0xa8][0x8a][0xda][0x3]D[0xca]UUU![0xd7]Y[0x88]U[0xc7][0x8e]l[0x87]k[0x84][0xf8][0xf7][0xae][0x93][0x86][0x96]SQ[0xd5]*[0xf][0x89]wg[0xd7];3[0x9b][0x13][0xa1]U%8[0xa3][0x96]+iHt"G[0xd0][0xc6]}[0xef]v9[0x8]KID|2p([0x8c][0x14][0xd4][0x14]L[0xe5][0x80][0xc1][0xed]z[0xe7][0xef][0xba]D_N[0xa2][0xcf]'"i[0xe9][0xd2][0xc9][0xd3][0xfa][0xfd][0xea]S[0x92][0xc][0xb3]d[0xf3][0x9c].[0x12]Dri,[0x95][0xc]ZXHs[0x4][0xa7][0x9b]4[0x1b].[0xb2][0xb7]C6[0xe3][0x95][0xa6]P%x[0x12]l[0x4]e%T[0x3]04[0xa0][0x8f][0x9c]A[0x14][0x8e][0xef][0xc7][0xd8][0xaa]P[0xc6].[0xbb][0x8b]n[0xd5]v[0xa3][0xdd][0x98][0xa4]z[0xcc]s[0xed][0x98][0xdd]O<[0x1e]z[0x93][0xd0][0xf3][0x83][0x19]fp([[0x9b][0x96][0x1e][0x9e][0x14]j[0xa1]y[0x9e][0x83][0xcc].[0xf1][0xe5][0xbb][0xe5][0xea][0xe3][0x12][0x93][0x95][0xd2][0xd6][0xe9]uG[0xda][0xa9][0x6][0xe4][0x1]$[0xfd]*[0xc0][0x11][0xb2][0xba][0x6]r[0xc6]v[0xc0]j[\r][0xeb]_[0xc8] [0x98]^[0x1][0xf7]T[0x98][0x16][0xc9]T-[0xad]n[0x9c][0x1c][0xfe][0x80][0xe4][0xd4][0xd2][0x5]H[0xb]:[0x95]{[0xe5]j[0x1f][0x98][0xa0][0xc6][\r][0xc0]T[0xe9][0xe8][0xed][0x5][0xff][0xee]!A[0x8e]y/[0xed][0xc5][0xc4][0xc3]][0xc]{Z[0xb][0x1b]_[0xb7][0x18][0xf4][0xc6]<5[0xab][0x17][0xe9]n[0x14]@[\r][0xf4][0xed]5Hx[0xa1]"u[0xf8][0xa3]{g[0xc0][0xf0][0xb6])[0xd2][0xca]k[0xdd][0xba][0xdb][0xc7][0x1c]U[\r][0x7]nl[0x17][0xff][0xc0]K[0xc0][0xeb]K[0xd4][0xda][0x9f]Mg[0xc1]4[0xc][0xe7][0xc1][0xc4][0xf][0xf1][0x6]j[0xec][0xa6]k|[0x1b][0x4][0xe8][0xeb][0xab]6c'\[0xeb][0xf7][0xb6][0xba]U[0x88][0x4]J[0xb0][0xd4][0x9][0xe5][0xe6]/[0xa9][0xa4][0x7]([0x91][0xaf][0xd7][0xf9]B[0xda]M9[0xbb]U)a[0x8d][0xb9][0xad][0x16][0x18]-[0xac][0xad][0xa2][0xd1][0xe8][0xe6][0xc2][0xb9][0xaa][0xd1]e[0xf][0xfe][0xb1][0x8e]2[S[0xab][0xf4][0x88]w[0x8a][0x17]@[0x85]-[0x16][0x5][0xb0]o[0xff][0xd3][0xa5]+[0xc7]>[0xc7]n_[0xa1][0xf5][0xff][0xf5]/A[0xfa]-{[0xfe][0xb][0x8a][0x9b][0x85]R:[0xe7][0x12]][0x93][0x87][0x98][0x1b][0xe6][0xd6][0xbb][0xc9][0x10][0x0][0xfa][0xb2][0x8a][0x9d]k[0xdb][\n]"
<< "[0x85][0x85][0xfc]7[0xf1][0xc9][0x95][0xfa]?a1[0xd7][0xb6][0xf9]3h<[\r][0xdc][0x1f][0xd8]Y[0xdb]Tn[0xf3][0x1e][0xe3]8[0x89][0xc9][0xf9][0xb]>[0xe7][0x1f][0xc1][0x8d][0x8f][0xd8]w[0x4][0x0][0x0]"
Connecting to localhost:8061
CookieSpec selected: default
Auth cache not set in the context
Target auth state: UNCHALLENGED
Proxy auth state: UNCHALLENGED
Attempt 1 to execute request
Sending request: PUT /eureka/apps/EMPLOYEE-SERVICE/aaaa-aaaa-1567.mshome.net:employee-service:8090?status=UP&lastDirtyTimestamp=1535438864034 HTTP/1.1
>> "PUT /eureka/apps/EMPLOYEE-SERVICE/aaaa-aaa-1567.mshome.net:employee-service:8090?status=UP&lastDirtyTimestamp=1535438864034 HTTP/1.1[\r][\n]"
>> "DiscoveryIdentity-Name: DefaultClient[\r][\n]"
>> "DiscoveryIdentity-Version: 1.4[\r][\n]"
>> "DiscoveryIdentity-Id: 192.168.28.145[\r][\n]"
>> "Accept-Encoding: gzip[\r][\n]"
>> "Content-Length: 0[\r][\n]"
>> "Host: localhost:8061[\r][\n]"
>> "Connection: Keep-Alive[\r][\n]"
>> "User-Agent: Java-EurekaClient/v1.9.2[\r][\n]"
>> "[\r][\n]"
>> PUT /eureka/apps/EMPLOYEE-SERVICE/aaaa-aaa-1567.mshome.net:employee-service:8090?status=UP&lastDirtyTimestamp=1535438864034 HTTP/1.1
>> DiscoveryIdentity-Name: DefaultClient
>> DiscoveryIdentity-Version: 1.4
>> DiscoveryIdentity-Id: 192.168.28.145
>> Accept-Encoding: gzip
>> Content-Length: 0
>> Host: localhost:8061
>> Connection: Keep-Alive
>> User-Agent: Java-EurekaClient/v1.9.2
<< "HTTP/1.1 200 [\r][\n]"
<< "Content-Type: application/xml[\r][\n]"
<< "Content-Length: 0[\r][\n]"
<< "Date: Tue, 28 Aug 2018 06:48:14 GMT[\r][\n]"
<< "[\r][\n]"
Receiving response: HTTP/1.1 200
<< HTTP/1.1 200
<< Content-Type: application/xml
<< Content-Length: 0
<< Date: Tue, 28 Aug 2018 06:48:14 GMT
Connection can be kept alive indefinitely
Released connection is reusable.
Releasing connection [{}->http://localhost:8061][null]
Pooling connection [{}->http://localhost:8061][null]; keep alive indefinitely
Notifying no-one, there are no waiting threads
Jersey HTTP PUT http://localhost:8061/eureka//apps/EMPLOYEE-SERVICE/aaa-aaa-1567.mshome.net:employee-service:8090; statusCode=200
DiscoveryClient_EMPLOYEE-SERVICE/aaaa-aaa-1567.mshome.net:employee-service:8090 - Heartbeat status: 200
答案 2 :(得分:-1)
在application.yml文件中将配置服务器端口更改为8888。
server:
port: 8888