Name based virtual hosting with Spring Boot - java

I am looking for the best method to host multiple websites developed using Spring Boot.
I have a public IP and it points to EC2 machine.
Already I am running one web application on it, developed using Spring Boot.
Now, I am looking for a way to create my second Spring Boot application(running on a different port).
My configuration should result like this(Single public IP),
www.app1.com(x.x.x.x) => Spring Boot App1
www.app2.com(x.x.x.x) => Spring Boot App2
I found many articles on internet dealing with conf/server.xml file, http://tomcat.apache.org/tomcat-7.0-doc/config/host.html
Can someone help me to achieve the same

The best way is probably to use a reverse proxy front end. E.g. install nginx on your EC2 box, or (probably better if you are serious about it) use an ELB, and Route 53 to register your DNS record.

Related

setup proxy to docker containers from java application

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.

spring boot actuator refreshscope

I have an application which is running on multiple AWS hosts behind a load balancer. All of these instances load the configuration from a spring config server. I can use spring boot admin server to identify the the URL's so that I can execute the POST at hostname:port/actuator/refresh command for individual host using POSTMAN. As the number of hosts increase, it becomes difficult to run a command for each one of the hosts. Is there a way I can do the same with a single command?
We use something similar for our application
i.e Spring applications fetching properties from config server and a spring boot admin server to which all these application registers.
We have exposed an post api in bootadmin which calls refresh endpoint on all instances of specified app.
Since bootadmin has all information about registered apps, we are using it to 'publish' message to all 'subscribed' apps.

Spring Cloud Starter Eureka without a webserver

Is it possible to run an eureka client without running a webserver? The 'spring-cloud-starter-eureka' artifact automatically pulls in 'spring-boot-starter-web'. Why is that? Is it possible to run the client without actually starting up a webserver?
My problem is that starting up a webserver eats up around ~200mb of ram. This is a problem because the memory allocated for the apps I want to use eureka with is ranging from 256-512mb.
It seems you don't need this service of yours to serve web request but still need the it to access your eureka server.
So disable web from the application.
spring.main.web-environment=false
And use the Discoveryclient to fetch the services.
If that is not good enough then remove eureka dependency and Make a rest call using (RestTemplate) to your eureka server to query for the services you need. Eureka exposes a rest endpoint for this. So it can't be used by even non-java/jvm based applications.
You could take a look at this project I wrote some time ago to see how to do this.
If that is not good enough still. Then you might have to write plain java code which you should be writing in the first place unless you have a reason to be using a framework such as spring (Transaction,JPA, web, security etc).

How to run multiple Spring Boot applications easily on Production

I am trying to figure out an easy way to manage many Spring Boot applications on my Production server. Right now I have many fat jars running on different folders where each one has its your own script to start/stop the application and there's an external folder for the configurations (logback, properties, xml). For record those configurations are loaded by command line -Dloader.path to Spring Boot execution.
So how can I avoid conflicts for the same http/https port already running on Production? Does exist any kind of application manager where system administrators could control it? One solution I found was to virtualize Spring Boot applications with Docker, but my environment is Unix Solaris.
Is there any java solution for this scenario?
You can have a look at Spring Cloud which will give you better control and management when running multiple boot applications. All components of Spring Cloud
might not be useful to you, but few of them will help in port resolution, service rerouting and property maintenance. Along with the above you can also try SBA.
Along with the above you can also try Nginx for UI load balancing and reverse proxy.

spring boot application in cluster

I am developing a spring boot application.
Since spring boot created a .jar file for an application.
I want to cluster this particular application on different server. Lets say I build a jar file and ran a project then it should run in cluster mode from number of defined servers and should be able to serve end user needs.
My jar will reside on only one server but it will be clustered across number of servers. When end user calls a web service from my spring boot app he never know from where it is getting called.
The reason behind clustering is suppose any of the server goes down in future, end user will still be able to access web services from another server. But I don't know how to make it clustered.
Can any one please give me insight on this ?
If you want to have it clustered, you just run your Spring Boot application on multiple servers (of course, the JAR must be present on those servers, otherwise you can't run it). You would then place a loadbalancer in front of the application servers to distribute the load.
If all services you are going to expose are stateless so you only need to use load balancer in front of your nodes for ex. apache or nginx, if your services are stateful "store any state [session, store data in db]" so you have to use distributed cache or in memory data grid:
for session you can use spring-session project which could used rails to store sessions.
for store data in DB you need to cluster DB it self and can use distributed cache above your DB layer like Hazelcast.
Look into spring cloud, they have used some netflix open software along with amazons to create 12 factor apps for micro services.
Ideally you would need a load balancer, service registry that can help you achieve multiple instances of spring boot. I believe you have to add a dependency called eureka.
Check the below link
Spring cloud
You can deploy it in cloud foundry and use autoscale function to increase your application instances.

Categories