spring-boot - 使用 Kafka 和 Spring Boot 进行电子邮件/通知调度
问题描述
我正在开发一个订阅系统,其中有 2 个微服务:
处理订阅逻辑(显然)的订阅服务,并在 Kafka 上生成与订阅相关的事件。
使用 Kafka 消息并根据主题发送通知(电子邮件、短信、推送)的通知服务。
我想做的是每天上午 12 点为每个订阅在 1 周后到期的客户发送电子邮件和短信。
我现在将向您描述我的推理:
- 在我的订阅服务上创建一个 cron 作业,以获取目标客户并为每个客户生成主题为“订阅到期提醒”的消息/事件
@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 客户上执行?
添加更多代理/分区是否是使其更快并避免失败的唯一解决方案(对于失败,我有一个重试和错误主题,并且所有内容都被记录和存储)?
提前致谢。
解决方案
推荐阅读
- android - 无法使用“adb reverse”连接到开发服务器:spawnSync adb ENOENT
- angular - Angular:如何拦截服务器发送的事件请求?
- php - laravel编辑表单中的选定记录不起作用
- javascript - 我如何使这段代码更干净?
- sql-server - SQL Server 表名按顺序列出
- android - 时间选择器不工作并崩溃
- firebase - Flutter iOS FCM 通知 onMessage
- android - ItemTouchHelper.SimpleCallback onMove() 未触发
- shell - 在变量中存储“没有这样的文件或目录”消息
- r - 用多个预测变量绘制逻辑回归?