简体   繁体   English

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

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

I am writing a mail service that replies to incoming messages and I'd like to set up a limit - max 10 sent messages/hour. 我正在写一个回复传入消息的邮件服务,我想设置一个限制-每小时最多发送10条消息。 It should reset at full hour too. 它也应该在全时重置。

Is it possible in Spring Integration? Spring Integration中可能吗? I read about Task Scheduling in Spring docs, but I'm not sure if that matches my case. 我在Spring文档中阅读了有关任务计划的信息,但不确定是否与我的情况相符。 I guess I could set up a CronTrigger that sends the messages at a fixed rate, but that doesn't sound like it does what I actually want to achieve. 我想我可以设置一个CronTrigger以固定的速率发送消息,但这听起来并不像我真正想要实现的那样。

Thanks in advance. 提前致谢。

I think you go right way though. 我想你虽然走对了。

You configure a QeueueChannel and PollingConsumer ( @ServiceActivator with the @Poller ). 您配置一个QeueueChannelPollingConsumer@ServiceActivator@Poller )。 You definitely can go the cron trigger there: 您绝对可以在那里进行cron触发:

/**
 * @return The cron expression to create the {@link CronTrigger}.
 * Can be specified as 'property placeholder', e.g. {@code ${poller.cron}}.
 */
String cron() default "";

And your requirement about max 10 sent messages/hour ca be achieved with the: 您可以通过以下方式达到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 "";

So, when the task is performed by the scheduler according the configured cron time, only configured maxMessagesPerPoll will be pulled from the QeueueChannel and sent downstream for processing (sending emails). 所以,当通过根据设置cron时间调度执行的任务,仅配置maxMessagesPerPoll将从拉QeueueChannel和用于处理(发送电子邮件)向下游发送。

See more info in the https://docs.spring.io/spring-integration/docs/5.0.0.RELEASE/reference/html/messaging-channels-section.html#polling-consumer and seek for the Important: Poller Configuration paragraph. 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