server.port in command line not working with spring cloud config server and eureka server - spring-boot

I am studying spring could. What I have now is a spring cloud config server and eureka server.
Code for Config Server
#SpringBootApplication
#EnableConfigServer
public class ConfigServerApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigServerApplication.class, args);
}
}
application.properties
spring.application.name=config-server
spring.cloud.config.server.git.uri=https://github.com/vincentwah/spring-cloud-config-repository/
server.port=7001
Code for Eureka server
#SpringBootApplication
#EnableEurekaServer
public class EurekaServerApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaServerApplication.class, args);
}
}
bootstrap.properties
spring.application.name=eureka-server
spring.cloud.config.uri=http://localhost:7001/
The config for eureka-server is https://github.com/vincentwah/spring-cloud-config-repository/blob/master/eureka-server.properties
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
eureka.client.serviceUrl.defaultZone=http://localhost:${server.port}/eureka/
server.port=1111
When I start eureka server, I'd like to change the port, so I run below command
java -jar target/eureka-server-0.0.1-SNAPSHOT.jar --server.port=1234
However, the server is still started with port 1111
2017-01-03 14:04:11.324 INFO 6352 --- [ Thread-10] c.n.e.r.PeerAwareInstanceRegistryImpl : Changing status to UP
2017-01-03 14:04:11.339 INFO 6352 --- [ Thread-10] e.s.EurekaServerInitializerConfiguration : Started Eureka Server
2017-01-03 14:04:11.492 INFO 6352 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 1111 (http)
2017-01-03 14:04:11.493 INFO 6352 --- [ main] c.n.e.EurekaDiscoveryClientConfiguration : Updating port to 1111
2017-01-03 14:04:11.500 INFO 6352 --- [ main] com.example.EurekaServerApplication : Started EurekaServerApplication in 27.532 seconds (JVM running for 29.515)
I think I am not doing wrong with --server.port in command line. Does anybody encounter same issue?

Spring Cloud Config, by default, overrides local configuration. It is meant to be the source of truth. You could use profiles so the port is not defined with a particular profile. You could also disable the config client if it's not really needed (in tests for example).
There are also options to allow overrides.
The property sources that are added to you application by the
bootstrap context are often "remote" (e.g. from a Config Server), and
by default they cannot be overridden locally, except on the command
line. If you want to allow your applications to override the remote
properties with their own System properties or config files, the
remote property source has to grant it permission by setting
spring.cloud.config.allowOverride=true (it doesn’t work to set this
locally). Once that flag is set there are some finer grained settings
to control the location of the remote properties in relation to System
properties and the application’s local configuration:
spring.cloud.config.overrideNone=true to override with any local
property source, and
spring.cloud.config.overrideSystemProperties=false if only System
properties and env vars should override the remote settings, but not
the local config files.

eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
eureka.client.serviceUrl.defaultZone=http://localhost:${server.port}/eureka/
server.port=1111
spring.cloud.config.allowOverride=true
spring.cloud.config.overrideNone=true
spring.cloud.config.overrideSystemProperties=false
This is working.

Related

Eureka client registration with external git repo configuration files

I have an external configuration repository on git containing all my propertie files.
My eureka client is microservice-order with this application file :
spring.application.name=microservice-order
spring.config.import=configserver:http://localhost:9101
This application file point to "microservice-order" propertie files :
server.port=9001
spring.data.mongodb.uri=mongodb+srv://admin:************#cluster0.yqhwqrj.mongodb.net/Facebouffe?retryWrites=true&w=majority
#configurations
configs.setOrderLimit= 5
#eureka
spring.application.name = microservice-order
eureka.client.serviceUrl.defaultZone: http://localhost:9102/eureka/
My eureka server has this propertie file :
spring.application.name=eureka-server spring.config.import=configserver:http://localhost:9101
pointing to exteral repo file "eureka-server.properties":
`
server.port= 9102
eureka.client.serviceUrl.defaultZone = http://localhost:9102/eureka/
eureka.client.registerWithEureka=false
eureka.client.fetchRegistry=false
spring.cloud.config.import-check.enabled=false`
I wrote "#EnableEurekaServer" (eureka-service-discovery) for server class and "#EnableEurekaClient" for client class (microservice-order)
When i start configserver, its running on 9101 port
When i start eureka-service-discovery, its running on 9102 port
When i start microservice-order, its running on 9001 port
So, each class load its own propertie files, but when i connect to http://localhost:9102/ , there is no service registered.
Do you have any idea ?
thank you !
I'm trying to register an eureka client to eureka server with external propertie files repository on github.

Eureka Server - Client setup - UnknownHostException - Could not get Swagegr definition from API

