Skip to content
Snippets Groups Projects
Verified Commit 6c649138 authored by Jan Kožusznik's avatar Jan Kožusznik
Browse files

Listener

Resolves: #
parent 33d2f87d
Branches
No related merge requests found
Pipeline #2796 failed with stages
# 📚 Bookworm Library
Jednoduchá Java aplikace pro správu knihovny – REST API, frontend a event-driven architektura pomocí Spring Boot a JMS (ActiveMQ Artemis).
---
## 🚀 Funkce
- ✅ Přidání knihy (REST + GUI)
- ✅ Půjčení a vrácení knihy
- ✅ Zobrazení seznamu knih (Thymeleaf)
- ✅ Event-driven reakce na vytvoření knihy
- ✅ In-memory databáze (H2)
- ✅ Embedded JMS (ActiveMQ Artemis)
- ✅ Swagger dokumentace
---
## 🔧 Technologie
- Java 21
- Spring Boot 3.2+
- Spring Web, JPA, Thymeleaf, JMS
- H2 database
- Mockito, JUnit 5
---
## ▶️ Jak aplikaci spustit
1. **Klonuj nebo rozbal projekt**
2. Ujisti se, že máš Javu 21+
3. V root složce spusť:
```bash
./mvnw spring-boot:run
\ No newline at end of file
......@@ -64,16 +64,7 @@
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-activemq</artifactId>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-broker</artifactId>
<version>5.17.6</version> <!-- aktuální verze k dubnu 2025 -->
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
......
package com.example.library;
public interface BookEventListener {
void onBookCreated(Book book);
}
package com.example.library;
public interface BookEventRegistry {
void registerListener(BookEventListener listener);
}
package com.example.library;
import jakarta.annotation.PostConstruct;
import org.springframework.stereotype.Service;
@Service
public class BookEventService {
private final BookEventRegistry registry;
public BookEventService(BookEventRegistry registry) {
this.registry = registry;
}
@PostConstruct
public void register() {
registry.registerListener(book -> {
// např. logika ukládání do DB
System.out.println("Book created: " + book.getTitle());
});
}
}
package com.example.library;
import jakarta.jms.Queue;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.stereotype.Service;
@Service
public class BookSender {
private final JmsTemplate jmsTemplate;
private final Queue bookQueue;
public BookSender(JmsTemplate jmsTemplate, Queue bookQueue) {
this.jmsTemplate = jmsTemplate;
this.bookQueue = bookQueue;
}
public void sendBook(Book book) {
jmsTemplate.convertAndSend(bookQueue, book);
}
}
\ No newline at end of file
package com.example.library;
import org.springframework.stereotype.Service;
@Service
public class BookeEventRegistryImpl implements BookEventRegistry {
@Override
public void registerListener(BookEventListener listener) {
}
}
package com.example.library.config;
import jakarta.jms.Queue;
import org.apache.activemq.command.ActiveMQQueue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class JmsConfig {
@Bean
public Queue bookQueue() {
return new ActiveMQQueue("bookQueue");
}
}
......@@ -5,4 +5,5 @@ spring.datasource.driver-class-name=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=
spring.jpa.hibernate.ddl-auto=update
spring.h2.console.enabled=true
\ No newline at end of file
spring.h2.console.enabled=true
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment