Setting up database and adding other required configurations

All dependent service host urls and API endpoints should be added in application.properties. Along with it whatever properties can be overwritten during deployment should be part of this file(eg: DB url and passwords,Kafka server properties, control knobs for functionalities  etc.). To remove boilerplate code for referring variables from application.properties, we create a configuration file and autowire this configuration file wherever we need to refer to these variables. Following properties should be added for configuring database and kafka server( Use the default values, in case you want to tune kafka server that can be overwritten during deployment).

Once all the external dependencies have been added to pom.xml and these maven changes have been reloaded, the following properties should be added to application.properties file to configure database and kafka for development -

#DATABASE CONFIGURATION spring.datasource.driver-class-name=org.postgresql.Driver spring.datasource.url=jdbc:postgresql://localhost:5432/postgres spring.datasource.username=postgres spring.datasource.password=postgres

 

Kafka Configuration properties -

# KAFKA SERVER CONFIGURATIONS kafka.config.bootstrap_server_config=localhost:9092 spring.kafka.consumer.value-deserializer=org.egov.tracer.kafka.deserializer.HashMapDeserializer spring.kafka.consumer.key-deserializer=org.apache.kafka.common.serialization.StringDeserializer spring.kafka.consumer.group-id={PLACEHOLDER_PUT_KAFKA_CONSUMER_NAME} spring.kafka.producer.key-serializer=org.apache.kafka.common.serialization.StringSerializer spring.kafka.producer.value-serializer=org.springframework.kafka.support.serializer.JsonSerializer spring.kafka.listener.missing-topics-fatal=false spring.kafka.consumer.properties.spring.json.use.type.headers=false # KAFKA CONSUMER CONFIGURATIONS kafka.consumer.config.auto_commit=true kafka.consumer.config.auto_commit_interval=100 kafka.consumer.config.session_timeout=15000 kafka.consumer.config.auto_offset_reset=earliest # KAFKA PRODUCER CONFIGURATIONS kafka.producer.config.retries_config=0 kafka.producer.config.batch_size_config=16384 kafka.producer.config.linger_ms_config=1 kafka.producer.config.buffer_memory_config=33554432

 

To add custom properties in application.properties file and then referencing them in your application -