我正在撰写回复收到邮件的邮件服务,我想设置限制 - 每小时最多发送10封邮件。它也应该在整个小时重置。
Spring Integration是否可行?我在Spring文档中阅读了有关任务调度的内容,但我不确定这是否符合我的情况。我想我可以设置一个以固定速率发送消息的CronTrigger,但这并不像我实际想要实现的那样。
提前致谢。
答案 0 :(得分:2)
我认为你走的是正确的。
您使用QeueueChannel
配置PollingConsumer
和@ServiceActivator
(@Poller
)。你肯定可以去那里的cron触发器:
/**
* @return The cron expression to create the {@link CronTrigger}.
* Can be specified as 'property placeholder', e.g. {@code ${poller.cron}}.
*/
String cron() default "";
您对max 10 sent messages/hour
的要求可通过以下方式实现:
/**
* @return The maximum number of messages to receive for each poll.
* Can be specified as 'property placeholder', e.g. {@code ${poller.maxMessagesPerPoll}}.
* Defaults to -1 (infinity) for polling consumers and 1 for polling inbound channel adapters.
*/
String maxMessagesPerPoll() default "";
因此,当调度程序根据配置的cron时间执行任务时,只会从maxMessagesPerPoll
中提取已配置的QeueueChannel
并向下游发送以进行处理(发送电子邮件)。
在https://docs.spring.io/spring-integration/docs/5.0.0.RELEASE/reference/html/messaging-channels-section.html#polling-consumer中查看更多信息,并寻找Important: Poller Configuration
段。