Specify multiple cassandra port in application properties - spring

I have following application.properties:
spring.data.cassandra.contact-points=localhost
spring.data.cassandra.port=1112
In our information system 2 accessible ** cassandra nodes** (one redirection is done on my laptop on localhost:1112 and localhost:1113)
My question is: How I can in application.properties, specify 2 differents host/port ? Because I already use
spring.data.cassandra.contact-points=localhost:1112,localhost:1113
With different port and it doesn't work

As noted in the spring data documentation, have you tried:
cassandra.contactpoints=10.1.55.80:9042,10.1.55.81:9042
cassandra.keyspace=showcase
*You'll probably still need to prefix it with spring.data

Related

deprecated property: connection-timeout: 12000

I have this property into Spring Boot application:
server:
connection-timeout: 12000
I get warning:
Deprecated Each server behaves differently. Use server specific properties instead.
Gradle: org.springframework.boot:spring-boot-autoconfigure:2.6.8 (spring-boot-autoconfigure-2.6.8.jar)
is there some better configuration property that I can use?
I don't even know why you receive a deprecated warning.
According to the documentation from Spring Boot version 2.3 and onwards this property is removed not deprecated any more.
As you can read here, there are some other properties which you can use instead depending on the server that runs your spring boot application.
server.tomcat.connection-timeout should be used if you have tomcat as running server.
server.netty.connection-timeout should be used if netty is used.
server.jetty.connection-idle-timeout should be used if jetty is used
Basically each server has it's own implementation, so you must read your server's documentation to see what it allows and how this behaves. There might be slight differences from how one server behaves and how it interprets connection-timeout and how another server behave and interprets a similar configuration.
This is I think the reason that Spring decides to move to server specific configuration on property connection-timeout instead of a general property and also a very important reason was that some servers may not even have this configuration available to them. So then you have a general property configured in your spring boot application which the server that runs the application can't even respect.
Therefore you now have specific properties for specific servers and now you can be sure upfront whether this configuration is available in your server and you can also read the server documentation to understand exactly what the behavior will be.
Although this setting is being deprecated, we still can use the timeout function.
According to official document, we can use #Transactional(timeout = 1) to do the track in the controller
https://www.baeldung.com/spring-rest-timeout

Shared Config Between SOME Spring Boot Services

This question is similar to (but different in the aim): Shared Config(at git) between SPring Boot Services so I will make use of the example the OP wrote there.
In my case I am using Spring Cloud Config Server with the Vault as backend, but for the sake of argument I will describe it as if it were in git. So imagine I have 4 Services: A, B, C and D.
And I have the following configs:
- A-prod.properties
- A-dev.properties
- B-prod.properties
- B-dev.properties
- C-prod.properties
- C-dev.properties
- D-prod.properties
- D-dev.properties
- application-prod.properties
- application-dev.properties
Now according to the docs I will have one of the services, let's say Service C getting his properties from C-(ENV).properties as well as application-(ENV).properties. Similarly the same with the others, i.e. everyone gets their own file and everything on application.properties.
My question is:
Is it possible to have for example a "semi-global" shared properties, e.g. a file that A and C share some config and another that B and D share some config?
An usage example would be DB Connection Credentials, where two services make use of one set of credentials, and the others another one.
I have been trying to find infos about this and doing some tests, but nothing that got me anywhere...
Unfortunately, it's not possible to achieve what you want. The only way to share properties is by using the application.properties(yml) file which is merged to every other configuration file.

application.properties configuration for distributed database pattern

I am trying to develop a microservice by using sprin and spring boot with postgresql database. I am here using distributted datbase. So for particular region I am using one DB, and for other region I am using different DB. Currently I only tried with one database. I added datasource name , username and password in application.properties.
Here my doubt is that, if I am using multiple distributed database, how cam mention different DB source URL in configuration (application.properties)? I am using following structure to use one database currently,
spring.datasource.url=jdbc:postgresql://localhost/milleTech_users
spring.datasource.username=postgres
spring.datasource.password=postgresql
spring.jpa.generate-ddl=true
Like above.
So if I am using multiple DB for multiple region How I can give configuration conditionally here? I am new to microservice world and distributed database design pattern.
Multiple Database details cannot be managed within a single application.properties.
Consider using Spring Cloud Config where in you can create multiple application.properties with different profile names for every application.
In your case, the profile names could reflect the region. When you deploy to a particular region, launch the app with that profile name so that the required config would be loaded and appropriate database connection would be used
Edit :
Also in your case, if you can set environment variables, you can explore on the following option mentioned in this thread

spring boot: create multiple context for the same application-context.xml

I need to create multiple context for the same application context.xml file and each context use its own application.properties.
How to do it using spring boot ?
I have 3 clients who have the same behaviour but each one with specific details declared into client-application.properties.
So i use also spring integration and the flow will be reused for each client .
I need to launch 3 clients in the same time and each one with its own application.properties. And i use xml for that.
Take a look at this... I have a single project, and inside of it are three application.properties (or the number you need)
in application.properties, i specify general parameters
and in each application-.properties i specify specific environment properties, e.g., the port in production:
And the port for my dev profile:
In order to use them check the documentation that Ivaylo recommended
...A small example:
In this case, the application will boot on the port showed in the different .properties files.
You can specify the profile like: mvn spring:boot run -Dspring.profiles.active=dev

Spring cloud config server - more than 1 properties file per app

Does anybody knows if it is possible to expose more than 1 property file per application in Spring Cloud config server?
For example I would like to have defined in my git repo properties for the same app, but in different files:
myapp-customer-services.yml
myapp-products-services.yml
and have all those properties defined inside the files, exposed under "myapp".
No that's not possible currently. I'm not sure it really makes much sense to be honest, since you can easily clearly delineate different sets of properties within a YAML file using separate documents.
Yes it is possible to expose more than 1 property file per application in Spring Cloud config server
You can access it in you client by using following properties
first specify profile which you want
example
myapp-customer.yml
myapp-products.yml
spring.profiles.active=customer,products
spring.cloud.config.name=myapp

Resources