I am having simple setup - eureka server and 'event-catalog' as eureka client. Both hosted in AWS.
eureka server loads up the service on home page:
EVENT-CATALOG n/a (1) (1) UP (1) - cff2a33fcf77:event-catalog:8550
However while accessing swagger-ui.html getting below errors on cloudwatch console :
2021-09-07 21:08:28.318 ERROR 42 --- [ scheduling-1] c.e.s.e.c.s.ServiceDescriptionUpdater : Error while getting service definition for service : event-catalog Error : I/O error on GET request for "http://cff2a33fcf77:8550/v2/api-docs": cff2a33fcf77; nested exception is java.net.UnknownHostException: cff2a33fcf77
ERROR 42 --- [ scheduling-1] c.e.s.e.c.s.ServiceDescriptionUpdater : Skipping service id : event-catalog Error : Could not get Swagegr definition from API
My design and code is aligned with https://dzone.com/articles/centralized-documentation-in-microservice-spring-b
My eureka server configuration as below:
#SpringBootApplication
#EnableEurekaServer
#EnableSwagger2
#EnableScheduling
public class EurekaserverApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaserverApplication.class, args);
}
}
client (event-catalog) configuration as below
Annotated application class with '#EnableEurekaClient'
and application.yml config file has below configuration:
---
spring:
config.activate.on-profile: dev
eureka:
instance:
appname: event-catalog
client:
enabled: true
register-with-eureka: true
#fetch-registry: false
service-url:
defaultZone: https://dev.eureka-service.rd.xxx.io/eureka/
Above whole setup works well when running locally. However after deploying to AWS it is giving above mentioned errors 'unknown host'. Wondering where it is getting 'cff2a33fcf77' and why not simply dev.event-catalog.rd.xxx.io/?
Please suggest what I am missing here. I am implementing discovery server first time and have spent so much time already to get it working. Please adivce.
Figured out. I observed that spring cloud service instance was not resolving host correctly. It was taking AWS ecs task container id for the host.
Manipulated code to resolve host.

Spring boot port opens randomly when running in Citrix machine

I have a Citrix machine and I have to run a web service there (developed using Spring Boot). It is a Windows 10 host. There is a strange behaviour - the port is randomly chosen instead of the configured port 8090.
I checked my application.properties and it is clearly showing
server.port=8090
There is no issue with the code, if I run it from any other machine, it will start in port 8090 as expected.
It even prints out in the Citrix machine that the Tomcat server is initialised with port 8090. But finally it starts at a random port (22345) as seen in the logs below. If I stop and start again, it will start in another port (maybe 23466).
2021-06-28 13:45:52.490 INFO 31792 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8090 (http)
......
......
2021-06-28 13:45:53.348 INFO 31792 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 22345 (http) with context path ''
2021-06-28 13:45:53.355 INFO 31792 --- [ main] com.sreejesh.MainApplicationClass : Started MainApplicationClass in 3.701 seconds (JVM running for 4.798)
I have even tried to override it in command line:
java -jar MyApp.jar --server.port=8090
Still the result is same (as if someone is strangely overwriting server.port=0 to start in a random port).
I want to reiterate that everything works fine in my local machine as expected. Only in Citrix machine this strange behaviour exists.
Any clue as to why this happens? Thank you for your time.

Is Eureka running on 8761 or 8080?

I've created a new spring boot project with "spring-cloud-starter-netflix-eureka-server" dependency. Also have added "#EnableEurekaServer" annotation and launched the spring boot app.
I see the below log messages
o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
c.n.eureka.cluster.PeerEurekaNodes : Adding new peer nodes [http://localhost:8761/eureka/]
From above, as I understand. Tomcat is running on port 8080 and eureka server is running on port 8761.
If so,
How come the Eureka Dash board is accessible at http://localhost:8080/ ? When the eureka server is running on port 8761 ?
On one of the client, I configured the following in the .properties file
eureka.client.service-url.defaultZone=http://localhost:8761/eureka/
Above, I specified the Eureka server location. But, why is the client unable to register?
Thanks!
By default it works on 8761, so configure server.port=8761

Eureka Client: Eureka Registry server address alternative to 'localhost'

Eureka-server(MediaStoreEurekaServer): bootstrap.properties
spring.application.name=MediaStoreEurekaServer
server.port=9091
eureka.client.serviceUrl.defaultZone=http://localhost:9091/eureka}
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
Eureka-client(Config-Server): bootstrap.properties
spring.application.name=Config-Server
server.port=9093
user.home=${HOME}
spring.cloud.config.server.native.search-locations=file://${user.home}/IdeaProjects/MediaStore/centralProperties
spring.profiles.active=native
eureka.client.serviceUrl.defaultZone=http://localhost:9091/eureka
With above 2 properties (services running on same machine), Config-Server is able to register with MediaStoreEurekaServer eureka registry server when using http://localhost:9091/eureka.
I don't want to use localhost. When I use http://MediaStoreEurekaServer:9091/eureka , Config-Server is not able to register.
Can we use something other than localhost for eureka client to find the eureka server like service or instance name? when services are running on same host
Edit 1:
This is what eureka client spring logs give when in eureka client properties file i set
eureka.client.serviceUrl.defaultZone=http://MediaStoreEurekaServer:9091/eureka
Error:
2020-05-22 20:01:02.137 ERROR 22846 --- [nfoReplicator-0] c.n.d.s.t.d.RedirectingEurekaHttpClient : Request execution error. endpoint=DefaultEndpoint{ serviceUrl='http://MediaStoreEurekaServer:9091/eureka/}
com.sun.jersey.api.client.ClientHandlerException: java.net.UnknownHostException: MediaStoreEurekaServer```

Resources