首页 > 解决方案 > 使用 Kafka 和 Spring Boot 进行电子邮件/通知调度

问题描述

我正在开发一个订阅系统,其中有 2 个微服务:

我想做的是每天上午 12 点为每个订阅在 1 周后到期的客户发送电子邮件和短信。

我现在将向您描述我的推理:

@Component
public class StoreSubscriptionExpirationReminder {

    @Scheduled(cron="0 0 12 1/1 * ? *",zone = "Europe/Paris")
    public void execute() {

        List<StoreSubscription> storeSubscriptions = subscriptionRepository.findAllByExpirationDate(LocalDate.now().plusMonths(1));

        storeSubscriptions.parallelStream().forEach( subscription -> {
            CompletableFuture.supplyAsync( () -> this.message(subscription))
                    .thenApply(message -> kt.send(SUBSCRIPTION_EXPIRED_REMINDER_EARLY,message));
        });
    }

该解决方案对我来说看起来不错,但是它将如何在我的 Kafka 集群中生成 X 条消息的大 X 客户上执行?

添加更多代理/分区是否是使其更快并避免失败的唯一解决方案(对于失败,我有一个重试和错误主题,并且所有内容都被记录和存储)?

提前致谢。

标签: spring-bootapache-kafkanotificationsmicroservicesspring-kafka

解决方案


推荐阅读