fix(build): switch from uber-jar to fast-jar for Docker compatibility
- Change quarkus.package.type from uber-jar to fast-jar - Add EventShare entity and migration for share tracking - Add establishment capacity field - Improve event and establishment services - Add comprehensive tests Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -18,7 +18,10 @@ import org.eclipse.microprofile.reactive.messaging.Channel;
|
||||
import org.eclipse.microprofile.reactive.messaging.Emitter;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.transaction.Status;
|
||||
import jakarta.transaction.Synchronization;
|
||||
import jakarta.transaction.Transactional;
|
||||
import jakarta.transaction.TransactionManager;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
@@ -46,8 +49,38 @@ public class FriendshipService {
|
||||
@Channel("notifications")
|
||||
Emitter<NotificationEvent> notificationEmitter; // v2.0 - Publie dans Kafka
|
||||
|
||||
@Inject
|
||||
TransactionManager transactionManager;
|
||||
|
||||
private static final Logger logger = Logger.getLogger(FriendshipService.class);
|
||||
|
||||
/**
|
||||
* Envoie un événement Kafka après le commit de la transaction courante.
|
||||
* Évite "Commit invoked while multiple threads active" quand Kafka publie sur un autre thread.
|
||||
*/
|
||||
private void sendToKafkaAfterCommit(NotificationEvent event) {
|
||||
try {
|
||||
transactionManager.getTransaction().registerSynchronization(new Synchronization() {
|
||||
@Override
|
||||
public void beforeCompletion() {}
|
||||
|
||||
@Override
|
||||
public void afterCompletion(int status) {
|
||||
if (status == Status.STATUS_COMMITTED) {
|
||||
try {
|
||||
notificationEmitter.send(event);
|
||||
logger.info("[LOG] Événement publié dans Kafka après commit pour : " + event.getUserId());
|
||||
} catch (Exception e) {
|
||||
logger.error("[ERROR] Publication Kafka après commit : " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
logger.error("[ERROR] Enregistrement synchronisation JTA : " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Envoie une demande d'amitié entre deux utilisateurs.
|
||||
*
|
||||
@@ -105,26 +138,22 @@ public class FriendshipService {
|
||||
logger.error("[ERROR] Erreur création notification demande d'amitié : " + e.getMessage());
|
||||
}
|
||||
|
||||
// TEMPS RÉEL: Publier dans Kafka (v2.0)
|
||||
// TEMPS RÉEL: Publier dans Kafka après commit (évite "multiple threads active" JTA)
|
||||
try {
|
||||
Map<String, Object> notificationData = new HashMap<>();
|
||||
notificationData.put("requestId", friendship.getId().toString());
|
||||
notificationData.put("senderId", user.getId().toString());
|
||||
// v2.0 - Utiliser les nouveaux noms de champs
|
||||
notificationData.put("senderName", user.getFirstName() + " " + user.getLastName());
|
||||
notificationData.put("senderProfileImage", user.getProfileImageUrl() != null ? user.getProfileImageUrl() : "");
|
||||
|
||||
NotificationEvent event = new NotificationEvent(
|
||||
friend.getId().toString(), // userId destinataire (clé Kafka)
|
||||
friend.getId().toString(),
|
||||
"friend_request_received",
|
||||
notificationData
|
||||
);
|
||||
|
||||
notificationEmitter.send(event);
|
||||
logger.info("[LOG] Événement friend_request_received publié dans Kafka pour : " + friend.getId());
|
||||
sendToKafkaAfterCommit(event);
|
||||
} catch (Exception e) {
|
||||
logger.error("[ERROR] Erreur lors de la publication dans Kafka : " + e.getMessage(), e);
|
||||
// Ne pas bloquer la demande d'amitié si Kafka échoue
|
||||
logger.error("[ERROR] Préparation publication Kafka : " + e.getMessage(), e);
|
||||
}
|
||||
|
||||
logger.info("[LOG] Demande d'amitié envoyée avec succès.");
|
||||
@@ -168,30 +197,20 @@ public class FriendshipService {
|
||||
// Log de succès
|
||||
logger.info(String.format("[LOG] Demande d'amitié acceptée avec succès pour l'ID: %s", friendshipId)); // Correctement formaté
|
||||
|
||||
// TEMPS RÉEL: Publier dans Kafka (v2.0)
|
||||
// TEMPS RÉEL: Publier dans Kafka après commit
|
||||
try {
|
||||
Users user = friendship.getUser();
|
||||
Users friend = friendship.getFriend();
|
||||
// v2.0 - Utiliser les nouveaux noms de champs
|
||||
String friendName = friend.getFirstName() + " " + friend.getLastName();
|
||||
|
||||
Map<String, Object> notificationData = new HashMap<>();
|
||||
notificationData.put("acceptedBy", friendName);
|
||||
notificationData.put("friendshipId", friendshipId.toString());
|
||||
notificationData.put("accepterId", friend.getId().toString());
|
||||
notificationData.put("accepterProfileImage", friend.getProfileImageUrl() != null ? friend.getProfileImageUrl() : "");
|
||||
|
||||
NotificationEvent event = new NotificationEvent(
|
||||
user.getId().toString(), // userId émetteur (destinataire de la notification)
|
||||
"friend_request_accepted",
|
||||
notificationData
|
||||
);
|
||||
|
||||
notificationEmitter.send(event);
|
||||
logger.info("[LOG] Événement friend_request_accepted publié dans Kafka pour : " + user.getId());
|
||||
NotificationEvent event = new NotificationEvent(user.getId().toString(), "friend_request_accepted", notificationData);
|
||||
sendToKafkaAfterCommit(event);
|
||||
} catch (Exception e) {
|
||||
logger.error("[ERROR] Erreur lors de la publication dans Kafka : " + e.getMessage(), e);
|
||||
// Ne pas bloquer l'acceptation si Kafka échoue
|
||||
logger.error("[ERROR] Préparation publication Kafka : " + e.getMessage(), e);
|
||||
}
|
||||
|
||||
// Créer des notifications pour les deux utilisateurs
|
||||
@@ -246,25 +265,16 @@ public class FriendshipService {
|
||||
friendship.setStatus(FriendshipStatus.REJECTED);
|
||||
friendshipRepository.persist(friendship);
|
||||
|
||||
// TEMPS RÉEL: Publier dans Kafka (v2.0)
|
||||
// TEMPS RÉEL: Publier dans Kafka après commit
|
||||
try {
|
||||
Users user = friendship.getUser();
|
||||
|
||||
Map<String, Object> notificationData = new HashMap<>();
|
||||
notificationData.put("friendshipId", friendshipId.toString());
|
||||
notificationData.put("rejectedAt", System.currentTimeMillis());
|
||||
|
||||
NotificationEvent event = new NotificationEvent(
|
||||
user.getId().toString(), // userId émetteur (destinataire de la notification)
|
||||
"friend_request_rejected",
|
||||
notificationData
|
||||
);
|
||||
|
||||
notificationEmitter.send(event);
|
||||
logger.info("[LOG] Événement friend_request_rejected publié dans Kafka pour : " + user.getId());
|
||||
NotificationEvent event = new NotificationEvent(user.getId().toString(), "friend_request_rejected", notificationData);
|
||||
sendToKafkaAfterCommit(event);
|
||||
} catch (Exception e) {
|
||||
logger.error("[ERROR] Erreur lors de la publication dans Kafka : " + e.getMessage(), e);
|
||||
// Ne pas bloquer le rejet si Kafka échoue
|
||||
logger.error("[ERROR] Préparation publication Kafka : " + e.getMessage(), e);
|
||||
}
|
||||
|
||||
logger.info("[LOG] Demande d'amitié rejetée.");
|
||||
|
||||
Reference in New Issue
Block a user