I have a java application that uses aws kinesis stream.
In the application, I get the student data in real time via kinesis stream and I have to make some action depending on the student id.
There is a list of students that I need to query from the database, and the each student from kinesis stream needs a checking if the student is in the list or not.
However I would like to query the list of students to the database only once, because that is one of the requirements.
On top of that I would like to make the query as soon as the application starts; that way if the query fails we can also fail the application. In other words, if the query does not succeed the application should not run.
This is what I would like to do
@SpringBootApplication
@EnabledScheduling
@EnableCaching
@Configuration
class Application implements CommandLineRuner {
@Autowired
RestTemplate restTemplate
@Autowired
List<Student> students
static void main(String[] args) {
SpringApplication app = new SpringApplication(Application);
app.webApplicationType = WebApplicationType.NONE;
app.run(args)
}
@Overrde
void run(String... args) thows Exception {
try {
// make a request
List<Student> people = this.restTemplate.exchange("https://some.url.com", ...other params)
this.students = people
// running kcl worker
KclConsumer.kclWorker.run()
} catch (Exception ex) {
....
}
}
}
@Service
class SomeService {
@Autowired
RestTemplate restTemplate
@Autowired
List<Student> students
void func(Student id) {
this.students.each {
if(id == it.id) {
println("found you")
return;
}
}
println("not found")
}
}
I have tried creating the bean and share across the project as following but it does not seem to work...
class SomeConfig {
@Bean
List<Student> students() {
return new ArrayList<>();
}
}
I am guess how I am using bean is wrong. Can someone help me with my code please? Thank you in advance