I'm trying to register my cloud contract stubs with a running Eureka discovery service for smoke-testing. The stubrunner itself is successfully registered in the service discovery, but the endpoints provided by the stubs are not reachable as expected.
The stubs should replace the real masterdata microservice (rest apis).
Stubrunner main class:
@SpringBootApplication
@EnableStubRunnerServer
@EnableEurekaClient
@AutoConfigureStubRunner
class EurekaStubRunnerApplication
fun main(args: Array<String>) {
runApplication<EurekaStubRunnerApplication>(*args)
}
Stubrunner bootstrap.yml
spring:
application:
name: masterdata
jhipster:
registry:
password: admin
Stubrunner application.yml
eureka:
client:
service-url:
defaultZone: http://admin:${jhipster.registry.password}@localhost:8761/eureka/
enabled: true
healthcheck:
enabled: false
fetch-registry: true
register-with-eureka: true
instance-info-replication-interval-seconds: 10
registry-fetch-interval-seconds: 10
instance:
appname: masterdata
instance-id: masterdata:${spring.application.instance-id:${random.value}}
lease-renewal-interval-in-seconds: 5
lease-expiration-duration-in-seconds: 10
status-page-url-path: management/info
health-check-url-path: management/health
ribbon:
eureka:
enabled: true
server:
port: 8888
stubrunner:
cloud:
eureka:
enabled: true
stubbed:
discovery:
enabled: true
Command to start stub runner:
java -jar eureka-stub-runner-0.0.1-SNAPSHOT.jar --stubrunner.ids=com.xetics.mes:masterdata-stubs:+:8081 --stubrunner.stubsMode=LOCAL
When I start the real masterdata service, I can call the api endpoint via the running gateway:
curl -X GET --header 'Authorization: Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZG1pbiIsImF1dGgiOiJST0xFX0FETUlOLFJPTEVfVVNFUiIsImV4cCI6MTU0NjYxMDc2OH0.EF3PHho-B-ayOmmeFrcA90U38cd3AZsU7pA7-9xN0SpuVBvev2sHvejv-FI_FlrwP7qWcCpibW-yWwFDBSUv9w' 'http://localhost:8080/masterdata/api/stations'
[]
The same call with stubs running in the stub runner:
curl -X GET --header 'Authorization: Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZG1pbiIsImF1dGgiOiJST0xFX0FETUlOLFJPTEVfVVNFUiIsImV4cCI6MTU0NjYxMDc2OH0.EF3PHho-B-ayOmmeFrcA90U38cd3AZsU7pA7-9xN0SpuVBvev2sHvejv-FI_FlrwP7qWcCpibW-yWwFDBSUv9w' 'http://localhost:8080/masterdata/api/stations'
{"timestamp":"2019-01-03T16:59:36.426+0000","status":404,"error":"Not Found","message":"No message available","path":"/api/stations"}
Although, I can call the stubs directly:
curl -X GET --header 'Authorization: Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZG1pbiIsImF1dGgiOiJST0xFX0FETUlOLFJPTEVfVVNFUiIsImV4cCI6MTU0NjYxMDc2OH0.EF3PHho-B-ayOmmeFrcA90U38cd3AZsU7pA7-9xN0SpuVBvev2sHvejv-FI_FlrwP7qWcCpibW-yWwFDBSUv9w' 'http://localhost:8081/api/stations'
[{"archiveTime":null,"description":"A fantastic base for building a time machine","id":1985,"maxCapacity":2,"name":"DeLorean DMC 12","icon":"delorean-icon"},{"archiveTime":null,"description":"A handy tool for manipulating the space time continuum","id":2015,"maxCapacity":1,"name":"Flux capacitor"}]
What am I doing wrong? As far as I understood that issue https://github.com/spring-cloud/spring-cloud-contract/pull/64 , it should be possible to register the stubs in the Eureka server, nor?
I've also read the following documentations without any success:
The problem were caused by the following misconfiguration of the application.
...
stubrunner:
cloud:
eureka:
enabled: true
stubbed:
discovery:
# must be false instead of
enabled: true
In addition, I needed to add a service mapping as my stubs artifact id is masterdata-stubs whereas the service id to call is masterdata.
The working application.yml looks like this now:
eureka:
client:
service-url:
defaultZone: http://admin:${jhipster.registry.password}@localhost:8761/eureka/
enabled: true
healthcheck:
enabled: false
fetch-registry: true
register-with-eureka: true
instance-info-replication-interval-seconds: 10
registry-fetch-interval-seconds: 10
instance:
appname: stubrunner
instance-id: stubrunner:${spring.application.instance-id:${random.value}}
lease-renewal-interval-in-seconds: 5
lease-expiration-duration-in-seconds: 10
status-page-url-path: management/info
health-check-url-path: management/health
ribbon:
eureka:
enabled: true
server:
port: 8888
stubrunner:
cloud:
eureka:
enabled: true
stubbed:
discovery:
enabled: false
idsToServiceIds:
masterdata-stubs: masterdata