feat: The chats are stored as local json-files
[demos/kafka/chat] / src / main / java / de / juplo / kafka / chat / backend / ChatBackendApplication.java
1 package de.juplo.kafka.chat.backend;
2
3 import de.juplo.kafka.chat.backend.domain.ChatHome;
4 import de.juplo.kafka.chat.backend.persistence.StorageStrategy;
5 import jakarta.annotation.PreDestroy;
6 import org.springframework.beans.factory.annotation.Autowired;
7 import org.springframework.boot.SpringApplication;
8 import org.springframework.boot.autoconfigure.SpringBootApplication;
9 import org.springframework.context.annotation.Bean;
10 import reactor.core.publisher.Flux;
11
12
13 @SpringBootApplication
14 public class ChatBackendApplication
15 {
16         @Autowired
17         ChatHome chatHome;
18         @Autowired
19         StorageStrategy storageStrategy;
20
21         @PreDestroy
22         public void onExit()
23         {
24                 storageStrategy.writeChatrooms(Flux.fromIterable(chatHome.list()));
25         }
26
27         public static void main(String[] args)
28         {
29                 SpringApplication.run(ChatBackendApplication.class, args);
30         }
31 }