Integrating Vert.x with spring data JPA - spring-boot

I am currently using common approach of calling Spring data JPA repository from Spring service class. But as those calls are blocking, performance is not good for my use-case as number of requests I have to handle is very high.
So I plan to use Vert.x. My understanding is that I would need to call DAO repository from verticle, which in turn I need to integrate in service layer.
Would that be correct way of doing that?

Related

best way to handle workflow call between multiple Spring Boot microservices using central service

I have to implement 4 microservice in spring boot , spring cloud and there is a central microservices that will handle the workflow between these 4 services like first service call then on response back to central one and then central one will make call to second service and so on . my question is how to implement (best possible way)central microservice avoiding if/else ?
Since you're already using Spring I suggest you have a look at Spring Statemachine.
You don't give much details but I think it sounds like it'd be a good fit.

is spring boot only for building rest api?

and if not what are more things that we can do with spring boot?
i know that we can build a whole web app(frontend and backend) in one spring boot application in the folder resource/template and resource/static but in the real world does somebody uses this method to create web application with the resource/template and resource/static?
and one more question what is used in the real world hibernate(with the SessionFactory or EntityManager) or JpaRepository in the spring data jpa?
No Spring Boot isn't just for REST APIs.
Spring Boot is "just" a mechanism for autoconfiguring a Spring Framework based application.
Therefore you can use and it does get used for all kinds of stuff.
REST APIs for webservices
Full web application using Spring MVC
SOAP services (or are they called SOAP dispensers?)
Reactive web applications
Command line tools
Batch jobs
Swing / JavaFX applications
...
Of course there are many more people writing web applications than Swing applications with or without Spring.
The kind of web application you describe and which I put under "Full web application using Spring MVC" is a very well established model and when done right way better aligned with the principles of REST than the average so called REST service. My very personal guess is: They will still be around when nobody remembers what Angular is.
For your additional question:
Your question sounds a little like the relation between JPA and Spring Data JPA might not be completely clear.
(see Spring Data JDBC / Spring Data JPA vs Hibernate)
Both are certainly used in real world projects. By definition more projects use JPA than Spring Data JPA since the first is a superset of the later.
This involves complete Spring history,
Actual motive of Spring was to enable loose coupling , so that unit tests can be easily performed . Spring MVC was for developing web applications with Model View Controller having their proper boundaries.
Then Spring Boot which enabled developer to focus on business logic then configurations. That's why spring boot is a good choice for microservices.
For JPA or hibernate query , many people prefer using JPARepositoy as again you just have to define entity for the repository and Spring boot automatically provides you queries like findById and so on.
In short Spring boot have made it really easy to run the applications with different configurations and environment smoothly.

Spring REST service with third party api as a datasource

I need to expose REST service which as a datasource gets data returned from third party api calls, instead of regular DB.
I'd like to have all the benefits of the Spring Data Rest, but I don't know what I really need as my dependency, since I'm not using JPA.
Basicaly, how my model (Entity?) should be implemented to have the functionalities (like, paging, sorting...).
What Spring framework dependencies should I choose.
Or possibly I'm overlooking something here and for such requirement is another path.
Thanks.

Spring Integration Webservice vs. RestTemplate

I'm trying to learn SI (Spring Integration) but i'm a bit confused on the real usage of this.
As first example i would like to interact with a WebService but i dont understand what could be the difference from
Invoke a WebService Using SI
Invoke a Webservice using RestTemplate
So, what is the benefit of using SI (in Webservice context, or in other context)?
Looking the web, i havent find an article that explain:
Usually you will do in this way....
With SI you can do better - in this another way - and the benefit are....
To be more explicit on what i have to realize, this is an example:
1) I have to write an application (Standalone application) that have to collect some data in the system periodically and then invoke a Web Service that will store it.
2) The Web Service receive the call from the "clients" and store in the database.
My webservice will use REST.
The reason because i've think to use SI is that the Standalone Application should interact with different system
Webservice in first instance
A Web Mail, if the webservice is not achievable
File system if Web mail is not achievable too
If you only need to pull some data in a simple way and push it onwards to a REST service this does not "justify" the use of Spring Integration. A simple Spring (Boot) application combined with a scheduler will be sufficient.
But if you want to use a more complex data source for which an endpoint is available, you need transformations, complex and flexible routing is a high priority or even Enterprise Integration Patterns (EIP) then Spring Integration is for you. Have a look at the Overview and decide if it mentions something you consider as valuable to you.
Perhaps you will create additional value by mixing in Spring Batch if you need to process a lot of data.
But as I understand your current demand starting with just a RESTTemplate should do for the moment. Starting small will not prevent you from switching to Spring Integration later on.
Have a look at the various tutorials and guides provided by the Spring Boot project. There is even an example for Spring Integration.

Spring Enterprise Application Best Practices

After read the Gordon's article about Best Practices to build Enterprise Application using Spring Framework, I would like to share some ideas about the Service layer.
My architecture represents exactly what Gordon described in this image http://gordondickens.com/wordpress/wp-content/uploads/2012/07/Spring-App-Layers.png
The application is complex, has a heavy business rule and demands to use different resources like Database, SOAP, REST and file handle sometimes in the same use case.
For this scenery that I have described above, I have a Service class that needs to perform SOAP and REST requests and handle some database data. So, I have autowired in my Service class a SOAP and a REST component and the Repository to handle the database stuff.
I'm concerned about if this is the best approach do handle the integration between my Services and the resources like SOAP, REST, Database and etc.
Thanks
So, I have autowired in my Service class a SOAP and a REST component
and the Repository to handle the database stuff.
Sounds problematic even though it will work.
Think about the dependency between layers. Service layer will depend on Repository layer (Business logic layer will depend on data layer). Service integration layer (or service communication layer) for incoming requests will depend on the Service layer. But the data layer does not depend on the service layer. Nor the service layer depend on the inbound service invocation layer.
So, remove the SOAP and REST components from the Service class. To the SOAP and REST components, wire the Service instance (i.e. avoid SOAP and REST components wired into the Service, do it in the reverse direction).
This way, when you want to support another integration protocol (say JMS), you do all such work not by modifying your service.
Your data access seems to be fine. I hope your Service accesses the repository via DAOs.
So, I have autowired in my Service class a SOAP and a REST component
and the Repository to handle the database stuff.
Sounds fine. You are using dependency injection, this means they can be easily tested or altered.

Resources