Hello stackoverflowers!
So I am working on spring boot microservices and following scenario came up:
I have follwing services:
user-services
admin-services
financial-services
and couple more..
I have spring-cloud where all my apps are reading configs from in combination with Eureka as discovery and Zuul as gateway servers.
Here's the scenario, the database is only one (very old legacy one) which we can't break into multiple dbs per microservice app (as per true microservice concepts). Now when all these apps will be started (most probably 2 instances per service) so there will be around 30 opened connections on the db. Is there a way to use a common database layer since there is only one db and all the apps configured to that layer?
Related
I am trying to understand the correlation between Database connections and spring boot app. My spring boot app is connecting to one schema and I am running 4 such spring boot apps on my system. Each app is connecting to a different schema.
The problem is that these 4 apps are acquiring 50 oracle db connections, but when I close all apps and open DB through oracle sql developer only one connection is acquired.
I don't have enough rep to post this as a comment.
By default Spring Boot uses HikariCP as a connection pooling framework. Some good information can be found at Baeldung, which I recommend using as it covers lots Spring Boot functionality and is almost always up to date.
https://www.baeldung.com/hikaricp
Spring-boot specific information:
https://www.baeldung.com/spring-boot-hikari
While 10 connections are not at all required, you can 'play' around with how much is best (or most optimum) for your app and set it as best fits your design. Usually this will be done by optimizing this as the need arises in your application. 10 is what spring/hikari identifies as a good starting point for most projects.
https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#data.sql.datasource.connection-pool
Since I had to post this as an answer I'll go a little more in depth in your actual question:
If we think of a connection to a database without a pool we can think of:
The application requests the driver to open a connection to your database
A socket is opened between your application and the database
You are authenticated to the database
Your query runs and the connection is closed
This is fine in a small application without many requests going through, but hopefully you can see the issue here as we scale and get more users. Removing the first 3 steps can make a huge difference.
It should also be noted that while your database holds 3 connections, the connections will be idle and not generating much (if any) load on your database.
I have a spring boot application with 3 tier architecture client->Application server(Spring boot application)->DB.
I want to split the current app server into two, one for handling the client request/response and business logic like controllers and services only.
Another one is for only communicating with DB like DAO,and spring data jpa's only.
These two servers will communicate through REST api.
I don't know this approach is good or not. Please suggest.
I have two micro services. One is in spring boot and other is using simple jdbc apis to perform database operation. I have to perform database operation using these two services.
(i.e.
Insert using jdbc service,
Insert using spring-boot service,
Insert using jdbc service).
These operation should follow acid property.
I have tried saga pattern using axon framework, it is working fine but I want to do it by using 2pc protocol. I have tried 2pc protocol in jdbc service but it is working only for transactions happened only in this service. I also used atomikos framework in spring service, it is working for this service only.
Is there any way to co-ordinate javax.transaction and springframework.transaction ?
For the scenario described in the question, you should try using Oracle Transaction Manager for Microservices (MicroTx). It is a free product that comes with a transaction manager and client library for microservices written in Java and node.js. With this, you can create XA (2PC) transactions involving multiple microservices. Oracle MicroTx - https://www.oracle.com/database/transaction-manager-for-microservices
I have two spring boot apps running in the same local network and they need to communicate with each other. An obvious answer is to leverage REST API and make http calls, but I would like to use Spring Integration project for this purpose.
That said, I have several architectural questions regarding that:
Should I setup a standalone messaging framework (e.g. Rabbit MQ) or embedded should also work (e.g. messaging will be embedded to one of the two apps).
If standalone, what messaging framework should I choose: ActiveMQ, RabbitMQ or something else?
Welcome to the Messaging Microservices world!
You go right way, but forget the embedded middleware if you are going to production. Especially when your application will be distributed geographically.
So, right you need some Message Broker and that should be definitely external one.
It's really your choice which one is better for your purpose. For example you can even take into account Apache Kafka or Redis.
If we talk here about Spring Integration it might be better for you to consider to use our new product - Spring Cloud Stream.
With that you just have your applications as Spring Boot Microservices which are able to connect to the external middleware transparently for the application. You just deal with message channels in the application!
I have a web application which uses Spring and connects to mongdb using spring data mongodb.
I want to extend it by connecting to multiple database instance for each tenant. There are some solutions which are available on stackoverflow. One was mentioned on Multi-tenant mongodb database based with spring data where the code was on github on the following link-
https://github.com/Loki-Afro/multi-tenant-spring-mongodb
I have a question regarding this? Will this approach work for concurrent requests?
I am also doing the same thing, autowiring the MongoTemplate and Repository.
Since these beans are singletons, they will be the same for each request. Then how will the database change for different request and what happens when multiple requests are being served in parallel?