Skip to content

Instantly share code, notes, and snippets.

View sheelprabhakar's full-sized avatar
🎯
Focusing

SHEEL SINDHU PRABHAKAR sheelprabhakar

🎯
Focusing
View GitHub Profile
@sheelprabhakar
sheelprabhakar / KafkaStreamConfig.java
Last active March 9, 2021 15:28
Kafka springboot stream config
@Configuration
@EnableKafka
@EnableKafkaStreams
public class KafkaStreamConfig {
@Value("${kafka.bootstrapAddress}")
private String bootstrapAddress;
@Value("${kafka.groupId}")
private String groupId;
@sheelprabhakar
sheelprabhakar / Application.java
Created March 6, 2021 05:39
Spring boot application with KafkaListener
@SpringBootApplication
@EnableScheduling
public class Application {
@Autowired
private WeatherLogService weatherLogService;
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@sheelprabhakar
sheelprabhakar / WeatherLogServiceImpl.java
Last active March 6, 2021 05:36
Spring boot service
@Service
public class WeatherLogServiceImpl implements WeatherLogService {
private final WeatherRepository repository;
@Autowired
WeatherLogServiceImpl(final WeatherRepository repository) {
this.repository = repository;
}
@Override
public void saveLogs(WeatherLog log) throws InterruptedException {
@sheelprabhakar
sheelprabhakar / KafkaConsumerConfig.java
Last active March 6, 2021 09:09
Spring boot kafka consumer config
@Configuration
@EnableKafka
public class KafkaConsumerConfig {
@Value( "${kafka.bootstrapAddress}" )
private String bootstrapAddress;
@Value( "${kafka.groupId}" )
private String groupId;
@Bean
@sheelprabhakar
sheelprabhakar / db.sql
Last active March 6, 2021 05:22
Postgreas partioned table sample script
CREATE TABLE weather.log
(
city character varying(255) COLLATE pg_catalog."default" NOT NULL,
latitude double precision NOT NULL,
longitude double precision NOT NULL,
temp double precision NOT NULL,
logdate date NOT NULL,
id integer NOT NULL
) PARTITION BY RANGE (logdate);
@sheelprabhakar
sheelprabhakar / Application.java
Last active March 6, 2021 05:12
Spring boot application to execute a task every hour
@SpringBootApplication
@EnableScheduling
public class Application {
@Autowired
private WeatherAgentService weatherAgentService;
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@sheelprabhakar
sheelprabhakar / WeatherAgentServiceImpl.java
Created March 6, 2021 05:08
Spring service to generate simulation data for cities temprature
@Service
public class WeatherAgentServiceImpl implements WeatherAgentService {
private final CityRepository cityRepository;
private final ExecutorService executor;
private final KafkaTemplate<String, WeatherInfo> kafkaTemplate;
private final Random rand = new Random();
private final int min = -20;
private final int max = 50;
@Autowired
public WeatherAgentServiceImpl(CityRepository cityRepository, KafkaTemplate<String, WeatherInfo> kafkaTemplate) {
@sheelprabhakar
sheelprabhakar / KafkaProducerConfig.java
Created March 6, 2021 05:01
Kafka Spring config for producer
@Configuration
public class KafkaProducerConfig {
@Value( "${kafka.bootstrapAddress}" )
private String bootstrapAddress;
@Bean
public ProducerFactory<String, WeatherInfo> producerFactory() {
Map<String, Object> configProps = new HashMap<>();
configProps.put(
ProducerConfig.BOOTSTRAP_SERVERS_CONFIG,
@sheelprabhakar
sheelprabhakar / KafkaTopicConfig.java
Last active March 6, 2021 04:55
Spring config for Kafka Topic
@Configuration
public class KafkaTopicConfig {
@Value("${kafka.bootstrapAddress}")
private String bootstrapAddress;
@Bean
public KafkaAdmin kafkaAdmin() {
Map<String, Object> configs = new HashMap<>();
configs.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapAddress);