I am trying to reduce database connections from my service which is using Spring Data JPA to connect to the database. I have created a separate microservice and exposed an API which will return response based on the queries passed in the request body. Is there any simple way to perform this migration as there are multiple database connections happening in my service.
I tried this migration but it requires a lot of code change to integrate this database API.
Related
I have an application which is using Spring data JPA and hibernate envers for db auditing.
Since R2DBC doesn't support auditing yet, is it possible to use combination of both in a single application?
If yes, Plan is to use Spring Data JPA for insert, update and delete operations, so that all DB auditing will be handled by hibernate envers. And use R2DBC for reactive non-blocking API's to read data.
If no, Is there any suggestions on how to achieve both reactive API's and auditing?
Spring provided simple Auditing via #EnableR2dbcAuditing, check my example.
Mix JPA in a reactive application is also possible, I have an example to demo run JPA in a reactive application, but not added r2dbc in it.
For your plan, a better solution is applying the cqrs pattern on the database topology, use database cluster for your application.
JPA for applying changes, use the main/master database to accept the modification, and sync changes to the secondary/slave database.
r2dbc for queries as you expected, use the secondary/slave database to query.
use a gateway at the front for the query and command service.
Update: I have created a sample to demo JPA and R2dbc coexistence in a single webflux application. But I do not suggest using it in real-world applications. Consider the 3rd solution above if you really need it.
Yes it is possible however you will probably face two issues, one is that multiple repos modules handling needs to be explicited (e.g specify the paths of the respective modules).
Secondly, the JDBC/JPA Spring Boot autoconfiguration will be disabled and you need to import it back.
Those issues have been reported in Reactive and Non Reactive repository in a Spring Boot application with H2 database
And a solution to them and the thought process can be found in this issue:
https://github.com/spring-projects/spring-boot/issues/28025
At my job we're gradually replacing a monolithic legacy system with a microservices architecture. I've been tasked with writing an auth server using Asp.Net Core, Identity Server 4 and Entity Framework*. The legacy system already has auth and our deadline is approaching, so we're going to use the legacy system as a backend for the time being.
How can I set up Identity Server/Entity Framework to pull login info through the legacy system? So far, everything I've found involves adding a database like SQL server. Assume for the sake of argument I'm not able to pull data directly from the MySQL database that the legacy system uses, but it is easy to get the user data via a JSON API.
I have written a DbContext and an implementation of IProfileService which uses it, but I'm not sure how to actually pull the users in the DbContext, and when I try to sign in from a client I get this error:
No database provider has been configured for this DbContext. A provider can be configured by overriding the DbContext.OnConfiguring method or by using AddDbContext on the application service provider. If AddDbContext is used, then also ensure that your DbContext type accepts a DbContextOptions object in its constructor and passes it to the base constructor for DbContext.
However I haven't been able to find/figure out what to put in DbContext.OnConfiguring to set this up. I suppose I need to implement IServiceProvider somewhere, but can't find any details of how to do so.
*We're not married to these so suggestions for something more appropriate are welcome. We are using .Net Core.
The EF bit seems like a red herring here. If you're talking to an API in a legacy system then you won't use EF for that at all.
If using IdentityServer4 then it makes sense to use their EF implementations for the configuration and operational stores and then implement your sign in UI, IClaimsService etc using the API exposed by your existing system. To do that just create a simple client implementation that calls said API and accepts and returns whatever models you require.
I have a very simple service project (SpringBootApplication) that exposes a REST endpoint via a Spring Boot controller class. The controller maps an /events endpoint that converts a simple incoming event DTO into a slightly different event entity object that is then persisted in a database via a org.springframework.data.repository.CrudRepository instance.
In my controller, I am only mapping the POST operator because I don't want my clients to be able to GET, PUT or DELETE data from the service.
During a security scan today, I discovered that the service is exposing a /eventsEntities endpoint, which appears to be mapping all of the CrudRepository verbs into the REST endpoint.
Any idea how I managed to enable this automatic endpoint and more importantly, how to disable it? I'm using Spring Boot 1.2.2.
After some additional digging, I realized that I had inadvertently included org.springframework.boot:spring-boot-starter-data-rest in my compile dependencies. That starter includes spring-data-rest-webmvc, which exposes JPA data over REST. Removing that dependency resolved the issue.
Hope my realization helps someone else in the future.
I have a web server application using Couchbase Server as its backend database.
Application comprises of few set of REST API's.
Now I have tested all my REST API's properly and deeply for all the scenarios, now I am in a dilemma if I should test my DB separately or not.
Because my REST API's gave me correct response (from DB) for all my input's passed to them.
So is there a need to separately test my DB using sql queries because it is the same thing which was done by API's.
And I am not considering the performance testing which is in my later scope. Just considering the functional testing.
My application currently accesses SQL Server the "traditional" way - via EntityConnection on top of SqlClient. I would like to add the option of accessing SQL Server via a new OData service. Any ideas on the best way to do this? Is it possible to reuse the existing model-first EntityObject-derived classes? Thanks!
The best way would be to follow this tutorial to create an OData service: http://www.asp.net/web-api/overview/odata-support-in-aspnet-web-api/odata-v4/create-an-odata-v4-endpoint.
Update adding more details given the comment:
Although the link should be enough for answering the question, I can also elaborate on the end-to-end scenario a little bit.
Now the premium experience of creating an OData V4 service out of an SQL Server DB is to use the ASP.NET Web API 2.2 for OData V4. With the help of the code-first aspect of entity framework you can create an OData V4 service that supports pagination, queries, and CRUD operations in a very reasonable time (about 10 minutes for every table in your database).
As soon as the service is created, various client libraries that supports consuming V4 services can be at your service. The premium experience on the .NET platform is the OData v4 Client Code Generator.
If your consumer is a non-developer, Power Query can help you import the data from the OData service. Their support for V4 services will come early next year according to this, but Excel and Power Pivot already natively support consuming V1-3 services. For creating a V1-3 service, the tutorial next to the one I gave at first would help.