Access one database from two sping boot applications - java

I have two separate spring boot projects that share one database (MySQL).
Is there a way I can host these two applications on a VPS and make them share the same database the way I make them share it on a local server?
Thank you

MySQL supports multiple client connections. Assuming your 2 apps and MySQL are running ok locally, they should all work the same if deployed to the same VPS. If you are deploying across multiple VPS instances then you would need to consider configuring network routes between the instances and firewall rules to allow traffic to flow between them.

Related

Deploy two spring boot applications with shared database into AWS (architecture)

I have two spring boot applications with shared database. Locally everything works perfect, I can run war files (tomcat is embedded) on ports 8080 and 8081.
Question is, how I can run it on AWS?
I know, there are a lot of possibilities, but I am really a beginner and have no experience. I just tried to run it on AWS as it is (as .war files) and open ports... this is working of course. But this is not secure for PROD. Another issue, I cannot serve it as HTTPS.
My imagine is described in the picture. Probably there should be some splitter (marked as ???X1) in the front and some container for the applications (???Y1).
Please, could somebody help me here? What is the best/simplest/the most secure/best performance solution.
Q2: I am not sure, whether I should use embedded tomcats for war applications.
Thank you in advance
picture of architecture
Launch your both apps on one Ec2 Instance( WebServer Instance) , use different ports (80,81), Launch this Ec2 instance in Public Subnet.
Launch another Instance for your Database and keep that instance in Private Subnet.
this Database instance will be accessed by only Public subnet's Instance ( WebServer Instance)..
keeping Database Instance in Private Subnet will make it secure as no one can access it other than your own webserver.
OR
Use Amazon RDS for your Database, which is managed service and secure one.
The "splitter" thing in your image would be an Application Load Balancer on AWS. And you can create free SSL certificates in AWS ACM that can be attached to the Application Load Balancer.

Testing a Spring application on multiple JVMs

I have coded a Spring MVC Hibernate application with RabbitMQ as a messaging server & a MySQL DB. I have also used Hazelcast an in-memory distributed cache to centralize the state of the application, moving the local tomcat session to a centralized session & implementing distributed locks.
The app right now is hosted on a single tomcat server in my local system.
I want to test my application on a multiple JVM node environment i'e app running on multiple tomcat servers.
What would be the best approach to test the app.
Few things that come to my mind
A. Install & configure a load balancer & set up a tomcat cluster in my local system. This I believe is a tedious task & requires much effort.
B. Host the application on a PAAS like OpenShift, cloudfoundry but I am not sure if I will be able to test my application on several nodes.
C. Any other way to simulate a clustered environment on my local windows system?
I would suggest first you should understand your application requirement. For the real production/live environment, are you going to use Infrastructure as a service or PAAS.
If Infrastructure as a service then
I would suggest create local cluster environment and use the tomcat and spring application sticky session concept. Persist the session in Hazelcast or redis server installed on different node. Configure load balancer for multiple nodes having tomcat server. 2-3 VMs for testing purpose would be suitable.
If requirement is PAAS then
Don't think about local environment. Test directly on OpenShift or AWS free account and trust me you would be able to test on PAAS if all setup is fine.

How to start slaves on different machines in spring remote partitioning strategy

I am using spring batch local partitioning to process my Job.In local partitioning multiple slaves will be created in same instance i.e in the same job. How Remote partitioning is different from local partitioning.What i am assuming is that in Remote partitioning each slave will be executed in different machine. Is my understanding correct. If my understanding is correct how to start the slaves in different machines without using cloudfoundry. I have seen Michael Minella talk on Remote partitioning https://www.youtube.com/watch?v=CYTj5YT7CZU tutorial. I am curious to know how remote partitioning works without using cloudfoundry. How can I start slaves in different machines?
While that video uses CloudFoundry, the premise of how it works applies off CloudFoundry as well. In that video I launch multiple JVM processes (web apps in that case). Some are configured as slaves so they listen for work. The other is configured as a master and he's the one I use to do the actual launching of the job.
Off of CloudFoundry, this would be no different than deploying WAR files onto Tomcat instances on multiple servers. You could also use Spring Boot to package executable jar files that run your Spring applications in a web container. In fact, the code for that video (which is available on Github here: https://github.com/mminella/Spring-Batch-Talk-2.0) can be used in the same way it was on CF. The only change you'd need to make is to not use the CF specific connection factories and use traditional configuration for your services.
In the end, the deployment model is the same off CloudFoundry or on. You launch multiple JVM processes on multiple machines (connected by middleware of your choice) and Spring Batch handles the rest.

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.

convert weblogic admin server into managed server

I'm currently having 2 Weblogic admin servers in 2 different domains created on the same machine.
I want to convert one of the admin server to a managed server and then use them together to deploy a Java application. Is this feasible? If yes, how?
I'm currently using Weblogic Server 10.3.
PS: I'm quite new to Weblogic domain creation and administration. Please revert for any more details needed.
The simple answer is no, however, adding a managed server to a domain is extremely simple. See the documentation here. When deploying your application you'll need to target both servers or create a cluster (also very easy), add both machines to it and give the cluster name as the target.
Note, it is generally not concidered best practice to target applications to the Admin server (although it's fine when you're developing on your local machine). If you have the resources available on your environment, you could create two managed servers and put them in a cluster. Depending on the configuration of your Admin server, you may be able to reduce it's size if memory is tight.

Categories