I use spring boot and undertow in eureka server. After I kill the process, it tells me the port is in use when I restart the applicaiton.
I searched and finded that the server application won't release the port immediately after stopping . It will wait about 50s.
Someone suggested to add REUSE option:
setsockopt(listenfd,SOL_SOCKET,SO_REUSEADDR,&opt,sizeof(&opt));
I am wondering if there is a way to to this in spring boot embedded containers.
Thanks.
Related
Need help with technical solution.
I have java (spring boot) application which may start docker container. Application assign ID and port to each container. That port is used as separate UI. ID is used to stop container.
For now, application work with 443 secured port, while each container open it own port in a range 19000-19100.
Is it possible to setup something like proxy server in application, verify request and then forward it to container?
Let's say, instead of myhost.com:19000 I want to use myhost.com/container/{containerId}?
I'm thinking about rest template or feign client, but not sure how it will behave with websockets. Any thoughts? Existing tools or libraries?
Take a look at Spring Cloud Netflix Zuul.
I am working on a project where we use this to proxy requests from frontend to a service which handles persistence processes.
Maybe it will help you achieve what you are looking for.
I'm using docker swarm. I have two services.
Spring boot app
PostgreSQL database
every things is ok. suppose :
all of my tasks be kill for any reason (for example restart the server) swarm try to run my services.
my problem is there if first run spring boot then run database. in this status my spring boot can not connect to database. and my app not working.
I know that I can resolve this problem in spring with connection pool but I want handle it in docker swarm.
can you help me?
is there any way ????
When starting/relaunching a Spring Boot App and the app runs on a port which was already in use before I got an error:
Web server failed to start. Port 8092 was already in use.
So, everytime I am starting a Spring Boot App I have to switch server.port in application.properties.
Note: Because I do not have the Run as "Spring Boot App" I use the work around mentioned here to start it:
First Answer, How to run Spring Boot web application in Eclipse itself?
Is there a solution to avoid switching ports every time?
Thanks a lot!
I have created a Spring Boot microservice and hosted inside a Tomcat on a Linux machine.
Everything is inside the container and the container is inside the IBM cloud private platform.
Now the microservice should be running continuously.
But suppose for any reasons the microservice got stop or tomcat got crashed.
Is there any way we could restart the Tomcat server or microservice automatically without manual intervention?
Why are you deploying a Spring boot app in your local tomcat? By default Springboot comes with embedded Tomcat server in it, so if you just build and run the jar, a tomcat will be started with the service itself.You can also , configure the server type(tomcat or jetty) and other server properties in the application.yml file. More details here - https://www.springboottutorial.com/spring-boot-with-embedded-servers-tomcat-jetty
Coming to the second part, of the question,about how to make sure , that if one service crashes, a new instance should be started automatically, for this you might be needing to do some reading on container managers like dockerswarm or kubernetes, which support auto-scaling, and can take care of restarting services (pods) as and when required,they can even scale up, meaning increase the number of instances of a service if existing containers reach a resource usage threshold and then load balancing requests to that service through some discovery and registry client.I think this would be helpful to you - https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#restart-policy
The problem is relatively simple:
I have a web based application, that, among other things, needs to check for status of a remote service. This remote service has JMX based mbeans exposed. However, the remote service might be not running all the time. What I need is:
Setup Spring to connect to remote JMX server
When the remote is not running, present this information in the web ui
The problem with this is that if I setup the JMX client bean in springContext.xml and the service is not running, the webapp won't even start with exceptions like ConnectionRefused and so on.
So the question is: is there a way I can tell spring to ignore the fact that it cannot connect to remote mbean server and try it later?
I am assuming you are using the MBeanServerConnectionFactoryBean? Set the connectOnStartup property to false.