How to set preferredLocation for cosmosDB in application.properties for Springboot app? - spring

cosmos DB has multi master set up with multiple regions. cosmos connection parameters are present in application.properties.
But my observation is, when we use CosmosRepository interface and use getById method,the call goes to any random region and not the preferred region.this is adding latency.
How to correctly setup preferred location / region in application.properties?
"preferredLocation" property seems to be not working.

Related

Spring boot Redis cache TTL property change on the fly

is it possible to change the TTL property of Redis cache during the runtime if the same property has been changed in app config server? is there a way to automate the process to refresh the Redis instance properties during runtime on the event of config server change?
If you want to get the latest property in Config Server, it is recommended to do it through the client polling method, which can be found at
https://learn.microsoft.com/en-us/azure/spring-apps/how-to-config-server#config-server-refresh
Regarding the load to Redis instances, you may need to write some code to send out the event.

Keyspaces in same cassandra cluster with different passwords

I am connecting to two different keyspaces with different credentials. These keyspaces are in the same cluster.
Currently, I am needing to create two different cluster beans in my spring boot app to achieve this as the credentials are set in the cluster. Credentials are not set in the session object.
For this scenario is it right to have two separate cluster beans? Can I avoid making two different cluster beans?
In Cassandra there is no such things as a password on the keyspace. Password is set for a user that has some roles, and then this role is given particular access to the keyspace - modify, read, etc. So to have different access rights to different keyspaces, you need to have different users, and to connect as different user from the same application, you need to have different Cluster objects for every user (except the case if you're using DSE with DSE Java driver, where you can have so-called proxy user).
You can have a single spring Cassandra Cluster bean and create a two separate session beans by using the single cluster bean and by setting the corresponding key space while creating the session beans. A sample implementation from spring data docs

How can Spring JPA use two different database connections for read and write operations?

we use in our backend AWS Aurora which has two instances, one for read+write-access and one only for read access.
In our backend we use Spring data JPA to manage our Entities in the database. Would it now be possible, that spring will use the read node for selecting data and the read/write node only for write operations?
How could we configure that? Therefore the read instance has another hostname this instance do nothing.
Thx.

Spring Cloud Connector Plan Information

I am using Spring Cloud Connector to bind to databases. Is there any way to get the plan of the bound service? When I extend an AbstractCloudConfig and do
cloud().getSingletonServiceInfosByType(PostgresqlServiceInfo.class)...
I will have information on the url and how to connect to the postgres. PostgresqlServiceInfo and others do not carry along the plan data. How can I extend the service info, in order to read this information form VCAP_SERVICES?
Thanks
By design, the ServiceInfo classes in Spring Cloud Connectors carry just enough information to create the connection beans necessary for an app to consume the service resources. Connectors was designed to be platform-neutral, and fields like plan, label, and tags that are available on Cloud Foundry are not captured because they might not be available on other platforms (e.g. Heroku).
To add the plan information to a ServiceInfo, you'd need to write your own ServiceInfo class that includes a field for the value, then write a CloudFoundryServiceInfoCreator to populate the value from the VCAP_SERVICES data that the framework provides as a Map. See the project documentation for more information on creating such an extension.
Another (likely easier) option is to use the newer java-cfenv project instead of Spring Cloud Connectors. java-cfenv supports Cloud Foundry only, and gives access to the full set of information in VCAP_SERVICES. See the project documentation for an example of how you can use this library.

Autoscaling up in Mongo with Spring Boot

I am setting up an application connecting to mongoDB with high availability.
I have studied the documentation and setup the replica set successfully through
spring.data.mongodb.uri=mongodb://user:secret#mongo1.example.com:12345,mongo2.example.com:23456/test
As the application property file is fixed, the application is required to restart if I change the spring.data.mongodb.uri.
What if I have a new replica member in mongo, should I need to restart my application with the update in application property?
Or, is it fair enough to use the old configuration? Mongo driver will automatically connect to the new replica member for me with the old configuration.
If you are loading properties from the file you need to restart the application once the property is updated.
Otherwise, you need to use some global property management apps like consul which when the properties are changed it will reload the properties value in the application(#RefreshScope).
In your case, once the property is changed you need to disconnect and reconnect to the mongodb by code.

Resources