繁体   English   中英

Spring Integration-设置发送消息的上限

[英]Spring Integration - setting upper limit on sending messages

我正在写一个回复传入消息的邮件服务,我想设置一个限制-每小时最多发送10条消息。 它也应该在全时重置。

Spring Integration中可能吗? 我在Spring文档中阅读了有关任务计划的信息,但不确定是否与我的情况相符。 我想我可以设置一个CronTrigger以固定的速率发送消息,但这听起来并不像我真正想要实现的那样。

提前致谢。

我想你虽然走对了。

您配置一个QeueueChannelPollingConsumer@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段。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM