diff --git a/src/main/java/com/security/events/notification/CreatedUserEvent.java b/src/main/java/com/security/events/notification/CreatedUserEvent.java index 606f407..901d93b 100644 --- a/src/main/java/com/security/events/notification/CreatedUserEvent.java +++ b/src/main/java/com/security/events/notification/CreatedUserEvent.java @@ -6,6 +6,7 @@ public record CreatedUserEvent( String lastName, String dni, String phone, + String email, String profileImageUrl ) { } diff --git a/src/main/java/com/security/services/Impl/AuthServiceImpl.java b/src/main/java/com/security/services/Impl/AuthServiceImpl.java index f7a4bf8..790aa9a 100644 --- a/src/main/java/com/security/services/Impl/AuthServiceImpl.java +++ b/src/main/java/com/security/services/Impl/AuthServiceImpl.java @@ -196,6 +196,7 @@ public LoginResponseDTO registerUser(RegisterRequestDto registerRequestDto) { registerRequestDto.lastName(), registerRequestDto.dni(), registerRequestDto.phone(), + registerRequestDto.email(), null ); diff --git a/src/main/java/com/security/services/Impl/NotificationServiceImpl.java b/src/main/java/com/security/services/Impl/NotificationServiceImpl.java index e20de32..995d82c 100644 --- a/src/main/java/com/security/services/Impl/NotificationServiceImpl.java +++ b/src/main/java/com/security/services/Impl/NotificationServiceImpl.java @@ -4,9 +4,12 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.kafka.core.KafkaTemplate; +import org.springframework.kafka.support.SendResult; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.concurrent.CompletableFuture; + @Service @Slf4j @RequiredArgsConstructor @@ -15,10 +18,26 @@ public class NotificationServiceImpl { @Transactional public void sendNotification(String message) { - log.info("Antes de publicar el mensaje"); - NotificationEvent event = new NotificationEvent(message); - kafkaTemplate.send("user-created-event-topic", event); - log.info("Mensaje enviado {}", event); - } + try { + log.info("Enviando notificación: {}", message); + NotificationEvent event = new NotificationEvent(message); + + // Envío asíncrono con callback + CompletableFuture> future = + kafkaTemplate.send("user-created-event-topic", event); -} + future.whenComplete((result, exception) -> { + if (exception == null) { + log.info("✅ Notificación enviada exitosamente: offset={}", + result.getRecordMetadata().offset()); + } else { + log.error("❌ Error enviando notificación", exception); + } + }); + + } catch (Exception e) { + log.error("❌ Error en sendNotification", e); + throw e; + } + } +} \ No newline at end of file diff --git a/src/main/java/com/security/services/oauth2/CustomOAuth2UserService.java b/src/main/java/com/security/services/oauth2/CustomOAuth2UserService.java index 0fe8509..1d7077b 100644 --- a/src/main/java/com/security/services/oauth2/CustomOAuth2UserService.java +++ b/src/main/java/com/security/services/oauth2/CustomOAuth2UserService.java @@ -146,6 +146,7 @@ private void publishUserCreatedEvent(UserEntity user, OAuth2UserInfo userInfo) { userInfo.getLastName(), null, null, + userInfo.getEmail(), userInfo.getProfileImageUrl() ); @@ -160,6 +161,7 @@ private void publishUserUpdateEvent(UserEntity user, OAuth2UserInfo userInfo) { userInfo.getLastName(), null, null, + userInfo.getEmail(), userInfo.getProfileImageUrl() );