How to run spring boot application multiple instance when get resource from config server? - spring-boot

I have Eureka server, Eureka zuul and config server.
So I write a simple microservice. Then, running on 8686 port.
So I want to run that microservice on another port.
I trying that command. But don't work.
java -Dserver.port=8687 -jar -Dlogging.file="bla.log" testMicro.jar --debug > "bla.log"&
I am confusing. Help me!

You have two ways to running your instances on different ports.
user assignment of random port from a specified range:
server:
port: ${random.int(8080,8090)}
Set in property file from config server for testMicro microservice the following configurations:
spring:
cloud:
config:
override-system-properties: false
allow-override: true
override-none: true
and then run again your jar with -Dserver.port=8687 property

Related

Spring cloud config server share binary file

I am using spring configuration server.
While setting up Kafka, I came across the fact that I need to somehow specify binary certificates
spring:
kafka:
ssl:
truststore:
location: /filepath/trust_cert.jks
password: 1234
keystore:
location: /filepath/keystore_cert.jks
password: 1234
Can I somehow put them on the configuration server, and in this case, what should I write to the config, where the path to the file is expected?
I really don’t want to manually upload them to each server, I would like the configuration server to give them
Of course, these urls must be protected, just like configuration server urls

spring-boot auto change port if port is already used

I am using Windows command to run my spring-boot application with emblemed tomcat. Beside, I need to run many console application using CommandlineRunner. Off cource I am facing port in use issue.
***************************
APPLICATION FAILED TO START
***************************
Description:
Web server failed to start. Port 8080 was already in use.
Action:
Identify and stop the process that's listening on port 8080 or configure this application to listen on another port.
I can set port in every console application but I need to run at least 10 console application at the same time.
Do I have any config or solution for application auto-change port?
You can auto generate port number to get rid from Port was already in use. just put server.port= 0 in properties or yml. It is auto generate server port in console.
application.properties
server.port= 0
application.yml
server:
port : 0
console

Spring cloud client trying to run on server port 8888

The config server is up and the client is able to fetch the properties from config server.
HTTP GET http://localhost:8888/account-service/dev/config
Accept=[application/json, application/*+json]
Response 200 OK
But the problem is, client service is trying to start on config server port 8888. I have set server.port=8080 in the client but still not working.
***************************
APPLICATION FAILED TO START
***************************
Description:
Web server failed to start. Port 8888 was already in use.
Am I missing any configuration here? Highly appreciate any help.
Config server application.properties,
spring.application.name=config-server
spring.cloud.config.profiles=dev
spring.cloud.config.server.git.uri=REPO_URL
server.port=8888
Finally, I was able to find the solution. When I was trying to start client service, server.port was also getting overridden with config server port. I added server.port=8080 in the properties file for the client service profile in config repo (account-service.properties) and it worked.

Spring Configuration Server: Fallback configuration in case repository is not available

We use spring cloud configuration Server (SCCS) with a svn backend.
I currently investigate into fallback/emergency scenarios when the backend is (temporarly) not available.
In case of a svn backend SCCS is downloading the configuration files into a local directory.
Our idea is to configure SCCS it first looks for the svn backend, and when it is not available the copied files are taken for the source.
Does anybody know how configuration has to look like, or has a totally different idea how this scenario is to be faced?
Thank you in advance!
So basically you want the Cloud Config Server to have multiple repositories. You can do that with profiles, but the switch from one repository to another one won't be automatic (at least from the top of my head).
The Spring Cloud Config Server bootstrap.yml with two repositories:
spring:
profiles.active: remote-svn
application:
name: config-server
cloud:
config:
server:
svn:
uri: https://yourserver.com/config-repo
force-pull: true
//---
spring:
profiles: local-svn
application:
name: config-server
cloud:
config:
server:
svn:
uri: ${user.home}/config-repo
Generally you would start your server like:
mvn spring-boot:run
But if your remote svn server is down, you would kill the server and restart it like:
mvn spring-boot:run -Dspring.profiles.active=local-svn
The thing is that you must maintain both of these repositories synced. So when you push your configurations to the SVN repository, you need to have two remotes configured. One referencing your SVN server and the other referencing the Spring Cloud Config Server repository.
You can have a bash script with a logic that checks the health of your SVN server and when it finds out that the server is down it restart the Spring Cloud Config Server using the local-svn profile.

How to register a service using Spring Cloud Consul

I have registered a service using Spring Cloud Consul, but for this I had to run a Consul local agent which establishes a channel communication to Consul server node (running as bootstrap).
For example:
#Server
consul agent -server -bootstrap -bind -data-dir data -ui-dir web_ui
#Desktop
consul agent -data-dir consul -ui-dir consul/dist -join server_ip_address
Is there any way to avoid of having this local agent in my desktop, I mean from my desktop Spring Cloud Consul would register the service to server node?
An example of this is what Netflix Eureka client does with Netflix Eureka server, no external agents running in machines to bind services names.
you have to use property file or yaml file i just give sample yaml file
application.yml
# Configure this Discovery Server
spring:
cloud:
consul:
host: localhost
port: 8500
bootstrap.yml
spring:
application:
name: service-name

Resources