Skip to content

Commit 9188920

Browse files
committed
feat: add JMS module
1 parent 383a4a3 commit 9188920

File tree

26 files changed

+1268
-2
lines changed

26 files changed

+1268
-2
lines changed

api/.env

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,8 @@ PEARL_DB=pearl
55

66
KEYCLOAK_PORT=7080
77
KEYCLOAK_ADMIN_PASSWORD=administrator
8+
9+
IMAGES_REGISTRY_DOCKER_IO=docker.io
10+
IMAGE_ACTIVEMQ=apache/activemq-artemis:2.32.0-alpine
11+
ARTEMIS_USER=insee
12+
ARTEMIS_PASSWORD=lille

api/compose.yml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,18 @@ services:
2525
ports:
2626
- "${KEYCLOAK_PORT}:8080"
2727
volumes:
28-
- ./container/keycloak/realms:/opt/keycloak/data/import
28+
- ./container/keycloak/realms:/opt/keycloak/data/import
29+
activemq:
30+
image: ${IMAGES_REGISTRY_DOCKER_IO:-docker.io}/${IMAGE_ACTIVEMQ:-apache/activemq-artemis:2.32.0-alpine}
31+
environment:
32+
ARTEMIS_USER: ${ARTEMIS_USER:-insee}
33+
ARTEMIS_PASSWORD: ${ARTEMIS_PASSWORD:-lille}
34+
ports:
35+
- "61616:61616"
36+
- "8161:8161"
37+
healthcheck:
38+
test: ["CMD-SHELL", "nc -z localhost 61616 || exit 1"]
39+
interval: 10s
40+
timeout: 5s
41+
retries: 10
42+
start_period: 30s
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package fr.insee.pearljam.infrastructure.db.events;
2+
3+
import com.fasterxml.jackson.databind.node.ObjectNode;
4+
import jakarta.persistence.Column;
5+
import jakarta.persistence.Entity;
6+
import jakarta.persistence.Id;
7+
import jakarta.persistence.Table;
8+
import lombok.Getter;
9+
import lombok.NoArgsConstructor;
10+
import lombok.Setter;
11+
import org.hibernate.annotations.CreationTimestamp;
12+
import org.hibernate.annotations.JdbcTypeCode;
13+
import org.hibernate.type.SqlTypes;
14+
15+
import java.time.LocalDateTime;
16+
import java.util.UUID;
17+
18+
@Entity
19+
@Table(name = "inbox")
20+
@Getter
21+
@Setter
22+
@NoArgsConstructor
23+
public class InboxDB {
24+
@Id
25+
@Column(length = 50)
26+
private UUID id;
27+
28+
@JdbcTypeCode(SqlTypes.JSON)
29+
@Column(columnDefinition = "jsonb")
30+
private ObjectNode payload;
31+
32+
@CreationTimestamp
33+
@Column(name = "created_date", nullable = false, updatable = false)
34+
private LocalDateTime createdDate;
35+
36+
public InboxDB(UUID id, ObjectNode payload) {
37+
super();
38+
this.id = id;
39+
this.payload = payload;
40+
}
41+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package fr.insee.pearljam.infrastructure.db.events;
2+
3+
import org.springframework.data.jpa.repository.JpaRepository;
4+
import org.springframework.data.jpa.repository.Query;
5+
import org.springframework.stereotype.Repository;
6+
7+
import java.util.List;
8+
import java.util.UUID;
9+
10+
@Repository
11+
public interface InboxJpaRepository extends JpaRepository<InboxDB, UUID> {
12+
13+
@Query("SELECT i FROM InboxDB i ORDER BY i.createdDate ASC")
14+
List<InboxDB> findAllOrderByCreatedDate();
15+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
5+
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.4.xsd">
6+
7+
<changeSet id="630_add_inbox_table" author="claude">
8+
<preConditions onFail="MARK_RAN">
9+
<not>
10+
<tableExists tableName="inbox"/>
11+
</not>
12+
</preConditions>
13+
14+
<createTable tableName="inbox">
15+
<column name="id" type="UUID">
16+
<constraints primaryKey="true" nullable="false"/>
17+
</column>
18+
<column name="payload" type="jsonb">
19+
<constraints nullable="true"/>
20+
</column>
21+
<column name="created_date" type="TIMESTAMP">
22+
<constraints nullable="false"/>
23+
</column>
24+
</createTable>
25+
26+
<rollback>
27+
<dropTable tableName="inbox"/>
28+
</rollback>
29+
</changeSet>
30+
31+
</databaseChangeLog>

api/src/main/resources/db/master.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,7 @@
9898

9999
<include file="changelog/621_remove_notnull_panel_contact_history.xml" relativeToChangelogFile="true"/>
100100

101+
<!-- add inbox table for event sourcing -->
102+
<include file="changelog/630_add_inbox_table.xml" relativeToChangelogFile="true"/>
103+
101104
</databaseChangeLog>

listener-jms/.env

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
IMAGES_REGISTRY_DOCKER_IO=docker.io
2+
#IMAGES_REGISTRY_DOCKER_IO=proxy-docker-io.insee.fr
3+
IMAGES_REGISTRY_QUAY_IO=quay.io
4+
#IMAGES_REGISTRY_QUAY_IO=proxy-quay-io.insee.fr
5+
6+
PEARL_DB_USER=mypostgresuser2
7+
PEARL_DB_PASSWORD=mypostgrespassword2
8+
PEARL_DB_PORT=5434
9+
PEARL_DB=queen
10+
11+
KEYCLOAK_PORT=7080
12+
13+
IMAGE_ACTIVEMQ=apache/activemq-artemis:2.32.0-alpine
14+
# Comptes
15+
ARTEMIS_USER=insee
16+
ARTEMIS_PASSWORD=lille

listener-jms/Dockerfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM eclipse-temurin:21-jre-jammy
2+
3+
WORKDIR /opt/app/
4+
COPY ./target/*.jar /opt/app/app.jar
5+
6+
# Setup a non-root user context (security)
7+
RUN groupadd -g 1000 tomcatgroup
8+
RUN useradd -r -u 1000 -g tomcatgroup tomcatuser
9+
RUN mkdir /opt/app/temp-files
10+
RUN chown -R 1000:1000 /opt/app
11+
12+
USER 1000
13+
14+
ENTRYPOINT ["java", "-jar", "/opt/app/app.jar"]
15+

listener-jms/compose.test.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
services:
2+
pearl-db:
3+
image: ${IMAGES_REGISTRY_DOCKER_IO:-docker.io}/${IMAGE_POSTGRES:-postgres:14.15}
4+
environment:
5+
- POSTGRES_USER=${PEARL_DB_USER:-mypostgresuser2}
6+
- POSTGRES_PASSWORD=${PEARL_DB_PASSWORD:-mypostgrespassword2}
7+
- POSTGRES_DB=${PEARL_DB:-pearl}
8+
command: ["postgres"]
9+
healthcheck:
10+
test: ["CMD-SHELL", "pg_isready -U ${PEARL_DB_USER:-mypostgresuser2} -d ${PEARL_DB:-queen} -h localhost"]
11+
interval: 5s
12+
timeout: 10s
13+
retries: 10
14+
ports:
15+
- "${QUEEN_DB_PORT:-5434}:5432"
16+
17+
activemq:
18+
image: ${IMAGES_REGISTRY_DOCKER_IO:-docker.io}/${IMAGE_ACTIVEMQ:-apache/activemq-artemis:2.32.0-alpine}
19+
environment:
20+
ARTEMIS_USER: ${ARTEMIS_USER:-insee}
21+
ARTEMIS_PASSWORD: ${ARTEMIS_PASSWORD:-lille}
22+
ports:
23+
- "61616:61616"
24+
- "8161:8161"

listener-jms/compose.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#----------------------------------------------------------------------------
2+
# (\___/) (\_(\
3+
# (='.'=) (=':') Conteneurisation
4+
# (")_(") (,(")(")
5+
#
6+
# Commandes :
7+
# PODMAN INSEE
8+
# - podman --log-level=debug compose -f compose.yml --env-file .env --project-name queen-listener-jms --profile all up -d
9+
# - podman --log-level=debug compose -f compose.yml --env-file .env --project-name queen-listener-jms --profile activemq up -d
10+
# - podman --log-level=debug compose -f compose.yml --env-file .env --project-name queen-listener-jms --profile all down
11+
# - podman --log-level=debug compose -f compose.yml --env-file .env --project-name queen-listener-jms --profile activemq down
12+
13+
# mvn clean verify -Pcoverage --no-transfer-progress -Dspring.docker.compose.enabled=false
14+
15+
# mvn test -Dspring.docker.compose.enabled=false
16+
17+
# podman --log-level=debug compose -f compose.yml --env-file .env --project-name queen-back-office --profile all up -d
18+
19+
x-activemq-volumes: &activemq-volumes
20+
- activemq_vol:/data/activemq
21+
- activemq_vol:/var/log/activemq
22+
- ./containers/activemq/broker.xml:/var/lib/artemis-instance/etc-override/broker.xml
23+
24+
services:
25+
26+
activemq:
27+
container_name: activemq
28+
image: ${IMAGES_REGISTRY_DOCKER_IO}/${IMAGE_ACTIVEMQ}
29+
profiles:
30+
- all
31+
- activemq
32+
environment:
33+
ARTEMIS_USER: ${ARTEMIS_USER}
34+
ARTEMIS_PASSWORD: ${ARTEMIS_PASSWORD}
35+
volumes: *activemq-volumes
36+
ports:
37+
- "61616:61616"
38+
- "8161:8161"
39+
40+
pearl-db:
41+
image: postgres:14.15
42+
profiles:
43+
- all
44+
- pearl-db
45+
environment:
46+
- POSTGRES_USER=${PEARL_DB_USER}
47+
- POSTGRES_PASSWORD=${PEARL_DB_PASSWORD}
48+
- POSTGRES_DB=${PEARL_DB}
49+
command: ["postgres"]
50+
healthcheck:
51+
test: ["CMD-SHELL", "pg_isready -U ${PEARL_DB_USER} -d ${PEARL_DB} -h localhost"]
52+
interval: 5s
53+
timeout: 10s
54+
retries: 10
55+
ports:
56+
- ${PEARL_DB_PORT}:5432
57+
58+
volumes:
59+
activemq_vol:

0 commit comments

Comments
 (0)