How to configure maxDegreeOfParallelism for cosmosdb in Springboot? - spring-boot

I want to configure the CosmosQueryRequestOptions.maxDegreeOfParallelism while using the CosmosRepository. I didn't find any documentation around it.
This blog shows how to configure and use this setting through a custom client, but I want to use the repository instead. https://medium.com/#middha.nishant173/improve-query-performance-with-azure-cosmosdb-java-sdk-v4-db1fc54cb484

CosmosQueryRequestOptions is implementation detail for Spring Data Cosmos SDK, so customers cannot set it through spring application.
This can be implemented as a new feature, and can be exposed through application.properties via query.maxDegreeOfParallelism - which customers can opt in if they want.
Default value for maxDegreeOfParallelism is 0, which is the right value for single partition queries. For cross partition queries in the current SDK version, you can get the cosmosClient through spring boot applicationContext and run the query directly against the client. This example shows how to do it - https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/cosmos/azure-spring-data-cosmos-test/src/test/java/com/azure/spring/data/cosmos/repository/integration/PageableAddressRepositoryIT.java#L144

Related

What is the best way to maintain queries in Spring boot application?

In My Application, Using the below technologies
Spring boot 2.7.x
Cassandra
spring batch 5. x
java 11
As part of this, I need to extract data from the Cassandra database and need to write out the file
so here I need to use queries to fetch data so
just want to know what is the best way to maintain all queries at one place so any query changes come in the future, I shouldn't build the app rather just need to modify the query.
Using a repository class is necessary. If you are using JPA i recommend using a repository for each Entity class. With JDBC it is possible to create a single repository which contains all the queries. To access the query methodes i would use a service class. In this way your code is structured well and maintainable for future changes.

Spring Boot: Handle configuration in multitenant application

I am implementing a Spring Boot application which will be providing a multitenant environment. That is achieved in my case by using a database schema for each customer. Example see this project.
Now I am wondering how to implement tenant-specific configurations. I am using #ConfigurationProperties to bundle my property values, but these are getting instantiated once and not for each tenant.
What if I would like to use Spring Cloud Config with multiple tenant specific git repository as an configuration backend. Would it be possible when using a jdbc backend for Spring Cloud Config?
Is there any way with default Spring mechanisms or do I have to implement a database based configuration framework myself?
Edit: For example I have two tenants called Tenant1 and Tenant2. Both are running over the same application in the same context and are writing in the database schemes tenant_1 and tenant_2.
Identification of tenants is happening over keycloak (see Spring Keycloak multi tenant example). So I identify the tenantId from the jwt token and select the database connection like described here.
But now I would need the same mechanism for #Configuration beans. Since #Configuration beans are as far as I know Singletons, so there is always ONE configuration per application scope, and not ONE configuration per tenant.
So using Spring Cloud Config Tenant1 is using https://git-url/tenant1, Tenant2 is using Hashicorp Vault as backend and perhaps Tenant3 will be using a jdbc based configuration backend. And all of that in ONE (of course scalable) application.
In case your application uses tenant specific files (html templates etc), the following can be applied. As I have used the below approach for handling many tenants and works fine and easy to maintain.
I would suggest that you maintain a consistent configuration source (JDBC) for all of your tenant configurations. This helps you have a single source that is cacheable and scalable for your application. Also, you could have your tenants navigate to a configuration page to manage their settings and alter them to suit their needs at any point of time on the fly. (Example Settings: Records Per Page, Theme, Logo, Filters etc...)
Having the tenant configuration in files in git will be a difficult task when you wanted to auto-provision tenant's when they sign-up as it will involve couple of distributed services. Having them in a TenantSettings table with the tenantId as a column could help you get the data in no time and will be easy.
You can use Spring Cloud Config for your scenario and it is adoptable. It is easily configurable and provides out of the box features. For your specific scenario, you can have any number of microservices running yet all controlled by one Spring Cloud Config Server which is connected to one Git Repository. Your all microservices are asking configuration properties from Spring Cloud Config Server and it is directly fetching properties from Git Repository. That repository can have multiple property files. It can hold common properties for all the microservices or specific service based configuration properties. If you want to keep confidential properties more securely, that is also made possible via HashiCorp vault. I will leave an image below for you to get a better idea about this concept.
In the below image, you can see the Git Repository with common configuration property files and specific configuration property files for different services yet in same repository.
I will add another image for you to get a better idea how does this can be arranged with application profiles as well.
Finally I will add something additional to show the power of Spring Cloud Config and out of the box features it allows us to play with. You can automatically refresh configuration properties in running application as well. You can configure Spring Cloud Config to do that. I will add an architectural diagram to achieve that.
References for this answer is taken from Spring in Action, Fifth Edition
Craig Walls

How to automatically create DynamoDB table on application startup using Spring Data DynamoDB?

I am using spring-data-dynamodb Spring Data extension to integrate AWS DynamDB with Spring Boot 2.0. I was able to make it work.
My question is, is there a way that the table is automatically created on application startup if it doesn't already exists, similar to what Hiberate offers via hibernate.hbm2ddl.auto ?. Right now, I have to create the table manually or in the application using the AWS DynamoDB sdk. Many Thanks.
Right now there is no such feature but there is an open feature request: https://github.com/derjust/spring-data-dynamodb/issues/17 (which I'm actually working on these days)
Note: I'm the maintainer of this GitHub project.

Spring boot , Elasticsearch

Searched over the net but unable to find the satisfying approach.
I am new to spring boot and aware of starter dependancies,
I want to develop a springboot app using elastic search as a storage system.
Wherever i searched i found that somewhere my service class will have to implement some interface from springframework for ES crud operations.
Is there any other way without implementing or extending the components.
I myself want to create transport client and want to query ES by my code or methods not by overidden ones.
Please if you ahve ever seen any projects you can redirect me to that link .
Thanks.
Assuming I understand you correctly, you can use the Elasticsearch REST client: https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-low.html
You supply the JSON entities for the queries and parse the responses yourself. Its pretty basic in what it does, so you're not dependent on a lot of third party stuff to perform operations.

Can someone provide me an example for Spring Data Couch Base 2.x client to store and retrieve data in Key Value format from couch base server?

My current project uses spring data couch base 1.2.3 Release version where CouchBaseClient object will be there to retrieve save/get data in key value format from couch base server/cluster/bucket. Now we are planning to upgrade spring data couch base version to 2.x, but CouchBaseClient object has been deleted in 2.x instead bucket/cluster beans are available. Bucket object doesn't have any APIs/methods to save/get data in key value format [ i might be wrong, not sure] so request to help me to find out how to proceed further is there a way in 2.x to store data in key value format?
we have plans to upgrade spring boot version to 1.4.4.release as well so if there are any others ways to interact easily with couch base server, please let me know.
My project env info:
Spring boot 1.2.3
Java 1.8
Thanks,
Satish
This is more a factor of the underlying SDK being of a different generation (2nd generation of Couchbase SDKs, where most methods align in all languages/SDKs and the whole API has been made more coherent).
This generation of SDK exposes objects closer to the reality of the Couchbase cluster: Cluster object to connect to the nodes and perform cluster-wide operations, then Bucket to perform data operations.
Spring Data Couchbase 2.x builds on that. In your configuration you'll choose which Bucket to use (see the docs) and as such you'll also be able to inject that Bucket instance if you really need to.
Note that Spring Data Couchbase offers several layers of abstraction on top of the SDK: repositories for CRUD operations around an entity type, then CouchbaseTemplate that offers individually typed operations but is still capable of marshalling to JSON (the SDK is accessible from CouchbaseTemplate).
On the other hand, with the SDK you have to marshall to JSON yourself, either as a JsonObject map-like structure (default) or a String (in which case you need to store and retreive a RawJsonDocument). Working with these Document types is all explained in the SDK's documentation.

Resources