Skip to content

Commit

Permalink
mail is send via kafka
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc Gorzala committed Dec 27, 2023
1 parent e323caa commit 2d3b4b5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
import jakarta.transaction.Transactional;
import lombok.RequiredArgsConstructor;
import net.dancier.dancer.core.ScheduleMessagePort;
import net.dancier.dancer.mail.model.DancierMailMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

import java.net.URI;
import java.util.UUID;

@Component
@RequiredArgsConstructor
Expand All @@ -20,7 +22,16 @@ public class ApplicationEventListener {
private final ScheduleMessagePort scheduleMessagePort;

@EventListener
@Transactional
public void handle(DancierMailMessage dancierMailMessage) {
scheduleMessagePort.schedule(
dancierMailMessage,
UUID.randomUUID().toString(),
SOURCE,
"email-sending-requested"
);
}

@EventListener
public void handle(ProfileUpdatedEvent profileUpdatedEvent) {
log.info("Got a Profile Change: {}", profileUpdatedEvent);
scheduleMessagePort.schedule(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.dancier.dancer.mail.model.OutgoingMailStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.stereotype.Component;

Expand All @@ -18,12 +19,15 @@ public class MailEnqueueService {

private final OutgoingMailRepository outgoingMailRepository;

private final ApplicationEventPublisher applicationEventPublisher;

public void enqueueMail(DancierMailMessage dancierMailMessage) {
OutgoingMail outgoingMail = new OutgoingMail();
outgoingMail.setStatus(OutgoingMailStatus.QUEUED);
outgoingMail.setRetry(0);
outgoingMail.setMail(dancierMailMessage);
this.outgoingMailRepository.save(outgoingMail);
applicationEventPublisher.publishEvent(dancierMailMessage);
}

}

0 comments on commit 2d3b4b5

Please sign in to comment.